openassets-ruby 0.5.6 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73a2e3f9a8afacf4353d268e424223fd17baaa11
4
- data.tar.gz: 194c9b3a032235108ae763f7c9f4fe967e3e763b
3
+ metadata.gz: 76264bfa708badea9cd4797851dbf74c8d96e869
4
+ data.tar.gz: 1bf65b91f46e0e81b6a4b5b7ee580dc4b131cb3c
5
5
  SHA512:
6
- metadata.gz: 8ea7f8836af8f8095145692593b05f79c399c6cb5a90cd9fb40291bdc093a65f0994c5b987b56241ffe444e7680c85c06b8e3fc25f34cf09ea174274d023e826
7
- data.tar.gz: 0ef222597d3614e49481d953eb11e1453e892ca1b8ee68c7287d8c96c4ea1f83f7c8392a6de933000b68108b5ed2a14615c4abca5d95f6ebb02788577267b393
6
+ metadata.gz: 9f4b49c84af17ef43f9e0b961d65b4320566c2174ebaa9dd036295448ecbd5b5769ab118bf01f14283862a7c02dcbb0d61ffa9e3a04a6195a2d7ee83c1c4fa93
7
+ data.tar.gz: c5da7028a8bed46e6488544972bec5e129b6b3f6aa7bea56f09ea977b2c9f1257c74302fe28ee69ac14415a85b88614c0e7c227c9ca8d220cff2f7c47bb8ad0c
@@ -59,6 +59,7 @@ module OpenAssets
59
59
  'address' => address,
60
60
  'oa_address' => oa_address,
61
61
  'script' => @script.to_payload.bth,
62
+ 'script_type' => script_type,
62
63
  'amount' => satoshi_to_coin(@value),
63
64
  'asset_id' => @asset_id,
64
65
  'asset_quantity' => @asset_quantity.to_s,
@@ -89,6 +90,30 @@ module OpenAssets
89
90
  end
90
91
  end
91
92
 
93
+ # get pubkey script type
94
+ def script_type
95
+ case @script.type
96
+ when :hash160
97
+ 'pubkeyhash'
98
+ when :pubkey
99
+ 'pubkey'
100
+ when :multisig
101
+ 'multisig'
102
+ when :p2sh
103
+ 'scripthash'
104
+ when :op_return
105
+ 'nulldata'
106
+ when :witness_v0_keyhash
107
+ 'witness_v0_keyhash'
108
+ when :witness_v0_scripthash
109
+ 'witness_v0_scripthash'
110
+ when :unknown
111
+ 'nonstandard'
112
+ else
113
+ 'nonstandard'
114
+ end
115
+ end
116
+
92
117
  private
93
118
 
94
119
  @@definition_cache = {}
@@ -56,7 +56,7 @@ module OpenAssets
56
56
 
57
57
  # LEB128 encode
58
58
  def encode_leb128(value)
59
- LEB128.encode(value, false).read.bth
59
+ LEB128.encode_unsigned(value).read.bth
60
60
  end
61
61
 
62
62
  # LEB128 decode
@@ -66,7 +66,7 @@ module OpenAssets
66
66
  value.htb.each_byte{|b|
67
67
  sio.putc(b)
68
68
  if b < 128
69
- results << LEB128.decode(sio, false)
69
+ results << LEB128.decode_unsigned(sio)
70
70
  sio = StringIO.new
71
71
  end
72
72
  }
@@ -1,3 +1,3 @@
1
1
  module OpenAssets
2
- VERSION = '0.5.6'
2
+ VERSION = '0.5.7'
3
3
  end
data/lib/segwit.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module Bitcoin
2
2
  module Protocol
3
3
  require 'segwit/tx'
4
+ require 'segwit/script'
4
5
  autoload :TxWitness, 'segwit/tx_witness'
5
6
  autoload :TxInWitness, 'segwit/tx_in_witness'
6
7
  autoload :ScriptWitness, 'segwit/script_witness'
@@ -0,0 +1,36 @@
1
+ module SegwitScript
2
+
3
+ # override Bitcoin::Script#is_standard?
4
+ # Add P2WPKH and P2WSH to the standard
5
+ def is_standard?
6
+ super || is_witness_v0_keyhash? || is_witness_v0_scripthash?
7
+ end
8
+
9
+ # see https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#Witness_program
10
+ def is_witness_v0_keyhash?
11
+ @chunks.length == 2 &&@chunks[0] == 0 && @chunks[1].bytesize == 20
12
+ end
13
+
14
+ # see https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#Witness_program
15
+ def is_witness_v0_scripthash?
16
+ @chunks.length == 2 &&@chunks[0] == 0 && @chunks[1].bytesize == 32
17
+ end
18
+
19
+ # override Bitcoin::Script#type
20
+ # Add type witness_v0_keyhash and witness_v0_scripthash
21
+ def type
22
+ base = super
23
+ if base == :unknown
24
+ return :witness_v0_keyhash if is_witness_v0_keyhash?
25
+ return :witness_v0_scripthash if is_witness_v0_scripthash?
26
+ :unknown
27
+ else
28
+ base
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ class Bitcoin::Script
35
+ prepend SegwitScript
36
+ end
data/lib/segwit/tx.rb CHANGED
@@ -8,10 +8,10 @@ class Bitcoin::Protocol::Tx
8
8
  @ver, @lock_time, @in, @out, @scripts, @witness = 1, 0, [], [], [], Bitcoin::Protocol::TxWitness.new
9
9
  @enable_bitcoinconsensus = !!ENV['USE_BITCOINCONSENSUS']
10
10
  if data
11
- begin
12
- parse_data_from_io(data) # parse no witness data
13
- rescue StandardError
11
+ if witness_tx?(data)
14
12
  parse_witness_data_from_io(data) # parse witness data
13
+ else
14
+ parse_data_from_io(data) # parse no witness data
15
15
  end
16
16
  end
17
17
  end
@@ -73,4 +73,14 @@ class Bitcoin::Protocol::Tx
73
73
  payload
74
74
  end
75
75
 
76
+ # Checks witness transaction data.
77
+ # see https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki
78
+ def witness_tx?(data)
79
+ buf = data.is_a?(String) ? StringIO.new(data) : data
80
+ buf.read(4) # read nVersion
81
+ marker = buf.read(1).unpack("c").first
82
+ flag = buf.read(1).unpack("c").first
83
+ marker == 0 && flag == 1
84
+ end
85
+
76
86
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_runtime_dependency "rest-client", "~>1.8.0"
24
24
  spec.add_runtime_dependency "httpclient"
25
25
  spec.add_runtime_dependency "sqlite3"
26
- spec.add_runtime_dependency "leb128", '0.1.1'
26
+ spec.add_runtime_dependency "leb128", '~> 1.0.0'
27
27
  spec.add_development_dependency "bundler", "~> 1.9"
28
28
  spec.add_development_dependency "rake", "~> 10.0"
29
29
  spec.add_development_dependency "rspec"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openassets-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-13 00:00:00.000000000 Z
11
+ date: 2016-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bitcoin-ruby
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: leb128
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '='
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.1.1
89
+ version: 1.0.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '='
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.1.1
96
+ version: 1.0.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: bundler
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -220,6 +220,7 @@ files:
220
220
  - lib/openassets/util.rb
221
221
  - lib/openassets/version.rb
222
222
  - lib/segwit.rb
223
+ - lib/segwit/script.rb
223
224
  - lib/segwit/script_witness.rb
224
225
  - lib/segwit/tx.rb
225
226
  - lib/segwit/tx_in_witness.rb