tapyrus 0.2.4 → 0.2.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e7f821324dfe56eb103457c17b585792e2cc250c3738f59f1665aa4a831a917
4
- data.tar.gz: 1faa2850c7dfe07d9be35c75e3c9500e10ef39725db64fc01d88de5548894068
3
+ metadata.gz: 6eacc6d47ecb8c8f955e1713d0245b95185857a313189e232102a24e9dcf43c6
4
+ data.tar.gz: a961c657873aa82e7f917f55c8b00ea80175b9eb2eb363d72c3c1621f7bee9dc
5
5
  SHA512:
6
- metadata.gz: 3299a042ff5f3fa919d4732c1c7c9288cef3bdb213267171d7fa733b53929479b83abb333be1820304fbb593cda742fd8240d8589424536a044901e92cf96823
7
- data.tar.gz: c579e85d346cb81290e5854c303147f32dbe1df3049f4190f05af1fded387aaf7cf7cc4170761fa9eaf409c174b7b37f9f3031193c442567bc95e5d8b1b02e2f
6
+ metadata.gz: 32adab54eb182f5f24536a0b48a89c05756901ba623b054916d7ba5ccc3e034f70147e578917bf847eabdb93070db3b7c628fe3ecc60ebc810ad4603497ec367
7
+ data.tar.gz: e7c802d4cd4081f0dcbf10c317551c47c7ab90ae764e341dfb55e7f32f91bfb28a0680d1ef915ae322ed15ca1524824df690c9e32e7d29fe27df8e080164f5bf
@@ -53,11 +53,11 @@ module Tapyrus
53
53
 
54
54
  module ColoredOutput
55
55
  def colored?
56
- script_pubkey.cp2pkh? || script_pubkey.cp2sh?
56
+ script_pubkey.colored?
57
57
  end
58
58
 
59
59
  def color_id
60
- @color_id ||= ColorIdentifier.parse_from_payload(script_pubkey.chunks[0].pushed_data)
60
+ @color_id ||= script_pubkey.color_id
61
61
  end
62
62
 
63
63
  def reissuable?
@@ -75,6 +75,18 @@ module Tapyrus
75
75
  end
76
76
  end
77
77
 
78
+ # Remove color identifier from cp2pkh or cp2sh
79
+ # @param [ColorIdentifier] color identifier
80
+ # @return [Script] P2PKH or P2SH script
81
+ # @raise [RuntimeError] if script is neither cp2pkh nor cp2sh
82
+ def remove_color
83
+ raise RuntimeError, 'Only cp2pkh and cp2sh can remove color' unless cp2pkh? or cp2sh?
84
+
85
+ Tapyrus::Script.new.tap do |s|
86
+ s.chunks = self.chunks[2..-1]
87
+ end
88
+ end
89
+
78
90
  def get_multisig_pubkeys
79
91
  num = Tapyrus::Opcodes.opcode_to_small_int(chunks[-2].bth.to_i(16))
80
92
  (1..num).map{ |i| chunks[i].pushed_data }
@@ -214,6 +226,8 @@ module Tapyrus
214
226
  (chunks.size == 1 || chunks[1].opcode <= OP_16)
215
227
  end
216
228
 
229
+ # Return whether this script is a CP2PKH format script or not.
230
+ # @return [Boolean] true if this script is cp2pkh, otherwise false.
217
231
  def cp2pkh?
218
232
  return false unless chunks.size == 7
219
233
  return false unless chunks[0].bytesize == 34
@@ -223,6 +237,8 @@ module Tapyrus
223
237
  (chunks[2..3]+ chunks[5..6]).map(&:ord) && chunks[4].bytesize == 21
224
238
  end
225
239
 
240
+ # Return whether this script is a CP2SH format script or not.
241
+ # @return [Boolean] true if this script is cp2pkh, otherwise false.
226
242
  def cp2sh?
227
243
  return false unless chunks.size == 5
228
244
  return false unless chunks[0].bytesize == 34
@@ -230,6 +246,20 @@ module Tapyrus
230
246
  return false unless chunks[1].ord == OP_COLOR
231
247
  OP_HASH160 == chunks[2].ord && OP_EQUAL == chunks[4].ord && chunks[3].bytesize == 21
232
248
  end
249
+
250
+ # Return whether this script represents colored coin.
251
+ # @return [Boolean] true if this script is colored, otherwise false.
252
+ def colored?
253
+ cp2pkh? || cp2sh?
254
+ end
255
+
256
+ # Return color identifier for this script.
257
+ # @return [ColorIdentifer] color identifier for this script if this script is colored. return nil if this script is not colored.
258
+ def color_id
259
+ return nil unless colored?
260
+
261
+ Tapyrus::Color::ColorIdentifier.parse_from_payload(chunks[0].pushed_data)
262
+ end
233
263
 
234
264
  def op_return_data
235
265
  return nil unless op_return?
@@ -1,3 +1,3 @@
1
1
  module Tapyrus
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.authors = ["azuchi"]
11
11
  spec.email = ["azuchi@chaintope.com"]
12
12
 
13
- spec.summary = %q{[WIP]The implementation of Tapyrus Protocol for Ruby.}
14
- spec.description = %q{[WIP]The implementation of Tapyrus Protocol for Ruby.}
13
+ spec.summary = %q{The implementation of Tapyrus Protocol for Ruby.}
14
+ spec.description = %q{The implementation of Tapyrus Protocol for Ruby.}
15
15
  spec.homepage = 'https://github.com/chaintope/tapyrusrb'
16
16
  spec.license = "MIT"
17
17
 
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.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-25 00:00:00.000000000 Z
11
+ date: 2020-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ecdsa
@@ -290,7 +290,7 @@ dependencies:
290
290
  - - "~>"
291
291
  - !ruby/object:Gem::Version
292
292
  version: '3.0'
293
- description: "[WIP]The implementation of Tapyrus Protocol for Ruby."
293
+ description: The implementation of Tapyrus Protocol for Ruby.
294
294
  email:
295
295
  - azuchi@chaintope.com
296
296
  executables:
@@ -452,5 +452,5 @@ requirements: []
452
452
  rubygems_version: 3.0.3
453
453
  signing_key:
454
454
  specification_version: 4
455
- summary: "[WIP]The implementation of Tapyrus Protocol for Ruby."
455
+ summary: The implementation of Tapyrus Protocol for Ruby.
456
456
  test_files: []