tapyrus 0.3.1 → 0.3.3
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/README.md +1 -1
- data/exe/tapyrus-script-debugger +71 -0
- data/lib/tapyrus/block_header.rb +1 -1
- data/lib/tapyrus/constants.rb +0 -2
- data/lib/tapyrus/errors.rb +1 -0
- data/lib/tapyrus/ext_key.rb +6 -3
- data/lib/tapyrus/key.rb +5 -1
- data/lib/tapyrus/script/debugger.rb +164 -0
- data/lib/tapyrus/script/script_interpreter.rb +441 -432
- data/lib/tapyrus/script/tx_checker.rb +5 -9
- data/lib/tapyrus/tx.rb +8 -17
- data/lib/tapyrus/tx_builder.rb +10 -5
- data/lib/tapyrus/version.rb +1 -1
- data/lib/tapyrus.rb +2 -0
- data/tapyrusrb.gemspec +1 -0
- metadata +22 -5
@@ -1,12 +1,10 @@
|
|
1
1
|
module Tapyrus
|
2
2
|
class TxChecker
|
3
|
-
|
4
|
-
|
5
|
-
attr_reader :amount
|
3
|
+
attr_accessor :tx
|
4
|
+
attr_accessor :input_index
|
6
5
|
|
7
|
-
def initialize(tx: nil,
|
6
|
+
def initialize(tx: nil, input_index: nil)
|
8
7
|
@tx = tx
|
9
|
-
@amount = amount
|
10
8
|
@input_index = input_index
|
11
9
|
end
|
12
10
|
|
@@ -14,15 +12,13 @@ module Tapyrus
|
|
14
12
|
# @param [String] script_sig a signature with hex format.
|
15
13
|
# @param [String] pubkey a public key with hex format.
|
16
14
|
# @param [Tapyrus::Script] script_code
|
17
|
-
# @param [Integer] sig_version
|
18
15
|
# @return [Boolean] if check is passed return true, otherwise false.
|
19
|
-
def check_sig(script_sig, pubkey, script_code
|
16
|
+
def check_sig(script_sig, pubkey, script_code)
|
20
17
|
return false if script_sig.empty?
|
21
18
|
script_sig = script_sig.htb
|
22
19
|
hash_type = script_sig[-1].unpack('C').first
|
23
20
|
sig = script_sig[0..-2]
|
24
|
-
sighash =
|
25
|
-
tx.sighash_for_input(input_index, script_code, hash_type: hash_type, amount: amount, sig_version: sig_version)
|
21
|
+
sighash = tx.sighash_for_input(input_index, script_code, hash_type: hash_type)
|
26
22
|
verify_sig(sig.bth, pubkey, sighash)
|
27
23
|
end
|
28
24
|
|
data/lib/tapyrus/tx.rb
CHANGED
@@ -103,34 +103,23 @@ module Tapyrus
|
|
103
103
|
to_payload.bytesize
|
104
104
|
end
|
105
105
|
|
106
|
-
#
|
106
|
+
# Generate signature hash
|
107
107
|
# @param [Integer] input_index input index.
|
108
108
|
# @param [Integer] hash_type signature hash type
|
109
|
-
# @param [Tapyrus::Script] output_script script pubkey or script code. if script pubkey is
|
110
|
-
# @
|
111
|
-
|
112
|
-
# the script code needs is the witnessScript but removing everything up to and including the last executed OP_CODESEPARATOR before the signature checking opcode being executed.
|
113
|
-
def sighash_for_input(
|
114
|
-
input_index,
|
115
|
-
output_script,
|
116
|
-
hash_type: SIGHASH_TYPE[:all],
|
117
|
-
sig_version: :base,
|
118
|
-
amount: nil,
|
119
|
-
skip_separator_index: 0
|
120
|
-
)
|
109
|
+
# @param [Tapyrus::Script] output_script script pubkey or script code. if script pubkey is P2SH, set redeem script to this.
|
110
|
+
# @return [String] sighash
|
111
|
+
def sighash_for_input(input_index, output_script, hash_type: SIGHASH_TYPE[:all])
|
121
112
|
raise ArgumentError, 'input_index must be specified.' unless input_index
|
122
113
|
raise ArgumentError, 'does not exist input corresponding to input_index.' if input_index >= inputs.size
|
123
114
|
raise ArgumentError, 'script_pubkey must be specified.' unless output_script
|
124
|
-
raise ArgumentError, 'unsupported sig version specified.' unless SIG_VERSION.include?(sig_version)
|
125
115
|
sighash_for_legacy(input_index, output_script, hash_type)
|
126
116
|
end
|
127
117
|
|
128
118
|
# verify input signature.
|
129
119
|
# @param [Integer] input_index
|
130
120
|
# @param [Tapyrus::Script] script_pubkey the script pubkey for target input.
|
131
|
-
# @param [Integer] amount the amount of tapyrus, require for witness program only.
|
132
121
|
# @param [Array] flags the flags used when execute script interpreter.
|
133
|
-
def verify_input_sig(input_index, script_pubkey,
|
122
|
+
def verify_input_sig(input_index, script_pubkey, flags: STANDARD_SCRIPT_VERIFY_FLAGS)
|
134
123
|
flags << SCRIPT_VERIFY_P2SH if script_pubkey.p2sh?
|
135
124
|
verify_input_sig_for_legacy(input_index, script_pubkey, flags)
|
136
125
|
end
|
@@ -207,7 +196,9 @@ module Tapyrus
|
|
207
196
|
checker = Tapyrus::TxChecker.new(tx: self, input_index: input_index)
|
208
197
|
interpreter = Tapyrus::ScriptInterpreter.new(checker: checker, flags: flags)
|
209
198
|
|
210
|
-
interpreter.verify_script(script_sig, script_pubkey)
|
199
|
+
result = interpreter.verify_script(script_sig, script_pubkey)
|
200
|
+
warn("Verify failed. Cause: #{interpreter.error}") unless result
|
201
|
+
result
|
211
202
|
end
|
212
203
|
end
|
213
204
|
end
|
data/lib/tapyrus/tx_builder.rb
CHANGED
@@ -89,9 +89,11 @@ module Tapyrus
|
|
89
89
|
script_pubkey = script_pubkey.add_color(color_id)
|
90
90
|
end
|
91
91
|
|
92
|
+
output = Tapyrus::TxOut.new(script_pubkey: script_pubkey, value: value)
|
93
|
+
raise ArgumentError, 'The transaction amount is too small' if color_id.default? && output.dust?
|
92
94
|
@outgoings[color_id] ||= 0
|
93
95
|
@outgoings[color_id] += value
|
94
|
-
@outputs <<
|
96
|
+
@outputs << output
|
95
97
|
self
|
96
98
|
end
|
97
99
|
|
@@ -136,13 +138,16 @@ module Tapyrus
|
|
136
138
|
def add_change(tx)
|
137
139
|
@incomings.each do |color_id, in_amount|
|
138
140
|
out_amount = @outgoings[color_id] || 0
|
139
|
-
|
141
|
+
output =
|
140
142
|
if color_id.default?
|
141
|
-
|
143
|
+
change = in_amount - out_amount - estimated_fee
|
144
|
+
change_output = Tapyrus::TxOut.new(script_pubkey: @change_script_pubkey, value: change)
|
145
|
+
change_output unless change_output.dust?
|
142
146
|
else
|
143
|
-
|
147
|
+
change = in_amount - out_amount
|
148
|
+
Tapyrus::TxOut.new(script_pubkey: @change_script_pubkey.add_color(color_id), value: change) if change > 0
|
144
149
|
end
|
145
|
-
tx.outputs <<
|
150
|
+
tx.outputs << output if output
|
146
151
|
end
|
147
152
|
end
|
148
153
|
|
data/lib/tapyrus/version.rb
CHANGED
data/lib/tapyrus.rb
CHANGED
@@ -24,6 +24,7 @@ module Tapyrus
|
|
24
24
|
autoload :Script, 'tapyrus/script/script'
|
25
25
|
autoload :Multisig, 'tapyrus/script/multisig'
|
26
26
|
autoload :ScriptInterpreter, 'tapyrus/script/script_interpreter'
|
27
|
+
autoload :ScriptDebugger, 'tapyrus/script/debugger'
|
27
28
|
autoload :ScriptError, 'tapyrus/script/script_error'
|
28
29
|
autoload :TxChecker, 'tapyrus/script/tx_checker'
|
29
30
|
autoload :TxIn, 'tapyrus/tx_in'
|
@@ -50,6 +51,7 @@ module Tapyrus
|
|
50
51
|
autoload :Errors, 'tapyrus/errors'
|
51
52
|
autoload :TxBuilder, 'tapyrus/tx_builder'
|
52
53
|
autoload :BIP175, 'tapyrus/bip175'
|
54
|
+
autoload :Contract, 'tapyrus/contract'
|
53
55
|
|
54
56
|
require_relative 'tapyrus/constants'
|
55
57
|
require_relative 'tapyrus/ext/ecdsa'
|
data/tapyrusrb.gemspec
CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_runtime_dependency 'siphash'
|
32
32
|
spec.add_runtime_dependency 'activesupport', '>= 5.2.3'
|
33
33
|
spec.add_runtime_dependency 'json_pure', '>= 2.3.1'
|
34
|
+
spec.add_runtime_dependency 'terminal-table', '~> 3.0.2'
|
34
35
|
|
35
36
|
# for options
|
36
37
|
spec.add_development_dependency 'leveldb-native'
|
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.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- azuchi
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ecdsa
|
@@ -178,6 +178,20 @@ dependencies:
|
|
178
178
|
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: 2.3.1
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: terminal-table
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 3.0.2
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 3.0.2
|
181
195
|
- !ruby/object:Gem::Dependency
|
182
196
|
name: leveldb-native
|
183
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -280,6 +294,7 @@ description: The implementation of Tapyrus Protocol for Ruby.
|
|
280
294
|
email:
|
281
295
|
- azuchi@chaintope.com
|
282
296
|
executables:
|
297
|
+
- tapyrus-script-debugger
|
283
298
|
- tapyrusrb-cli
|
284
299
|
- tapyrusrbd
|
285
300
|
extensions: []
|
@@ -299,6 +314,7 @@ files:
|
|
299
314
|
- Rakefile
|
300
315
|
- bin/console
|
301
316
|
- bin/setup
|
317
|
+
- exe/tapyrus-script-debugger
|
302
318
|
- exe/tapyrusrb-cli
|
303
319
|
- exe/tapyrusrbd
|
304
320
|
- lib/openassets.rb
|
@@ -389,6 +405,7 @@ files:
|
|
389
405
|
- lib/tapyrus/rpc/request_handler.rb
|
390
406
|
- lib/tapyrus/rpc/tapyrus_core_client.rb
|
391
407
|
- lib/tapyrus/script/color.rb
|
408
|
+
- lib/tapyrus/script/debugger.rb
|
392
409
|
- lib/tapyrus/script/multisig.rb
|
393
410
|
- lib/tapyrus/script/script.rb
|
394
411
|
- lib/tapyrus/script/script_error.rb
|
@@ -425,7 +442,7 @@ homepage: https://github.com/chaintope/tapyrusrb
|
|
425
442
|
licenses:
|
426
443
|
- MIT
|
427
444
|
metadata: {}
|
428
|
-
post_install_message:
|
445
|
+
post_install_message:
|
429
446
|
rdoc_options: []
|
430
447
|
require_paths:
|
431
448
|
- lib
|
@@ -441,7 +458,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
441
458
|
version: '0'
|
442
459
|
requirements: []
|
443
460
|
rubygems_version: 3.3.7
|
444
|
-
signing_key:
|
461
|
+
signing_key:
|
445
462
|
specification_version: 4
|
446
463
|
summary: The implementation of Tapyrus Protocol for Ruby.
|
447
464
|
test_files: []
|