tapyrus 0.2.7 → 0.2.8
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/.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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ad31bf4aa539aa394eeb5002fe11fc9b8c6a43aab73c9e36a63220159c2fb30
|
4
|
+
data.tar.gz: 8b7aaacfd238de278b334b7b26249045facf14843b8fb32985045c0a52b9cdc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad3bc4d2fbaaf0e228cd7c07ee78e878f6b913e971645b8a6e188df70c9e363fbc210456833436f1e7ea780881bd10accdd7a069365e26fc09195744fe606766
|
7
|
+
data.tar.gz: b267bb2ff699df8822feffc75573db5e506dc5490f5f79146cfaf16d20abfd14660ddbfa4f2f01401d54b5bb9ecdb646613de8c7a28b01d48260aebb862834d3
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [master]
|
13
|
+
pull_request:
|
14
|
+
branches: [master]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
strategy:
|
20
|
+
matrix:
|
21
|
+
ruby-version: ["2.5", "2.6", "2.7", "3.0"]
|
22
|
+
|
23
|
+
steps:
|
24
|
+
- run: sudo apt install libleveldb-dev
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
+
# uses: ruby/setup-ruby@v1
|
30
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
- name: Run prettier
|
35
|
+
run: bundle exec rbprettier --check .
|
36
|
+
- name: Run tests
|
37
|
+
run: bundle exec rake
|
data/.prettierignore
ADDED
data/.prettierrc.yaml
ADDED
data/CODE_OF_CONDUCT.md
CHANGED
@@ -12,13 +12,13 @@ body size, race, ethnicity, age, religion, or nationality.
|
|
12
12
|
|
13
13
|
Examples of unacceptable behavior by participants include:
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
- The use of sexualized language or imagery
|
16
|
+
- Personal attacks
|
17
|
+
- Trolling or insulting/derogatory comments
|
18
|
+
- Public or private harassment
|
19
|
+
- Publishing other's private information, such as physical or electronic
|
20
20
|
addresses, without explicit permission
|
21
|
-
|
21
|
+
- Other unethical or unprofessional conduct
|
22
22
|
|
23
23
|
Project maintainers have the right and responsibility to remove, edit, or
|
24
24
|
reject comments, commits, code, wiki edits, issues, and other contributions
|
@@ -46,4 +46,4 @@ version 1.3.0, available at
|
|
46
46
|
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
47
|
|
48
48
|
[homepage]: http://contributor-covenant.org
|
49
|
-
[version]: http://contributor-covenant.org/version/1/3/0/
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/README.md
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
# Tapyrusrb [](https://travis-ci.org/chaintope/tapyrusrb) [](https://badge.fury.io/rb/tapyrus) [](LICENSE)
|
2
2
|
|
3
|
-
|
4
3
|
Tapyrusrb is a Ruby implementation of [Tapyrus](https://github.com/chaintope/tapyrus-core) Protocol.
|
5
4
|
|
6
|
-
NOTE: Tapyrusrb work in progress, and there is a possibility of incompatible change.
|
5
|
+
NOTE: Tapyrusrb work in progress, and there is a possibility of incompatible change.
|
7
6
|
|
8
7
|
## Features
|
9
8
|
|
10
9
|
Tapyrusrb supports following feature:
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
- Tapyrus script interpreter
|
12
|
+
- De/serialization of Tapyrus protocol network messages
|
13
|
+
- De/serialization of blocks and transactions
|
14
|
+
- Key generation and verification for Schnorr and ECDSA (including [BIP-32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) and [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) supports).
|
15
|
+
- ECDSA signature(RFC6979 -Deterministic ECDSA, LOW-S, LOW-R support)
|
16
|
+
- [WIP] SPV node
|
17
|
+
- [WIP] 0ff-chain protocol
|
19
18
|
|
20
19
|
## Requirements
|
21
20
|
|
@@ -25,13 +24,13 @@ If you use node features, please install level DB as follows.
|
|
25
24
|
|
26
25
|
#### install LevelDB
|
27
26
|
|
28
|
-
|
27
|
+
- for Ubuntu
|
29
28
|
|
30
|
-
|
29
|
+
$ sudo apt-get install libleveldb-dev
|
31
30
|
|
32
|
-
|
31
|
+
* for Mac
|
33
32
|
|
34
|
-
|
33
|
+
$ brew install leveldb
|
35
34
|
|
36
35
|
and put `leveldb-native` in your Gemfile and run bundle install.
|
37
36
|
|
@@ -65,7 +64,7 @@ And then add to your .rb file:
|
|
65
64
|
|
66
65
|
The parameters of the blockchain are managed by `Tapyrus::ChainParams`. Switch chain parameters as follows:
|
67
66
|
|
68
|
-
|
67
|
+
- prod
|
69
68
|
|
70
69
|
```ruby
|
71
70
|
Tapyrus.chain_params = :prod
|
@@ -73,7 +72,7 @@ Tapyrus.chain_params = :prod
|
|
73
72
|
|
74
73
|
This parameter is described in https://github.com/chaintope/tapyrusrb/blob/master/lib/tapyrus/chainparams/prod.yml.
|
75
74
|
|
76
|
-
|
75
|
+
- dev
|
77
76
|
|
78
77
|
```ruby
|
79
78
|
Tapyrus.chain_params = :dev
|
@@ -85,8 +84,6 @@ This parameter is described in https://github.com/chaintope/tapyrusrb/blob/maste
|
|
85
84
|
|
86
85
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tapyrusrb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
87
86
|
|
88
|
-
|
89
87
|
## License
|
90
88
|
|
91
89
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
92
|
-
|
data/Rakefile
CHANGED
data/lib/openassets.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
module OpenAssets
|
2
|
-
|
3
2
|
module MarkerOutput
|
4
|
-
|
5
3
|
# whether this output is marker output for open assets.
|
6
4
|
def open_assets_marker?
|
7
5
|
return false unless script_pubkey.op_return?
|
@@ -14,7 +12,5 @@ module OpenAssets
|
|
14
12
|
return nil unless script_pubkey.op_return?
|
15
13
|
Payload.parse_from_payload(script_pubkey.op_return_data)
|
16
14
|
end
|
17
|
-
|
18
15
|
end
|
19
|
-
|
20
16
|
end
|
data/lib/openassets/payload.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module OpenAssets
|
4
|
-
|
5
4
|
MARKER = "\x4f\x41"
|
6
5
|
VERSION = "\x01\x00"
|
7
6
|
|
8
7
|
# the open assets payload
|
9
8
|
class Payload
|
10
|
-
|
11
9
|
attr_accessor :quantities
|
12
10
|
attr_accessor :metadata
|
13
11
|
|
@@ -26,14 +24,12 @@ module OpenAssets
|
|
26
24
|
count = Tapyrus.unpack_var_int_from_io(buf)
|
27
25
|
return nil unless count
|
28
26
|
quantities = []
|
29
|
-
count.times
|
30
|
-
quantities << LEB128.decode_unsigned(buf, buf.pos)
|
31
|
-
end
|
27
|
+
count.times { quantities << LEB128.decode_unsigned(buf, buf.pos) }
|
32
28
|
metadata_length = Tapyrus.unpack_var_int_from_io(buf)
|
33
29
|
return nil if metadata_length.nil? || buf.length < metadata_length + buf.pos
|
34
30
|
metadata = buf.read(metadata_length).each_byte.map(&:chr).join
|
35
31
|
new(quantities, metadata)
|
36
|
-
rescue
|
32
|
+
rescue StandardError
|
37
33
|
# LEB128#decode_unsigned raise 'undefined method `unpack' for nil:NilClass'
|
38
34
|
# for invalid format such as "018f8f" (the most significant bit of the last byte should be 0)
|
39
35
|
nil
|
@@ -44,11 +40,9 @@ module OpenAssets
|
|
44
40
|
payload = String.new
|
45
41
|
payload << MARKER
|
46
42
|
payload << VERSION
|
47
|
-
payload << Tapyrus.pack_var_int(quantities.size) << quantities.map{|q| LEB128.encode_unsigned(q).read }.join
|
48
|
-
payload << Tapyrus.pack_var_int(metadata.length) << metadata.bytes.map{|b| sprintf(
|
43
|
+
payload << Tapyrus.pack_var_int(quantities.size) << quantities.map { |q| LEB128.encode_unsigned(q).read }.join
|
44
|
+
payload << Tapyrus.pack_var_int(metadata.length) << metadata.bytes.map { |b| sprintf('%02x', b) }.join.htb
|
49
45
|
payload
|
50
46
|
end
|
51
|
-
|
52
47
|
end
|
53
|
-
|
54
48
|
end
|
data/lib/schnorr.rb
CHANGED
@@ -76,8 +76,7 @@ module Schnorr
|
|
76
76
|
# @return (Integer) digest e.
|
77
77
|
def create_challenge(x, p, message)
|
78
78
|
r_x = ECDSA::Format::IntegerOctetString.encode(x, GROUP.byte_length)
|
79
|
-
p_str= p.to_hex.htb
|
79
|
+
p_str = p.to_hex.htb
|
80
80
|
(ECDSA.normalize_digest(Digest::SHA256.digest(r_x + p_str + message), GROUP.bit_length)) % GROUP.order
|
81
81
|
end
|
82
|
-
|
83
|
-
end
|
82
|
+
end
|
data/lib/schnorr/signature.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
module Schnorr
|
2
|
-
|
3
|
-
|
2
|
+
class InvalidSignatureError < StandardError
|
3
|
+
end
|
4
4
|
|
5
5
|
# Instances of this class represents Schnorr signatures,
|
6
6
|
# which are simply a pair of integers named `r` and `s`.
|
7
7
|
class Signature
|
8
|
-
|
9
8
|
attr_reader :r
|
10
9
|
attr_reader :s
|
11
10
|
|
@@ -32,7 +31,5 @@ module Schnorr
|
|
32
31
|
def encode
|
33
32
|
ECDSA::Format::IntegerOctetString.encode(r, 32) + ECDSA::Format::IntegerOctetString.encode(s, 32)
|
34
33
|
end
|
35
|
-
|
36
34
|
end
|
37
|
-
|
38
|
-
end
|
35
|
+
end
|
data/lib/tapyrus.rb
CHANGED
@@ -13,7 +13,6 @@ require_relative 'openassets'
|
|
13
13
|
require_relative 'schnorr'
|
14
14
|
|
15
15
|
module Tapyrus
|
16
|
-
|
17
16
|
autoload :Ext, 'tapyrus/ext'
|
18
17
|
autoload :Util, 'tapyrus/util'
|
19
18
|
autoload :ChainParams, 'tapyrus/chain_params'
|
@@ -49,6 +48,7 @@ module Tapyrus
|
|
49
48
|
autoload :SLIP39, 'tapyrus/slip39'
|
50
49
|
autoload :Color, 'tapyrus/script/color'
|
51
50
|
autoload :Errors, 'tapyrus/errors'
|
51
|
+
autoload :TxBuilder, 'tapyrus/tx_builder'
|
52
52
|
|
53
53
|
require_relative 'tapyrus/constants'
|
54
54
|
require_relative 'tapyrus/ext/ecdsa'
|
@@ -59,7 +59,7 @@ module Tapyrus
|
|
59
59
|
|
60
60
|
# set tapyrus network chain params
|
61
61
|
def self.chain_params=(name)
|
62
|
-
raise "chain params for #{name} is not defined." unless %i
|
62
|
+
raise "chain params for #{name} is not defined." unless %i[prod dev].include?(name.to_sym)
|
63
63
|
@current_chain = nil
|
64
64
|
@chain_param = name.to_sym
|
65
65
|
end
|
@@ -153,17 +153,11 @@ module Tapyrus
|
|
153
153
|
def valid_hex?
|
154
154
|
!self[/\H/]
|
155
155
|
end
|
156
|
-
|
157
156
|
end
|
158
157
|
|
159
158
|
class ::Object
|
160
|
-
|
161
159
|
def build_json
|
162
|
-
|
163
|
-
"[#{self.map{|o|o.to_h.to_json}.join(',')}]"
|
164
|
-
else
|
165
|
-
to_h.to_json
|
166
|
-
end
|
160
|
+
self.is_a?(Array) ? "[#{self.map { |o| o.to_h.to_json }.join(',')}]" : to_h.to_json
|
167
161
|
end
|
168
162
|
|
169
163
|
def to_h
|
@@ -172,14 +166,9 @@ module Tapyrus
|
|
172
166
|
key = var.to_s
|
173
167
|
key.slice!(0) if key.start_with?('@')
|
174
168
|
value = instance_variable_get(var)
|
175
|
-
|
176
|
-
result.update(key => value.map{|v|v.to_h})
|
177
|
-
else
|
178
|
-
result.update(key => value)
|
179
|
-
end
|
169
|
+
value.is_a?(Array) ? result.update(key => value.map { |v| v.to_h }) : result.update(key => value)
|
180
170
|
end
|
181
171
|
end
|
182
|
-
|
183
172
|
end
|
184
173
|
|
185
174
|
class ::Integer
|
@@ -193,13 +182,8 @@ module Tapyrus
|
|
193
182
|
end
|
194
183
|
|
195
184
|
# convert bit string
|
196
|
-
def to_bits(length = nil
|
197
|
-
|
198
|
-
to_s(2).rjust(length, '0')
|
199
|
-
else
|
200
|
-
to_s(2)
|
201
|
-
end
|
185
|
+
def to_bits(length = nil)
|
186
|
+
length ? to_s(2).rjust(length, '0') : to_s(2)
|
202
187
|
end
|
203
188
|
end
|
204
|
-
|
205
189
|
end
|
data/lib/tapyrus/base58.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
module Tapyrus
|
2
|
-
|
3
2
|
# Base58Check encoding
|
4
3
|
# https://en.bitcoin.it/wiki/Base58Check_encoding
|
5
4
|
module Base58
|
@@ -23,16 +22,18 @@ module Tapyrus
|
|
23
22
|
# decode base58 string to hex value.
|
24
23
|
def decode(base58_val)
|
25
24
|
int_val = 0
|
26
|
-
base58_val
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
base58_val
|
26
|
+
.reverse
|
27
|
+
.split(//)
|
28
|
+
.each_with_index do |char, index|
|
29
|
+
raise ArgumentError, 'Value passed not a valid Base58 String.' if (char_index = ALPHABET.index(char)).nil?
|
30
|
+
int_val += char_index * (SIZE**index)
|
31
|
+
end
|
30
32
|
s = int_val.to_even_length_hex
|
31
33
|
s = '' if s == '00'
|
32
34
|
leading_zero_bytes = (base58_val.match(/^([1]+)/) ? $1 : '').size
|
33
35
|
s = ('00' * leading_zero_bytes) + s if leading_zero_bytes > 0
|
34
36
|
s
|
35
37
|
end
|
36
|
-
|
37
38
|
end
|
38
39
|
end
|
data/lib/tapyrus/block.rb
CHANGED
data/lib/tapyrus/block_header.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
module Tapyrus
|
2
|
-
|
3
2
|
# Block Header
|
4
3
|
class BlockHeader
|
5
4
|
include Tapyrus::HexConverter
|
6
5
|
extend Tapyrus::Util
|
7
6
|
include Tapyrus::Util
|
8
7
|
|
9
|
-
X_FILED_TYPES = {none: 0, aggregate_pubkey: 1}
|
8
|
+
X_FILED_TYPES = { none: 0, aggregate_pubkey: 1 }
|
10
9
|
|
11
10
|
attr_accessor :features
|
12
11
|
attr_accessor :prev_hash
|
13
12
|
attr_accessor :merkle_root
|
14
13
|
attr_accessor :im_merkle_root # merkel root of immulable merkle tree which consist of immutable txid.
|
15
|
-
attr_accessor :time
|
14
|
+
attr_accessor :time # unix timestamp
|
16
15
|
attr_accessor :x_field_type
|
17
16
|
attr_accessor :x_field
|
18
17
|
attr_accessor :proof
|
@@ -33,7 +32,16 @@ module Tapyrus
|
|
33
32
|
features, prev_hash, merkle_root, im_merkle_root, time, x_filed_type = buf.read(105).unpack('Va32a32a32Vc')
|
34
33
|
x_field = buf.read(unpack_var_int_from_io(buf)) unless x_filed_type == X_FILED_TYPES[:none]
|
35
34
|
proof = buf.read(unpack_var_int_from_io(buf))
|
36
|
-
new(
|
35
|
+
new(
|
36
|
+
features,
|
37
|
+
prev_hash.bth,
|
38
|
+
merkle_root.bth,
|
39
|
+
im_merkle_root.bth,
|
40
|
+
time,
|
41
|
+
x_filed_type,
|
42
|
+
x_field ? x_field.bth : x_field,
|
43
|
+
proof.bth
|
44
|
+
)
|
37
45
|
end
|
38
46
|
|
39
47
|
def to_payload(skip_proof = false)
|
@@ -87,9 +95,9 @@ module Tapyrus
|
|
87
95
|
# @return [Boolean] if valid return true, otherwise false
|
88
96
|
def valid_x_field?
|
89
97
|
case x_field_type
|
90
|
-
when X_FILED_TYPES[:none]
|
98
|
+
when X_FILED_TYPES[:none]
|
91
99
|
x_field.nil?
|
92
|
-
when X_FILED_TYPES[:aggregate_pubkey]
|
100
|
+
when X_FILED_TYPES[:aggregate_pubkey]
|
93
101
|
Tapyrus::Key.new(pubkey: x_field).fully_valid_pubkey?
|
94
102
|
else
|
95
103
|
false
|
@@ -111,7 +119,5 @@ module Tapyrus
|
|
111
119
|
def size
|
112
120
|
to_payload.bytesize
|
113
121
|
end
|
114
|
-
|
115
122
|
end
|
116
|
-
|
117
|
-
end
|
123
|
+
end
|