tapyrus 0.2.12 → 0.3.1
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 +2 -3
- data/.ruby-version +1 -1
- data/lib/tapyrus/chain_params.rb +2 -1
- data/lib/tapyrus/ext.rb +16 -0
- data/lib/tapyrus/network/message_handler.rb +2 -0
- data/lib/tapyrus/rpc/request_handler.rb +1 -1
- data/lib/tapyrus/rpc/tapyrus_core_client.rb +14 -3
- data/lib/tapyrus/script/script.rb +24 -22
- data/lib/tapyrus/version.rb +1 -1
- data/lib/tapyrus.rb +0 -16
- data/tapyrusrb.gemspec +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc2e90197905239fab7d891f05da735cf1fb2df0127abbb1ca38c1299130914d
|
4
|
+
data.tar.gz: 36a9a028b360a238077bd30c2380b3c722983d5dbd7e5f5d9e6e1d2dbd1408c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e336315f9e68a361edf4b0e2dec290a6e37f666375badc13336391289b773084d57ac324fa5e1b3334faa6400d931abd24dda05345901767a29e9f11251200bc
|
7
|
+
data.tar.gz: a1a3df8abf276b794eed62cd7b238d57fa909315f116d5f12c4b472e32b24c8da1ff8cc62e656fb985cf5728e24a7821580b1f24f09613535a2be4b23f3bf1fa
|
data/.github/workflows/ruby.yml
CHANGED
@@ -18,7 +18,7 @@ jobs:
|
|
18
18
|
runs-on: ubuntu-latest
|
19
19
|
strategy:
|
20
20
|
matrix:
|
21
|
-
ruby-version: ["2.
|
21
|
+
ruby-version: ["2.6", "2.7", "3.0", "3.1"]
|
22
22
|
|
23
23
|
steps:
|
24
24
|
- run: sudo apt install libleveldb-dev
|
@@ -26,8 +26,7 @@ jobs:
|
|
26
26
|
- name: Set up Ruby
|
27
27
|
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
28
|
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
-
|
30
|
-
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
29
|
+
uses: ruby/setup-ruby@v1
|
31
30
|
with:
|
32
31
|
ruby-version: ${{ matrix.ruby-version }}
|
33
32
|
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.1.2
|
data/lib/tapyrus/chain_params.rb
CHANGED
@@ -54,7 +54,8 @@ module Tapyrus
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def self.init(name)
|
57
|
-
|
57
|
+
yaml = File.open("#{__dir__}/chainparams/#{name}.yml")
|
58
|
+
i = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(yaml) : YAML.load(yaml)
|
58
59
|
i.dust_relay_fee ||= Tapyrus::DUST_RELAY_TX_FEE
|
59
60
|
i
|
60
61
|
end
|
data/lib/tapyrus/ext.rb
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
module Tapyrus
|
2
2
|
module Ext
|
3
3
|
autoload :JsonParser, 'tapyrus/ext/json_parser'
|
4
|
+
|
5
|
+
refine Object do
|
6
|
+
def build_json
|
7
|
+
self.is_a?(Array) ? "[#{self.map { |o| o.to_h.to_json }.join(',')}]" : to_h.to_json
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_h
|
11
|
+
return self if self.is_a?(String)
|
12
|
+
instance_variables.inject({}) do |result, var|
|
13
|
+
key = var.to_s
|
14
|
+
key.slice!(0) if key.start_with?('@')
|
15
|
+
value = instance_variable_get(var)
|
16
|
+
value.is_a?(Array) ? result.update(key => value.map { |v| v.to_h }) : result.update(key => value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
4
20
|
end
|
5
21
|
end
|
@@ -96,7 +96,7 @@ module Tapyrus
|
|
96
96
|
script = Tapyrus::Script.parse_from_payload(hex_script.htb)
|
97
97
|
h = script.to_h
|
98
98
|
h.delete(:hex)
|
99
|
-
h[:p2sh] = script.to_p2sh.
|
99
|
+
h[:p2sh] = script.to_p2sh.to_addr unless script.p2sh?
|
100
100
|
h
|
101
101
|
rescue Exception
|
102
102
|
raise ArgumentError.new('Script decode failed')
|
@@ -24,8 +24,13 @@ module Tapyrus
|
|
24
24
|
@rpc_error = rpc_error
|
25
25
|
end
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
# Return response object as Hash
|
28
|
+
# @return [Hash] response
|
29
|
+
# @option response_code [Integer] HTTP status code
|
30
|
+
# @option response_msg [String] HTTP response body
|
31
|
+
# @option rpc_error [String] error message received from Tapyrus Core
|
32
|
+
def response
|
33
|
+
@response ||=
|
29
34
|
begin
|
30
35
|
m = { response_code: response_code, response_msg: response_msg }
|
31
36
|
m.merge!(rpc_error: rpc_error) if rpc_error
|
@@ -33,8 +38,14 @@ module Tapyrus
|
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
41
|
+
# Return string that represents error message.
|
42
|
+
# @return [String] error message
|
43
|
+
def message
|
44
|
+
response.to_json
|
45
|
+
end
|
46
|
+
|
36
47
|
def to_s
|
37
|
-
message
|
48
|
+
message
|
38
49
|
end
|
39
50
|
end
|
40
51
|
|
@@ -61,7 +61,7 @@ module Tapyrus
|
|
61
61
|
end
|
62
62
|
|
63
63
|
# Add color identifier to existing p2pkh or p2sh
|
64
|
-
# @param [ColorIdentifier] color identifier
|
64
|
+
# @param [ColorIdentifier] color_id color identifier
|
65
65
|
# @return [Script] CP2PKH or CP2SH script
|
66
66
|
# @raise [ArgumentError] if color_id is nil or invalid
|
67
67
|
# @raise [RuntimeError] if script is neither p2pkh nor p2sh
|
@@ -75,7 +75,6 @@ module Tapyrus
|
|
75
75
|
end
|
76
76
|
|
77
77
|
# Remove color identifier from cp2pkh or cp2sh
|
78
|
-
# @param [ColorIdentifier] color identifier
|
79
78
|
# @return [Script] P2PKH or P2SH script
|
80
79
|
# @raise [RuntimeError] if script is neither cp2pkh nor cp2sh
|
81
80
|
def remove_color
|
@@ -118,26 +117,18 @@ module Tapyrus
|
|
118
117
|
# @param [String] addr address.
|
119
118
|
# @return [Tapyrus::Script] parsed script.
|
120
119
|
def self.parse_from_addr(addr)
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
Tapyrus::Script.
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
color = Tapyrus::Color::ColorIdentifier.parse_from_payload(hex[0..65].htb)
|
134
|
-
Tapyrus::Script.to_cp2pkh(color, hex[66..-1])
|
135
|
-
when Tapyrus.chain_params.cp2sh_version
|
136
|
-
color = Tapyrus::Color::ColorIdentifier.parse_from_payload(hex[0..65].htb)
|
137
|
-
Tapyrus::Script.to_cp2sh(color, hex[66..-1])
|
138
|
-
else
|
139
|
-
throw e
|
140
|
-
end
|
120
|
+
hex, addr_version = Tapyrus.decode_base58_address(addr)
|
121
|
+
case addr_version
|
122
|
+
when Tapyrus.chain_params.address_version
|
123
|
+
Tapyrus::Script.to_p2pkh(hex)
|
124
|
+
when Tapyrus.chain_params.p2sh_version
|
125
|
+
Tapyrus::Script.to_p2sh(hex)
|
126
|
+
when Tapyrus.chain_params.cp2pkh_version
|
127
|
+
color = Tapyrus::Color::ColorIdentifier.parse_from_payload(hex[0..65].htb)
|
128
|
+
Tapyrus::Script.to_cp2pkh(color, hex[66..-1])
|
129
|
+
when Tapyrus.chain_params.cp2sh_version
|
130
|
+
color = Tapyrus::Color::ColorIdentifier.parse_from_payload(hex[0..65].htb)
|
131
|
+
Tapyrus::Script.to_cp2sh(color, hex[66..-1])
|
141
132
|
end
|
142
133
|
end
|
143
134
|
|
@@ -189,6 +180,17 @@ module Tapyrus
|
|
189
180
|
chunks.size == 0
|
190
181
|
end
|
191
182
|
|
183
|
+
# Returns the address corresponding to this script. Return nil if there is no corresponding address.
|
184
|
+
# @return [String] address
|
185
|
+
def to_addr
|
186
|
+
return p2pkh_addr if p2pkh?
|
187
|
+
return p2sh_addr if p2sh?
|
188
|
+
return cp2pkh_addr if cp2pkh?
|
189
|
+
return cp2sh_addr if cp2sh?
|
190
|
+
nil
|
191
|
+
end
|
192
|
+
|
193
|
+
# @deprecated use #to_addr method.
|
192
194
|
def addresses
|
193
195
|
return [p2pkh_addr] if p2pkh?
|
194
196
|
return [p2sh_addr] if p2sh?
|
data/lib/tapyrus/version.rb
CHANGED
data/lib/tapyrus.rb
CHANGED
@@ -156,22 +156,6 @@ module Tapyrus
|
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
|
-
class ::Object
|
160
|
-
def build_json
|
161
|
-
self.is_a?(Array) ? "[#{self.map { |o| o.to_h.to_json }.join(',')}]" : to_h.to_json
|
162
|
-
end
|
163
|
-
|
164
|
-
def to_h
|
165
|
-
return self if self.is_a?(String)
|
166
|
-
instance_variables.inject({}) do |result, var|
|
167
|
-
key = var.to_s
|
168
|
-
key.slice!(0) if key.start_with?('@')
|
169
|
-
value = instance_variable_get(var)
|
170
|
-
value.is_a?(Array) ? result.update(key => value.map { |v| v.to_h }) : result.update(key => value)
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
159
|
class ::Integer
|
176
160
|
def to_even_length_hex
|
177
161
|
hex = to_s(16)
|
data/tapyrusrb.gemspec
CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_development_dependency 'leveldb-native'
|
37
37
|
|
38
38
|
spec.add_development_dependency 'bundler'
|
39
|
-
spec.add_development_dependency 'prettier'
|
39
|
+
spec.add_development_dependency 'prettier', '2.0.0'
|
40
40
|
spec.add_development_dependency 'rake', '>= 12.3.3'
|
41
41
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
42
42
|
spec.add_development_dependency 'timecop'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tapyrus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- azuchi
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ecdsa
|
@@ -210,16 +210,16 @@ dependencies:
|
|
210
210
|
name: prettier
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
212
212
|
requirements:
|
213
|
-
- -
|
213
|
+
- - '='
|
214
214
|
- !ruby/object:Gem::Version
|
215
|
-
version:
|
215
|
+
version: 2.0.0
|
216
216
|
type: :development
|
217
217
|
prerelease: false
|
218
218
|
version_requirements: !ruby/object:Gem::Requirement
|
219
219
|
requirements:
|
220
|
-
- -
|
220
|
+
- - '='
|
221
221
|
- !ruby/object:Gem::Version
|
222
|
-
version:
|
222
|
+
version: 2.0.0
|
223
223
|
- !ruby/object:Gem::Dependency
|
224
224
|
name: rake
|
225
225
|
requirement: !ruby/object:Gem::Requirement
|
@@ -425,7 +425,7 @@ homepage: https://github.com/chaintope/tapyrusrb
|
|
425
425
|
licenses:
|
426
426
|
- MIT
|
427
427
|
metadata: {}
|
428
|
-
post_install_message:
|
428
|
+
post_install_message:
|
429
429
|
rdoc_options: []
|
430
430
|
require_paths:
|
431
431
|
- lib
|
@@ -440,8 +440,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
440
440
|
- !ruby/object:Gem::Version
|
441
441
|
version: '0'
|
442
442
|
requirements: []
|
443
|
-
rubygems_version: 3.
|
444
|
-
signing_key:
|
443
|
+
rubygems_version: 3.3.7
|
444
|
+
signing_key:
|
445
445
|
specification_version: 4
|
446
446
|
summary: The implementation of Tapyrus Protocol for Ruby.
|
447
447
|
test_files: []
|