openassets-ruby 0.5.6 → 0.5.7
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/lib/openassets/protocol/transaction_output.rb +25 -0
- data/lib/openassets/util.rb +2 -2
- data/lib/openassets/version.rb +1 -1
- data/lib/segwit.rb +1 -0
- data/lib/segwit/script.rb +36 -0
- data/lib/segwit/tx.rb +13 -3
- data/openassets-ruby.gemspec +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76264bfa708badea9cd4797851dbf74c8d96e869
|
4
|
+
data.tar.gz: 1bf65b91f46e0e81b6a4b5b7ee580dc4b131cb3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 = {}
|
data/lib/openassets/util.rb
CHANGED
@@ -56,7 +56,7 @@ module OpenAssets
|
|
56
56
|
|
57
57
|
# LEB128 encode
|
58
58
|
def encode_leb128(value)
|
59
|
-
LEB128.
|
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.
|
69
|
+
results << LEB128.decode_unsigned(sio)
|
70
70
|
sio = StringIO.new
|
71
71
|
end
|
72
72
|
}
|
data/lib/openassets/version.rb
CHANGED
data/lib/segwit.rb
CHANGED
@@ -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
|
-
|
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
|
data/openassets-ruby.gemspec
CHANGED
@@ -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.
|
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.
|
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-
|
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.
|
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.
|
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
|