Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion lib/bitcoin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ def self.network=(name)
@network
end

[:bitcoin, :namecoin, :litecoin, :dogecoin, :dogecoin_testnet].each do |n|
[:bitcoin, :bitcoin_cash, :namecoin, :litecoin, :dogecoin, :dogecoin_testnet].each do |n|
instance_eval "def #{n}?; network_project == :#{n}; end"
end

Expand Down Expand Up @@ -727,6 +727,38 @@ def self.network=(name)
}
})

NETWORKS[:bitcoin_cash] = NETWORKS[:bitcoin].merge({
project: :bitcoin_cash,
magic_head: "\xE3\xE1\xF3\xE8",
protocol_version: 70015,
dns_seeds: [
'seed.bitcoinabc.org',
'seed-abc.bitcoinforks.org',
'seed.bitprim.org',
'seed.deadalnix.me',
'seeder.criptolayer.net'
]
})

NETWORKS[:bitcoin_cash_testnet3] = NETWORKS[:testnet3].merge({
project: :bitcoin_cash,
magic_head: "\xF4\xE5\xF3\xF4",
protocol_version: 70015,
dns_seeds: [
'testnet-seed.bitcoinabc.org',
'testnet-seed-abc.bitcoinforks.org',
'testnet-seed.bitprim.org',
'testnet-seed.deadalnix.me',
'testnet-seeder.criptolayer.net'
]
})

NETWORKS[:bitcoin_cash_regtest] = NETWORKS[:regtest].merge({
project: :bitcoin_cash,
magic_head: "\xDA\xB5\xBF\xFA",
protocol_version: 70015
})

NETWORKS[:litecoin] = NETWORKS[:bitcoin].merge({
project: :litecoin,
magic_head: "\xfb\xc0\xb6\xdb",
Expand Down
8 changes: 6 additions & 2 deletions spec/bitcoin/bitcoin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@
success = false if Bitcoin.valid_address?(addr[0]) != true
}
success.should == true

Bitcoin::network = :bitcoin_cash
Bitcoin.valid_address?("1D3KpY5kXnYhTbdCbZ9kXb2ZY7ZapD85cW").should == true
Bitcoin.valid_address?("mpXwg4jMtRhuSpVq4xS3HFHmCmWp9NyGKt").should == false
end

it 'validate bitcoin public key' do
Expand Down Expand Up @@ -339,7 +343,7 @@
Bitcoin.hash_mrkl_tree(["aa", "bb", "cc"]).last.should !=
Bitcoin.hash_mrkl_tree(["aa", "bb", "cc", "cc"]).last
end

it 'return a value even if a merkle branch is empty' do
branch = []
mrkl_index = 0
Expand Down Expand Up @@ -530,7 +534,7 @@
prev_block_bits = 0x1a05db8b
last_retarget_time = 1348092851
new_difficulty = Bitcoin.block_new_target(prev_height, prev_block_time, prev_block_bits, last_retarget_time)

Bitcoin.decode_compact_bits(new_difficulty.should) == Bitcoin.decode_compact_bits(0x1a057e08)
end

Expand Down