bitcoinrb 0.3.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +6 -3
- data/README.md +17 -6
- data/bitcoinrb.gemspec +9 -8
- data/exe/bitcoinrbd +5 -0
- data/lib/bitcoin.rb +35 -19
- data/lib/bitcoin/bip85_entropy.rb +111 -0
- data/lib/bitcoin/block_filter.rb +14 -0
- data/lib/bitcoin/block_header.rb +2 -0
- data/lib/bitcoin/chain_params.rb +9 -8
- data/lib/bitcoin/chainparams/regtest.yml +1 -1
- data/lib/bitcoin/chainparams/signet.yml +39 -0
- data/lib/bitcoin/chainparams/testnet.yml +1 -1
- data/lib/bitcoin/constants.rb +45 -12
- data/lib/bitcoin/descriptor.rb +1 -1
- data/lib/bitcoin/errors.rb +19 -0
- data/lib/bitcoin/ext.rb +5 -0
- data/lib/bitcoin/ext/ecdsa.rb +31 -0
- data/lib/bitcoin/ext/json_parser.rb +46 -0
- data/lib/bitcoin/ext_key.rb +50 -19
- data/lib/bitcoin/key.rb +46 -29
- data/lib/bitcoin/key_path.rb +12 -5
- data/lib/bitcoin/message.rb +79 -0
- data/lib/bitcoin/message/addr_v2.rb +34 -0
- data/lib/bitcoin/message/base.rb +17 -0
- data/lib/bitcoin/message/cf_parser.rb +16 -0
- data/lib/bitcoin/message/cfcheckpt.rb +36 -0
- data/lib/bitcoin/message/cfheaders.rb +40 -0
- data/lib/bitcoin/message/cfilter.rb +35 -0
- data/lib/bitcoin/message/fee_filter.rb +1 -1
- data/lib/bitcoin/message/filter_load.rb +3 -3
- data/lib/bitcoin/message/get_cfcheckpt.rb +29 -0
- data/lib/bitcoin/message/get_cfheaders.rb +24 -0
- data/lib/bitcoin/message/get_cfilters.rb +25 -0
- data/lib/bitcoin/message/header_and_short_ids.rb +1 -1
- data/lib/bitcoin/message/inventory.rb +1 -1
- data/lib/bitcoin/message/merkle_block.rb +1 -1
- data/lib/bitcoin/message/network_addr.rb +141 -18
- data/lib/bitcoin/message/ping.rb +1 -1
- data/lib/bitcoin/message/pong.rb +1 -1
- data/lib/bitcoin/message/send_addr_v2.rb +13 -0
- data/lib/bitcoin/message/send_cmpct.rb +2 -2
- data/lib/bitcoin/message/version.rb +7 -0
- data/lib/bitcoin/mnemonic.rb +7 -7
- data/lib/bitcoin/network/peer.rb +9 -4
- data/lib/bitcoin/network/peer_discovery.rb +1 -1
- data/lib/bitcoin/node/cli.rb +14 -10
- data/lib/bitcoin/node/configuration.rb +3 -1
- data/lib/bitcoin/node/spv.rb +9 -1
- data/lib/bitcoin/opcodes.rb +14 -1
- data/lib/bitcoin/out_point.rb +7 -0
- data/lib/bitcoin/payment_code.rb +92 -0
- data/lib/bitcoin/psbt/hd_key_path.rb +1 -1
- data/lib/bitcoin/psbt/input.rb +8 -17
- data/lib/bitcoin/psbt/output.rb +1 -1
- data/lib/bitcoin/psbt/tx.rb +11 -16
- data/lib/bitcoin/rpc/bitcoin_core_client.rb +22 -12
- data/lib/bitcoin/rpc/request_handler.rb +3 -3
- data/lib/bitcoin/script/script.rb +68 -28
- data/lib/bitcoin/script/script_error.rb +27 -1
- data/lib/bitcoin/script/script_interpreter.rb +164 -67
- data/lib/bitcoin/script/tx_checker.rb +64 -14
- data/lib/bitcoin/secp256k1.rb +1 -0
- data/lib/bitcoin/secp256k1/native.rb +138 -25
- data/lib/bitcoin/secp256k1/rfc6979.rb +43 -0
- data/lib/bitcoin/secp256k1/ruby.rb +82 -54
- data/lib/bitcoin/sighash_generator.rb +156 -0
- data/lib/bitcoin/store.rb +2 -1
- data/lib/bitcoin/store/chain_entry.rb +1 -0
- data/lib/bitcoin/store/db/level_db.rb +2 -2
- data/lib/bitcoin/store/utxo_db.rb +226 -0
- data/lib/bitcoin/tx.rb +17 -88
- data/lib/bitcoin/tx_in.rb +4 -5
- data/lib/bitcoin/tx_out.rb +2 -3
- data/lib/bitcoin/util.rb +34 -6
- data/lib/bitcoin/version.rb +1 -1
- data/lib/bitcoin/wallet.rb +1 -0
- data/lib/bitcoin/wallet/account.rb +2 -1
- data/lib/bitcoin/wallet/base.rb +3 -3
- data/lib/bitcoin/wallet/db.rb +1 -1
- data/lib/bitcoin/wallet/master_key.rb +1 -0
- data/lib/bitcoin/wallet/utxo.rb +37 -0
- metadata +66 -32
data/lib/bitcoin/key_path.rb
CHANGED
@@ -4,14 +4,21 @@ module Bitcoin
|
|
4
4
|
# key path convert an array of derive number
|
5
5
|
# @param [String] path_string
|
6
6
|
# @return [Array[Integer]] key path numbers.
|
7
|
+
# @raise [ArgumentError] if invalid +path_string+.
|
7
8
|
def parse_key_path(path_string)
|
8
|
-
path_string.split('/')
|
9
|
+
paths = path_string.split('/')
|
10
|
+
raise ArgumentError, "Invalid path." if path_string.include?(" ")
|
11
|
+
raise ArgumentError, "Invalid path." unless path_string.count("/") <= paths.size
|
12
|
+
paths.map.with_index do|p, index|
|
9
13
|
if index == 0
|
10
|
-
|
11
|
-
|
14
|
+
next if p == 'm'
|
15
|
+
raise ArgumentError, "Invalid path." unless p == 'm'
|
12
16
|
end
|
13
|
-
raise ArgumentError.
|
14
|
-
|
17
|
+
raise ArgumentError, "Invalid path." if p.count("'") > 1 || (p.count("'") == 1 && p[-1] != "'")
|
18
|
+
raise ArgumentError, "Invalid path." unless p.delete("'") =~ /^[0-9]+$/
|
19
|
+
value = (p[-1] == "'" ? p.delete("'").to_i + Bitcoin::HARDENED_THRESHOLD : p.to_i)
|
20
|
+
raise ArgumentError, "Invalid path." if value > 4294967295 # 4294967295 = 0xFFFFFFFF (uint32 max)
|
21
|
+
value
|
15
22
|
end[1..-1]
|
16
23
|
end
|
17
24
|
|
data/lib/bitcoin/message.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Bitcoin
|
2
2
|
module Message
|
3
3
|
|
4
|
+
class Error < StandardError; end
|
5
|
+
|
4
6
|
autoload :Base, 'bitcoin/message/base'
|
5
7
|
autoload :Inventory, 'bitcoin/message/inventory'
|
6
8
|
autoload :InventoriesParser, 'bitcoin/message/inventories_parser'
|
@@ -37,6 +39,15 @@ module Bitcoin
|
|
37
39
|
autoload :BlockTransactionRequest, 'bitcoin/message/block_transaction_request'
|
38
40
|
autoload :BlockTxn, 'bitcoin/message/block_txn'
|
39
41
|
autoload :BlockTransactions, 'bitcoin/message/block_transactions'
|
42
|
+
autoload :GetCFilters, 'bitcoin/message/get_cfilters'
|
43
|
+
autoload :GetCFHeaders, 'bitcoin/message/get_cfheaders'
|
44
|
+
autoload :CFParser, 'bitcoin/message/cf_parser'
|
45
|
+
autoload :GetCFCheckpt, 'bitcoin/message/get_cfcheckpt'
|
46
|
+
autoload :CFCheckpt, 'bitcoin/message/cfcheckpt'
|
47
|
+
autoload :CFilter, 'bitcoin/message/cfilter'
|
48
|
+
autoload :CFHeaders, 'bitcoin/message/cfheaders'
|
49
|
+
autoload :SendAddrV2, 'bitcoin/message/send_addr_v2'
|
50
|
+
autoload :AddrV2, 'bitcoin/message/addr_v2'
|
40
51
|
|
41
52
|
USER_AGENT = "/bitcoinrb:#{Bitcoin::VERSION}/"
|
42
53
|
|
@@ -66,5 +77,73 @@ module Bitcoin
|
|
66
77
|
compact_witness: 70015
|
67
78
|
}
|
68
79
|
|
80
|
+
module_function
|
81
|
+
|
82
|
+
# Decode P2P message.
|
83
|
+
# @param [String] command P2P message command string.
|
84
|
+
# @param [String] payload P2P message payload with hex format..
|
85
|
+
# @return [Bitcoin::Message::]
|
86
|
+
def decode(command, payload = nil)
|
87
|
+
payload = payload.htb if payload
|
88
|
+
case command
|
89
|
+
when Bitcoin::Message::Version::COMMAND
|
90
|
+
Bitcoin::Message::Version.parse_from_payload(payload)
|
91
|
+
when Bitcoin::Message::VerAck::COMMAND
|
92
|
+
Bitcoin::Message::VerAck.new
|
93
|
+
when Bitcoin::Message::GetAddr::COMMAND
|
94
|
+
Bitcoin::Message::GetAddr.new
|
95
|
+
when Bitcoin::Message::Addr::COMMAND
|
96
|
+
Bitcoin::Message::Addr.parse_from_payload(payload)
|
97
|
+
when Bitcoin::Message::SendHeaders::COMMAND
|
98
|
+
Bitcoin::Message::SendHeaders.new
|
99
|
+
when Bitcoin::Message::FeeFilter::COMMAND
|
100
|
+
Bitcoin::Message::FeeFilter.parse_from_payload(payload)
|
101
|
+
when Bitcoin::Message::Ping::COMMAND
|
102
|
+
Bitcoin::Message::Ping.parse_from_payload(payload)
|
103
|
+
when Bitcoin::Message::Pong::COMMAND
|
104
|
+
Bitcoin::Message::Pong.parse_from_payload(payload)
|
105
|
+
when Bitcoin::Message::GetHeaders::COMMAND
|
106
|
+
Bitcoin::Message::GetHeaders.parse_from_payload(payload)
|
107
|
+
when Bitcoin::Message::Headers::COMMAND
|
108
|
+
Bitcoin::Message::Headers.parse_from_payload(payload)
|
109
|
+
when Bitcoin::Message::Block::COMMAND
|
110
|
+
Bitcoin::Message::Block.parse_from_payload(payload)
|
111
|
+
when Bitcoin::Message::Tx::COMMAND
|
112
|
+
Bitcoin::Message::Tx.parse_from_payload(payload)
|
113
|
+
when Bitcoin::Message::NotFound::COMMAND
|
114
|
+
Bitcoin::Message::NotFound.parse_from_payload(payload)
|
115
|
+
when Bitcoin::Message::MemPool::COMMAND
|
116
|
+
Bitcoin::Message::MemPool.new
|
117
|
+
when Bitcoin::Message::Reject::COMMAND
|
118
|
+
Bitcoin::Message::Reject.parse_from_payload(payload)
|
119
|
+
when Bitcoin::Message::SendCmpct::COMMAND
|
120
|
+
Bitcoin::Message::SendCmpct.parse_from_payload(payload)
|
121
|
+
when Bitcoin::Message::Inv::COMMAND
|
122
|
+
Bitcoin::Message::Inv.parse_from_payload(payload)
|
123
|
+
when Bitcoin::Message::MerkleBlock::COMMAND
|
124
|
+
Bitcoin::Message::MerkleBlock.parse_from_payload(payload)
|
125
|
+
when Bitcoin::Message::CmpctBlock::COMMAND
|
126
|
+
Bitcoin::Message::CmpctBlock.parse_from_payload(payload)
|
127
|
+
when Bitcoin::Message::GetData::COMMAND
|
128
|
+
Bitcoin::Message::GetData.parse_from_payload(payload)
|
129
|
+
when Bitcoin::Message::GetCFHeaders::COMMAND
|
130
|
+
Bitcoin::Message::GetCFHeaders.parse_from_payload(payload)
|
131
|
+
when Bitcoin::Message::GetCFilters::COMMAND
|
132
|
+
Bitcoin::Message::GetCFilters.parse_from_payload(payload)
|
133
|
+
when Bitcoin::Message::GetCFCheckpt::COMMAND
|
134
|
+
Bitcoin::Message::GetCFCheckpt.parse_from_payload(payload)
|
135
|
+
when Bitcoin::Message::CFCheckpt::COMMAND
|
136
|
+
Bitcoin::Message::CFCheckpt.parse_from_payload(payload)
|
137
|
+
when Bitcoin::Message::CFHeaders::COMMAND
|
138
|
+
Bitcoin::Message::CFHeaders.parse_from_payload(payload)
|
139
|
+
when Bitcoin::Message::CFilter::COMMAND
|
140
|
+
Bitcoin::Message::CFilter.parse_from_payload(payload)
|
141
|
+
when Bitcoin::Message::SendAddrV2::COMMAND
|
142
|
+
Bitcoin::Message::SendAddrV2.new
|
143
|
+
when Bitcoin::Message::AddrV2::COMMAND
|
144
|
+
Bitcoin::Message::AddrV2.parse_from_payload(payload)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
69
148
|
end
|
70
149
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Bitcoin
|
2
|
+
module Message
|
3
|
+
|
4
|
+
# addrv2 message class.
|
5
|
+
# https://github.com/bitcoin/bips/blob/master/bip-0155.mediawiki
|
6
|
+
class AddrV2 < Base
|
7
|
+
|
8
|
+
COMMAND = 'addrv2'
|
9
|
+
|
10
|
+
attr_reader :addrs
|
11
|
+
|
12
|
+
def initialize(addrs = [])
|
13
|
+
@addrs = addrs
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.parse_from_payload(payload)
|
17
|
+
buf = StringIO.new(payload)
|
18
|
+
addr_count = Bitcoin.unpack_var_int_from_io(buf)
|
19
|
+
v2 = new
|
20
|
+
addr_count.times do
|
21
|
+
v2.addrs << NetworkAddr.parse_from_payload(buf, type: NetworkAddr::TYPE[:addr_v2])
|
22
|
+
end
|
23
|
+
v2
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_payload
|
27
|
+
buf = Bitcoin.pack_var_int(addrs.size)
|
28
|
+
buf << (addrs.map { |a| a.to_payload(type: NetworkAddr::TYPE[:addr_v2])}.join)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
data/lib/bitcoin/message/base.rb
CHANGED
@@ -3,6 +3,7 @@ module Bitcoin
|
|
3
3
|
|
4
4
|
# Base message class
|
5
5
|
class Base
|
6
|
+
include Bitcoin::HexConverter
|
6
7
|
include Bitcoin::Util
|
7
8
|
extend Bitcoin::Util
|
8
9
|
|
@@ -22,6 +23,22 @@ module Bitcoin
|
|
22
23
|
raise 'to_payload must be implemented in a child class.'
|
23
24
|
end
|
24
25
|
|
26
|
+
# Decode message data to message object.
|
27
|
+
# @param [String] message with binary format.
|
28
|
+
# @return [Bitcoin::Message::XXX] An instance of a class that inherits Bitcoin::Message::Base
|
29
|
+
# @raise [ArgumentError] Occurs for data that cannot be decoded.
|
30
|
+
def self.from_pkt(message)
|
31
|
+
buf = StringIO.new(message)
|
32
|
+
magic = buf.read(4)
|
33
|
+
raise ArgumentError, 'Invalid magic.' unless magic == Bitcoin.chain_params.magic_head.htb
|
34
|
+
command = buf.read(12).delete("\x00")
|
35
|
+
length = buf.read(4).unpack1('V')
|
36
|
+
checksum = buf.read(4)
|
37
|
+
payload = buf.read(length)
|
38
|
+
raise ArgumentError, 'Checksum do not match.' unless checksum == Bitcoin.double_sha256(payload)[0...4]
|
39
|
+
Bitcoin::Message.decode(command, payload&.bth)
|
40
|
+
end
|
41
|
+
|
25
42
|
end
|
26
43
|
|
27
44
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Bitcoin
|
2
|
+
module Message
|
3
|
+
module CFParser
|
4
|
+
|
5
|
+
def parse_from_payload(payload)
|
6
|
+
type, start, hash = payload.unpack('CLH*')
|
7
|
+
self.new(type, start, hash)
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_payload
|
11
|
+
[filter_type, start_height, stop_hash].pack('CLH*')
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Bitcoin
|
2
|
+
module Message
|
3
|
+
|
4
|
+
# cfcheckpt message for BIP-157
|
5
|
+
# https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki#cfcheckpt
|
6
|
+
class CFCheckpt < Base
|
7
|
+
|
8
|
+
COMMAND = 'cfcheckpt'
|
9
|
+
|
10
|
+
attr_accessor :filter_type
|
11
|
+
attr_accessor :stop_hash # little endian
|
12
|
+
attr_accessor :filter_headers # little endian
|
13
|
+
|
14
|
+
def initialize(filter_type, stop_hash, filter_headers)
|
15
|
+
@filter_type = filter_type
|
16
|
+
@stop_hash = stop_hash
|
17
|
+
@filter_headers = filter_headers
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.parse_from_payload(payload)
|
21
|
+
buf = StringIO.new(payload)
|
22
|
+
type = buf.read(1).unpack1('C')
|
23
|
+
hash = buf.read(32).unpack1('H*')
|
24
|
+
count = Bitcoin.unpack_var_int_from_io(buf)
|
25
|
+
headers = count.times.map{buf.read(32).bth}
|
26
|
+
self.new(type, hash, headers)
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_payload
|
30
|
+
[filter_type, stop_hash].pack('CH*') +
|
31
|
+
Bitcoin.pack_var_int(filter_headers.size) + filter_headers.map(&:htb).join
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Bitcoin
|
2
|
+
module Message
|
3
|
+
|
4
|
+
# cfheaders message for BIP-157
|
5
|
+
# https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki#cfheaders
|
6
|
+
class CFHeaders < Base
|
7
|
+
|
8
|
+
COMMAND = 'cfheaders'
|
9
|
+
|
10
|
+
attr_accessor :filter_type
|
11
|
+
attr_accessor :stop_hash # little endian
|
12
|
+
attr_accessor :prev_filter_header # little endian
|
13
|
+
attr_accessor :filter_hashes # little endian
|
14
|
+
|
15
|
+
def initialize(filter_type, stop_hash, prev_filter_header, filter_hashes)
|
16
|
+
@filter_type = filter_type
|
17
|
+
@stop_hash = stop_hash
|
18
|
+
@prev_filter_header = prev_filter_header
|
19
|
+
@filter_hashes = filter_hashes
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.parse_from_payload(payload)
|
23
|
+
buf = StringIO.new(payload)
|
24
|
+
type = buf.read(1).unpack1("C")
|
25
|
+
hash = buf.read(32).bth
|
26
|
+
header = buf.read(32).bth
|
27
|
+
count = Bitcoin.unpack_var_int_from_io(buf)
|
28
|
+
hashes = count.times.map{buf.read(32).bth}
|
29
|
+
self.new(type, hash, header, hashes)
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_payload
|
33
|
+
[filter_type].pack('C') + stop_hash.htb + prev_filter_header.htb +
|
34
|
+
Bitcoin.pack_var_int(filter_hashes.size) + filter_hashes.map(&:htb).join
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Bitcoin
|
2
|
+
module Message
|
3
|
+
|
4
|
+
# cfilter message for BIP-157
|
5
|
+
# https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki#cfilter
|
6
|
+
class CFilter < Base
|
7
|
+
|
8
|
+
COMMAND = 'cfilter'
|
9
|
+
|
10
|
+
attr_accessor :filter_type
|
11
|
+
attr_accessor :block_hash # little endian
|
12
|
+
attr_accessor :filter # little endian
|
13
|
+
|
14
|
+
def initialize(filter_type, block_hash, filter)
|
15
|
+
@filter_type = filter_type
|
16
|
+
@block_hash = block_hash
|
17
|
+
@filter = filter
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.parse_from_payload(payload)
|
21
|
+
buf = StringIO.new(payload)
|
22
|
+
type = buf.read(1).unpack1("C")
|
23
|
+
hash = buf.read(32).bth
|
24
|
+
len = Bitcoin.unpack_var_int_from_io(buf)
|
25
|
+
filter = buf.read(len).bth
|
26
|
+
self.new(type, hash, filter)
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_payload
|
30
|
+
[filter_type, block_hash].pack('CH*') + Bitcoin.pack_var_string(filter.htb)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -23,9 +23,9 @@ module Bitcoin
|
|
23
23
|
buf = StringIO.new(payload)
|
24
24
|
filter_count = Bitcoin.unpack_var_int_from_io(buf)
|
25
25
|
filter = buf.read(filter_count).unpack('C*')
|
26
|
-
func_count = buf.read(4).
|
27
|
-
tweak = buf.read(4).
|
28
|
-
flag = buf.read(1).
|
26
|
+
func_count = buf.read(4).unpack1('V')
|
27
|
+
tweak = buf.read(4).unpack1('V')
|
28
|
+
flag = buf.read(1).unpack1('C')
|
29
29
|
FilterLoad.new(Bitcoin::BloomFilter.new(filter, func_count, tweak), flag)
|
30
30
|
end
|
31
31
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Bitcoin
|
2
|
+
module Message
|
3
|
+
|
4
|
+
# getcfcheckpt message for BIP-157
|
5
|
+
# https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki#getcfcheckpt
|
6
|
+
class GetCFCheckpt < Base
|
7
|
+
|
8
|
+
COMMAND = 'getcfcheckpt'
|
9
|
+
|
10
|
+
attr_accessor :filter_type
|
11
|
+
attr_accessor :stop_hash # little endian
|
12
|
+
|
13
|
+
def initialize(filter_type, stop_hash)
|
14
|
+
@filter_type = filter_type
|
15
|
+
@stop_hash = stop_hash
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.parse_from_payload(payload)
|
19
|
+
type, hash = payload.unpack('CH*')
|
20
|
+
self.new(type, hash)
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_payload
|
24
|
+
[filter_type, stop_hash].pack('CH*')
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Bitcoin
|
2
|
+
module Message
|
3
|
+
|
4
|
+
# getcfheaders message for BIP-157
|
5
|
+
# https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki#getcfheaders
|
6
|
+
class GetCFHeaders < Base
|
7
|
+
include CFParser
|
8
|
+
extend CFParser
|
9
|
+
|
10
|
+
COMMAND = 'getcfheaders'
|
11
|
+
|
12
|
+
attr_accessor :filter_type
|
13
|
+
attr_accessor :start_height
|
14
|
+
attr_accessor :stop_hash # little endian
|
15
|
+
|
16
|
+
def initialize(filter_type, start_height, stop_hash)
|
17
|
+
@filter_type = filter_type
|
18
|
+
@start_height = start_height
|
19
|
+
@stop_hash = stop_hash
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Bitcoin
|
2
|
+
module Message
|
3
|
+
|
4
|
+
# getcfilters message for BIP-157
|
5
|
+
# https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki#getcfilters
|
6
|
+
class GetCFilters < Base
|
7
|
+
include CFParser
|
8
|
+
extend CFParser
|
9
|
+
|
10
|
+
COMMAND = 'getcfilters'
|
11
|
+
|
12
|
+
attr_accessor :filter_type
|
13
|
+
attr_accessor :start_height
|
14
|
+
attr_accessor :stop_hash # little endian
|
15
|
+
|
16
|
+
def initialize(filter_type, start_height, stop_hash)
|
17
|
+
@filter_type = filter_type
|
18
|
+
@start_height = start_height
|
19
|
+
@stop_hash = stop_hash
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -22,7 +22,7 @@ module Bitcoin
|
|
22
22
|
def self.parse_from_payload(payload)
|
23
23
|
buf = StringIO.new(payload)
|
24
24
|
header = Bitcoin::BlockHeader.parse_from_payload(buf.read(80))
|
25
|
-
nonce = buf.read(8).
|
25
|
+
nonce = buf.read(8).unpack1('q*')
|
26
26
|
short_ids_len = Bitcoin.unpack_var_int_from_io(buf)
|
27
27
|
short_ids = short_ids_len.times.map do
|
28
28
|
buf.read(6).reverse.bth.to_i(16)
|
@@ -26,7 +26,7 @@ module Bitcoin
|
|
26
26
|
# parse inventory payload
|
27
27
|
def self.parse_from_payload(payload)
|
28
28
|
raise Error, 'invalid inventory size.' if payload.bytesize != 36
|
29
|
-
identifier = payload[0..4].
|
29
|
+
identifier = payload[0..4].unpack1('V')
|
30
30
|
hash = payload[4..-1].bth # internal byte order
|
31
31
|
new(identifier, hash)
|
32
32
|
end
|