tapyrus 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +37 -0
- data/.prettierignore +3 -0
- data/.prettierrc.yaml +3 -0
- data/CODE_OF_CONDUCT.md +7 -7
- data/README.md +14 -17
- data/Rakefile +3 -3
- data/lib/openassets.rb +0 -2
- data/lib/openassets/marker_output.rb +0 -4
- data/lib/openassets/payload.rb +4 -10
- data/lib/schnorr.rb +2 -3
- data/lib/schnorr/signature.rb +3 -6
- data/lib/tapyrus.rb +6 -22
- data/lib/tapyrus/base58.rb +7 -6
- data/lib/tapyrus/block.rb +1 -2
- data/lib/tapyrus/block_header.rb +15 -9
- data/lib/tapyrus/bloom_filter.rb +5 -3
- data/lib/tapyrus/chain_params.rb +1 -4
- data/lib/tapyrus/chainparams/dev.yml +3 -2
- data/lib/tapyrus/chainparams/prod.yml +3 -2
- data/lib/tapyrus/constants.rb +29 -23
- data/lib/tapyrus/errors.rb +1 -3
- data/lib/tapyrus/ext.rb +1 -1
- data/lib/tapyrus/ext/ecdsa.rb +4 -4
- data/lib/tapyrus/ext/json_parser.rb +1 -4
- data/lib/tapyrus/ext_key.rb +38 -34
- data/lib/tapyrus/key.rb +31 -35
- data/lib/tapyrus/key_path.rb +15 -12
- data/lib/tapyrus/logger.rb +20 -16
- data/lib/tapyrus/merkle_tree.rb +19 -20
- data/lib/tapyrus/message.rb +14 -16
- data/lib/tapyrus/message/addr.rb +1 -7
- data/lib/tapyrus/message/base.rb +0 -3
- data/lib/tapyrus/message/block.rb +2 -9
- data/lib/tapyrus/message/block_transaction_request.rb +3 -6
- data/lib/tapyrus/message/block_transactions.rb +2 -6
- data/lib/tapyrus/message/block_txn.rb +0 -4
- data/lib/tapyrus/message/cmpct_block.rb +1 -7
- data/lib/tapyrus/message/error.rb +1 -4
- data/lib/tapyrus/message/fee_filter.rb +1 -4
- data/lib/tapyrus/message/filter_add.rb +0 -4
- data/lib/tapyrus/message/filter_clear.rb +0 -4
- data/lib/tapyrus/message/filter_load.rb +2 -5
- data/lib/tapyrus/message/get_addr.rb +0 -4
- data/lib/tapyrus/message/get_block_txn.rb +0 -4
- data/lib/tapyrus/message/get_blocks.rb +0 -3
- data/lib/tapyrus/message/get_data.rb +1 -4
- data/lib/tapyrus/message/get_headers.rb +1 -3
- data/lib/tapyrus/message/header_and_short_ids.rb +3 -9
- data/lib/tapyrus/message/headers.rb +0 -4
- data/lib/tapyrus/message/headers_parser.rb +3 -8
- data/lib/tapyrus/message/inv.rb +1 -4
- data/lib/tapyrus/message/inventories_parser.rb +2 -7
- data/lib/tapyrus/message/inventory.rb +12 -5
- data/lib/tapyrus/message/mem_pool.rb +0 -4
- data/lib/tapyrus/message/merkle_block.rb +4 -9
- data/lib/tapyrus/message/network_addr.rb +7 -6
- data/lib/tapyrus/message/not_found.rb +0 -3
- data/lib/tapyrus/message/ping.rb +0 -3
- data/lib/tapyrus/message/pong.rb +0 -3
- data/lib/tapyrus/message/prefilled_tx.rb +0 -4
- data/lib/tapyrus/message/reject.rb +0 -3
- data/lib/tapyrus/message/send_cmpct.rb +1 -3
- data/lib/tapyrus/message/send_headers.rb +0 -3
- data/lib/tapyrus/message/tx.rb +0 -4
- data/lib/tapyrus/message/ver_ack.rb +1 -5
- data/lib/tapyrus/message/version.rb +2 -5
- data/lib/tapyrus/mnemonic.rb +17 -15
- data/lib/tapyrus/network.rb +0 -2
- data/lib/tapyrus/network/connection.rb +0 -3
- data/lib/tapyrus/network/message_handler.rb +61 -60
- data/lib/tapyrus/network/peer.rb +13 -12
- data/lib/tapyrus/network/peer_discovery.rb +3 -5
- data/lib/tapyrus/network/pool.rb +12 -12
- data/lib/tapyrus/node.rb +1 -1
- data/lib/tapyrus/node/cli.rb +12 -14
- data/lib/tapyrus/node/configuration.rb +1 -3
- data/lib/tapyrus/node/spv.rb +2 -3
- data/lib/tapyrus/opcodes.rb +9 -7
- data/lib/tapyrus/out_point.rb +5 -5
- data/lib/tapyrus/rpc/http_server.rb +21 -22
- data/lib/tapyrus/rpc/request_handler.rb +42 -44
- data/lib/tapyrus/rpc/tapyrus_core_client.rb +53 -25
- data/lib/tapyrus/script/color.rb +10 -0
- data/lib/tapyrus/script/multisig.rb +13 -12
- data/lib/tapyrus/script/script.rb +72 -71
- data/lib/tapyrus/script/script_error.rb +1 -4
- data/lib/tapyrus/script/script_interpreter.rb +439 -399
- data/lib/tapyrus/script/tx_checker.rb +20 -10
- data/lib/tapyrus/secp256k1.rb +0 -4
- data/lib/tapyrus/secp256k1/native.rb +14 -15
- data/lib/tapyrus/secp256k1/rfc6979.rb +7 -4
- data/lib/tapyrus/secp256k1/ruby.rb +10 -12
- data/lib/tapyrus/slip39.rb +20 -5
- data/lib/tapyrus/slip39/share.rb +41 -29
- data/lib/tapyrus/slip39/sss.rb +101 -57
- data/lib/tapyrus/store.rb +1 -3
- data/lib/tapyrus/store/chain_entry.rb +0 -4
- data/lib/tapyrus/store/db.rb +0 -2
- data/lib/tapyrus/store/db/level_db.rb +5 -9
- data/lib/tapyrus/store/spv_chain.rb +11 -17
- data/lib/tapyrus/tx.rb +45 -37
- data/lib/tapyrus/tx_builder.rb +158 -0
- data/lib/tapyrus/tx_in.rb +1 -6
- data/lib/tapyrus/tx_out.rb +2 -7
- data/lib/tapyrus/util.rb +7 -9
- data/lib/tapyrus/validation.rb +12 -11
- data/lib/tapyrus/version.rb +1 -1
- data/lib/tapyrus/wallet/account.rb +22 -18
- data/lib/tapyrus/wallet/base.rb +12 -9
- data/lib/tapyrus/wallet/db.rb +6 -9
- data/lib/tapyrus/wallet/master_key.rb +2 -4
- data/tapyrusrb.gemspec +13 -14
- metadata +21 -4
- data/.travis.yml +0 -14
data/lib/tapyrus/key_path.rb
CHANGED
@@ -1,26 +1,29 @@
|
|
1
1
|
module Tapyrus
|
2
2
|
module KeyPath
|
3
|
-
|
4
3
|
# key path convert an array of derive number
|
5
4
|
# @param [String] path_string
|
6
5
|
# @return [Array[Integer]] key path numbers.
|
7
6
|
def parse_key_path(path_string)
|
8
|
-
path_string
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
path_string
|
8
|
+
.split('/')
|
9
|
+
.map
|
10
|
+
.with_index do |p, index|
|
11
|
+
if index == 0
|
12
|
+
raise ArgumentError.new("#{path_string} is invalid format.") unless p == 'm'
|
13
|
+
next
|
14
|
+
end
|
15
|
+
raise ArgumentError.new("#{path_string} is invalid format.") unless p.delete("'") =~ /^[0-9]+$/
|
16
|
+
(p[-1] == "'" ? p.delete("'").to_i + Tapyrus::HARDENED_THRESHOLD : p.to_i)
|
17
|
+
end[
|
18
|
+
1..-1
|
19
|
+
]
|
16
20
|
end
|
17
21
|
|
18
22
|
# key path numbers convert to path string.
|
19
23
|
# @param [Array[Integer]] key path numbers.
|
20
24
|
# @return [String] path string.
|
21
25
|
def to_key_path(numbers)
|
22
|
-
"m/#{numbers.map{|p| p >= Tapyrus::HARDENED_THRESHOLD ? "#{p - Tapyrus::HARDENED_THRESHOLD}'" : p.to_s}.join('/')}"
|
26
|
+
"m/#{numbers.map { |p| p >= Tapyrus::HARDENED_THRESHOLD ? "#{p - Tapyrus::HARDENED_THRESHOLD}'" : p.to_s }.join('/')}"
|
23
27
|
end
|
24
|
-
|
25
28
|
end
|
26
|
-
end
|
29
|
+
end
|
data/lib/tapyrus/logger.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
require 'logger'
|
2
2
|
|
3
3
|
module Tapyrus
|
4
|
-
|
5
4
|
# Simple Logger module
|
6
5
|
module Logger
|
7
|
-
|
8
6
|
Format = "%s, [%s#%d #%d] %5s -- %s: %s\n".freeze
|
9
7
|
|
10
8
|
module_function
|
@@ -15,28 +13,34 @@ module Tapyrus
|
|
15
13
|
FileUtils.mkdir_p(dir)
|
16
14
|
logger = ::Logger.new(dir + "/#{name}.log", 10)
|
17
15
|
logger.level = level
|
18
|
-
logger.formatter =
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
logger.formatter =
|
17
|
+
proc do |severity, datetime, progname, msg|
|
18
|
+
Format % [
|
19
|
+
severity[0..0],
|
20
|
+
format_datetime(datetime),
|
21
|
+
$$,
|
22
|
+
Thread.current.object_id,
|
23
|
+
severity,
|
24
|
+
progname,
|
25
|
+
msg2str(msg)
|
26
|
+
]
|
27
|
+
end
|
22
28
|
logger
|
23
29
|
end
|
24
30
|
|
25
31
|
def self.msg2str(msg)
|
26
32
|
case msg
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
msg.inspect
|
33
|
+
when ::String
|
34
|
+
msg
|
35
|
+
when ::Exception
|
36
|
+
"#{msg.message} (#{msg.class})\n" << (msg.backtrace || []).join("\n")
|
37
|
+
else
|
38
|
+
msg.inspect
|
34
39
|
end
|
35
40
|
end
|
36
41
|
|
37
42
|
def format_datetime(time)
|
38
|
-
time.strftime(@datetime_format ||
|
43
|
+
time.strftime(@datetime_format || '%Y-%m-%dT%H:%M:%S.%6N '.freeze)
|
39
44
|
end
|
40
|
-
|
41
45
|
end
|
42
|
-
end
|
46
|
+
end
|
data/lib/tapyrus/merkle_tree.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module Tapyrus
|
2
|
-
|
3
2
|
# merkle tree
|
4
3
|
class MerkleTree
|
5
|
-
|
6
4
|
attr_accessor :root
|
7
5
|
|
8
6
|
def initialize(root = nil)
|
@@ -17,11 +15,12 @@ module Tapyrus
|
|
17
15
|
if txids.size == 1
|
18
16
|
nodes = [Node.new(txids.first)]
|
19
17
|
else
|
20
|
-
nodes =
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
nodes =
|
19
|
+
txids.each_slice(2).map do |m|
|
20
|
+
left = Node.new(m[0])
|
21
|
+
right = Node.new(m[1] ? m[1] : m[0])
|
22
|
+
[left, right]
|
23
|
+
end.flatten
|
25
24
|
end
|
26
25
|
new(build_initial_tree(nodes))
|
27
26
|
end
|
@@ -29,7 +28,7 @@ module Tapyrus
|
|
29
28
|
# https://bitcoin.org/en/developer-reference#creating-a-merkleblock-message
|
30
29
|
def self.build_partial(tx_count, hashes, flags)
|
31
30
|
flags = flags.each_char.map(&:to_i)
|
32
|
-
root = build_initial_tree(
|
31
|
+
root = build_initial_tree(Array.new(tx_count) { Node.new })
|
33
32
|
current_node = root
|
34
33
|
hash_index = 0
|
35
34
|
flags.each do |f|
|
@@ -40,9 +39,7 @@ module Tapyrus
|
|
40
39
|
end
|
41
40
|
current_node = current_node.next_partial
|
42
41
|
if hash_index == hashes.size
|
43
|
-
if current_node&.leaf?
|
44
|
-
current_node.value = hashes.last
|
45
|
-
end
|
42
|
+
current_node.value = hashes.last if current_node&.leaf?
|
46
43
|
break
|
47
44
|
end
|
48
45
|
end
|
@@ -51,12 +48,15 @@ module Tapyrus
|
|
51
48
|
|
52
49
|
def self.build_initial_tree(nodes)
|
53
50
|
while nodes.size != 1
|
54
|
-
nodes =
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
51
|
+
nodes =
|
52
|
+
nodes
|
53
|
+
.each_slice(2)
|
54
|
+
.map do |m|
|
55
|
+
parent = Node.new
|
56
|
+
parent.left = m[0]
|
57
|
+
parent.right = m[1] ? m[1] : m[0].dup
|
58
|
+
parent
|
59
|
+
end
|
60
60
|
end
|
61
61
|
nodes.first
|
62
62
|
end
|
@@ -67,7 +67,6 @@ module Tapyrus
|
|
67
67
|
|
68
68
|
# node of merkle tree
|
69
69
|
class Node
|
70
|
-
|
71
70
|
attr_accessor :flag
|
72
71
|
attr_accessor :value
|
73
72
|
attr_accessor :parent
|
@@ -118,7 +117,7 @@ module Tapyrus
|
|
118
117
|
def depth
|
119
118
|
d = 0
|
120
119
|
current_node = self
|
121
|
-
until current_node.root?
|
120
|
+
until current_node.root?
|
122
121
|
current_node = current_node.parent
|
123
122
|
d += 1
|
124
123
|
end
|
@@ -137,7 +136,7 @@ module Tapyrus
|
|
137
136
|
i = 0
|
138
137
|
d = 1
|
139
138
|
current_node = self
|
140
|
-
until current_node.root?
|
139
|
+
until current_node.root?
|
141
140
|
i += d if current_node.parent.right == current_node
|
142
141
|
current_node = current_node.parent
|
143
142
|
d *= 2
|
data/lib/tapyrus/message.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Tapyrus
|
2
2
|
module Message
|
3
|
-
|
4
3
|
autoload :Base, 'tapyrus/message/base'
|
5
4
|
autoload :Inventory, 'tapyrus/message/inventory'
|
6
5
|
autoload :InventoriesParser, 'tapyrus/message/inventories_parser'
|
@@ -41,30 +40,29 @@ module Tapyrus
|
|
41
40
|
USER_AGENT = "/tapyrusrb:#{Tapyrus::VERSION}/"
|
42
41
|
|
43
42
|
SERVICE_FLAGS = {
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
43
|
+
none: 0,
|
44
|
+
network: 1 << 0, # the node is capable of serving the block chain. It is currently set by all Bitcoin Core node, and is unset by SPV clients or other peers that just want network services but don't provide them.
|
45
|
+
# getutxo: 1 << 1, # BIP-64. not implemented in Bitcoin Core.
|
46
|
+
bloom: 1 << 2 # the node is capable and willing to handle bloom-filtered connections. Bitcoin Core node used to support this by default, without advertising this bit, but no longer do as of protocol version 70011 (= NO_BLOOM_VERSION)
|
47
|
+
#witness: 1 << 3, # the node can be asked for blocks and transactions including witness data.
|
48
|
+
# xthin: 1 << 4 # support Xtreme Thinblocks. not implemented in Bitcoin Core
|
50
49
|
}
|
51
50
|
|
52
51
|
# DEFAULT_SERVICE_FLAGS = SERVICE_FLAGS[:network] | SERVICE_FLAGS[:bloom] | SERVICE_FLAGS[:witness]
|
53
52
|
|
54
53
|
DEFAULT_SERVICE_FLAGS = SERVICE_FLAGS[:none]
|
55
54
|
|
56
|
-
DEFAULT_STOP_HASH =
|
55
|
+
DEFAULT_STOP_HASH = '00' * 32
|
57
56
|
|
58
57
|
# the protocol version.
|
59
58
|
VERSION = {
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
59
|
+
headers: 31_800,
|
60
|
+
pong: 60_001,
|
61
|
+
bloom: 70_011,
|
62
|
+
send_headers: 70_012,
|
63
|
+
fee_filter: 70_013,
|
64
|
+
compact: 70_014,
|
65
|
+
compact_witness: 70_015
|
67
66
|
}
|
68
|
-
|
69
67
|
end
|
70
68
|
end
|
data/lib/tapyrus/message/addr.rb
CHANGED
@@ -2,11 +2,9 @@ require 'ipaddr'
|
|
2
2
|
|
3
3
|
module Tapyrus
|
4
4
|
module Message
|
5
|
-
|
6
5
|
# addr message
|
7
6
|
# https://bitcoin.org/en/developer-reference#addr
|
8
7
|
class Addr < Base
|
9
|
-
|
10
8
|
COMMAND = 'addr'
|
11
9
|
|
12
10
|
attr_reader :addrs
|
@@ -19,17 +17,13 @@ module Tapyrus
|
|
19
17
|
buf = StringIO.new(payload)
|
20
18
|
addr_count = Tapyrus.unpack_var_int_from_io(buf)
|
21
19
|
addr = new
|
22
|
-
addr_count.times
|
23
|
-
addr.addrs << NetworkAddr.parse_from_payload(buf)
|
24
|
-
end
|
20
|
+
addr_count.times { addr.addrs << NetworkAddr.parse_from_payload(buf) }
|
25
21
|
addr
|
26
22
|
end
|
27
23
|
|
28
24
|
def to_payload
|
29
25
|
Tapyrus.pack_var_int(addrs.length) << addrs.map(&:to_payload).join
|
30
26
|
end
|
31
|
-
|
32
27
|
end
|
33
|
-
|
34
28
|
end
|
35
29
|
end
|
data/lib/tapyrus/message/base.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
module Tapyrus
|
2
2
|
module Message
|
3
|
-
|
4
3
|
# block message
|
5
4
|
# https://bitcoin.org/en/developer-reference#block
|
6
5
|
class Block < Base
|
7
|
-
|
8
6
|
attr_accessor :header
|
9
7
|
attr_accessor :transactions
|
10
8
|
attr_accessor :use_segwit
|
@@ -23,24 +21,19 @@ module Tapyrus
|
|
23
21
|
transactions = []
|
24
22
|
unless buf.eof?
|
25
23
|
tx_count = Tapyrus.unpack_var_int_from_io(buf)
|
26
|
-
tx_count.times
|
27
|
-
transactions << Tapyrus::Tx.parse_from_payload(buf)
|
28
|
-
end
|
24
|
+
tx_count.times { transactions << Tapyrus::Tx.parse_from_payload(buf) }
|
29
25
|
end
|
30
26
|
new(header, transactions)
|
31
27
|
end
|
32
28
|
|
33
29
|
def to_payload
|
34
|
-
header.to_payload << Tapyrus.pack_var_int(transactions.size) <<
|
35
|
-
transactions.map(&:to_payload).join
|
30
|
+
header.to_payload << Tapyrus.pack_var_int(transactions.size) << transactions.map(&:to_payload).join
|
36
31
|
end
|
37
32
|
|
38
33
|
# generate Tapyrus::Block object.
|
39
34
|
def to_block
|
40
35
|
Tapyrus::Block.new(header, transactions)
|
41
36
|
end
|
42
|
-
|
43
37
|
end
|
44
|
-
|
45
38
|
end
|
46
39
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module Tapyrus
|
2
2
|
module Message
|
3
|
-
|
4
3
|
# BIP-152 Compact Block's data format.
|
5
4
|
# https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki#BlockTransactionsRequest
|
6
5
|
class BlockTransactionRequest
|
7
|
-
|
8
6
|
attr_accessor :block_hash # When matching with Tapyrus::BlockHeader#hash It is necessary to reverse the byte order.
|
9
7
|
attr_accessor :indexes
|
10
8
|
|
@@ -17,7 +15,8 @@ module Tapyrus
|
|
17
15
|
buf = StringIO.new(payload)
|
18
16
|
block_hash = buf.read(32).bth
|
19
17
|
index_len = Tapyrus.unpack_var_int_from_io(buf)
|
20
|
-
indexes = index_len.times.map{Tapyrus.unpack_var_int_from_io(buf)}
|
18
|
+
indexes = index_len.times.map { Tapyrus.unpack_var_int_from_io(buf) }
|
19
|
+
|
21
20
|
# index data differentially encoded
|
22
21
|
offset = 0
|
23
22
|
index_len.times do |i|
|
@@ -33,13 +32,11 @@ module Tapyrus
|
|
33
32
|
p = block_hash.htb << Tapyrus.pack_var_int(indexes.size)
|
34
33
|
indexes.size.times do |i|
|
35
34
|
index = indexes[i]
|
36
|
-
index -= indexes[i-1] + 1 if i > 0
|
35
|
+
index -= indexes[i - 1] + 1 if i > 0
|
37
36
|
p << Tapyrus.pack_var_int(index)
|
38
37
|
end
|
39
38
|
p
|
40
39
|
end
|
41
|
-
|
42
40
|
end
|
43
|
-
|
44
41
|
end
|
45
42
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module Tapyrus
|
2
2
|
module Message
|
3
|
-
|
4
3
|
# BIP-152 Compact Block's data format.
|
5
4
|
# https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki#BlockTransactions
|
6
5
|
class BlockTransactions
|
7
|
-
|
8
6
|
attr_accessor :block_hash
|
9
7
|
attr_accessor :transactions
|
10
8
|
|
@@ -17,15 +15,13 @@ module Tapyrus
|
|
17
15
|
buf = StringIO.new(payload)
|
18
16
|
block_hash = buf.read(32).bth
|
19
17
|
tx_count = Tapyrus.unpack_var_int_from_io(buf)
|
20
|
-
txn = tx_count.times.map{Tapyrus::Tx.parse_from_payload(buf)}
|
18
|
+
txn = tx_count.times.map { Tapyrus::Tx.parse_from_payload(buf) }
|
21
19
|
self.new(block_hash, txn)
|
22
20
|
end
|
23
21
|
|
24
22
|
def to_payload
|
25
23
|
block_hash.htb << Tapyrus.pack_var_int(transactions.size) << transactions.map(&:to_payload).join
|
26
24
|
end
|
27
|
-
|
28
25
|
end
|
29
|
-
|
30
26
|
end
|
31
|
-
end
|
27
|
+
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module Tapyrus
|
2
2
|
module Message
|
3
|
-
|
4
3
|
# blocktxn message.
|
5
4
|
# https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki#blocktxn
|
6
5
|
class BlockTxn < Base
|
7
|
-
|
8
6
|
COMMAND = 'blocktxn'
|
9
7
|
|
10
8
|
attr_accessor :block_transactions
|
@@ -20,8 +18,6 @@ module Tapyrus
|
|
20
18
|
def to_payload
|
21
19
|
block_transactions.to_payload
|
22
20
|
end
|
23
|
-
|
24
21
|
end
|
25
|
-
|
26
22
|
end
|
27
23
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module Tapyrus
|
2
2
|
module Message
|
3
|
-
|
4
3
|
# cmpctblock message. support only version 1.
|
5
4
|
# https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki
|
6
5
|
class CmpctBlock < Base
|
7
|
-
|
8
6
|
COMMAND = 'cmpctblock'
|
9
7
|
|
10
8
|
attr_accessor :header_and_short_ids
|
@@ -19,9 +17,7 @@ module Tapyrus
|
|
19
17
|
# @return [Tapyrus::Message::CmpctBlock]
|
20
18
|
def self.from_block(block, nonce = SecureRandom.hex(8).to_i(16))
|
21
19
|
h = HeaderAndShortIDs.new(block.header, nonce)
|
22
|
-
block.transactions[1..-1].each
|
23
|
-
h.short_ids << h.short_id(tx.txid)
|
24
|
-
end
|
20
|
+
block.transactions[1..-1].each { |tx| h.short_ids << h.short_id(tx.txid) }
|
25
21
|
h.prefilled_txn << PrefilledTx.new(0, block.transactions.first)
|
26
22
|
self.new(h)
|
27
23
|
end
|
@@ -33,8 +29,6 @@ module Tapyrus
|
|
33
29
|
def to_payload
|
34
30
|
header_and_short_ids.to_payload
|
35
31
|
end
|
36
|
-
|
37
32
|
end
|
38
|
-
|
39
33
|
end
|
40
34
|
end
|