openassets-ruby 0.5.5 → 0.5.6

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: 72f3294a9b0b8a8936e8755c1425d11ad371e5c1
4
- data.tar.gz: 98adc0ea523613f33fd5f528a4a1a1879a494a5a
3
+ metadata.gz: 73a2e3f9a8afacf4353d268e424223fd17baaa11
4
+ data.tar.gz: 194c9b3a032235108ae763f7c9f4fe967e3e763b
5
5
  SHA512:
6
- metadata.gz: 57873cdabe16afb4d0a2b477d7becaf5705be753af43fb739621f7d7063b965fceea94ce577c0aa3623050dc89f649a07e970d566d7b41c4dfd1271480c241dc
7
- data.tar.gz: 3595d40e454e6fd7badb719233b6aa716ed5e26583a5c83e0ccb12fb600eb0366b80cbb9eec9ac38dcf15f8ecca5211b5fa71dfad5de30d83e278bc0fd5407e9
6
+ metadata.gz: 8ea7f8836af8f8095145692593b05f79c399c6cb5a90cd9fb40291bdc093a65f0994c5b987b56241ffe444e7680c85c06b8e3fc25f34cf09ea174274d023e826
7
+ data.tar.gz: 0ef222597d3614e49481d953eb11e1453e892ca1b8ee68c7287d8c96c4ea1f83f7c8392a6de933000b68108b5ed2a14615c4abca5d95f6ebb02788577267b393
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.2.2
1
+ ruby-2.3.0
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
- require "octorelease"
4
3
 
5
4
  RSpec::Core::RakeTask.new("spec")
6
5
  task :default => :spec
data/lib/openassets.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'bitcoin'
2
2
  require 'leb128'
3
+ require 'segwit'
3
4
  module OpenAssets
4
5
 
5
6
  autoload :Protocol, 'openassets/protocol'
@@ -271,11 +271,7 @@ module OpenAssets
271
271
  marker_output = outputs[marker_output_index]
272
272
 
273
273
  # Add the issuance outputs
274
- if prev_outs[0].script.is_p2sh?
275
- issuance_asset_id = script_to_asset_id(prev_outs[0].script.to_payload.bth)
276
- else
277
- issuance_asset_id = pubkey_hash_to_asset_id(prev_outs[0].script.get_hash160)
278
- end
274
+ issuance_asset_id = script_to_asset_id(prev_outs[0].script.to_payload.bth)
279
275
 
280
276
  for i in (0..marker_output_index-1)
281
277
  value = outputs[i].value
@@ -283,7 +279,7 @@ module OpenAssets
283
279
  if i < asset_quantities.length && asset_quantities[i] > 0
284
280
  payload = OpenAssets::Protocol::MarkerOutput.parse_script(marker_output.parsed_script.to_payload)
285
281
  metadata = OpenAssets::Protocol::MarkerOutput.deserialize_payload(payload).metadata
286
- if prev_outs[0].script.is_p2sh?
282
+ if (metadata.nil? || metadata.length == 0) && prev_outs[0].script.is_p2sh?
287
283
  metadata = parse_issuance_p2sh_pointer(tx.in[0].script_sig)
288
284
  end
289
285
  metadata = '' unless metadata
@@ -1,3 +1,3 @@
1
1
  module OpenAssets
2
- VERSION = '0.5.5'
2
+ VERSION = '0.5.6'
3
3
  end
data/lib/segwit.rb ADDED
@@ -0,0 +1,8 @@
1
+ module Bitcoin
2
+ module Protocol
3
+ require 'segwit/tx'
4
+ autoload :TxWitness, 'segwit/tx_witness'
5
+ autoload :TxInWitness, 'segwit/tx_in_witness'
6
+ autoload :ScriptWitness, 'segwit/script_witness'
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ class Bitcoin::Protocol::ScriptWitness
2
+
3
+ # witness stack
4
+ attr_reader :stack
5
+
6
+ def initialize
7
+ @stack = []
8
+ end
9
+
10
+ def empty?
11
+ stack.empty?
12
+ end
13
+
14
+ # output script in raw binary format
15
+ def to_payload
16
+ payload = Bitcoin::Protocol.pack_var_int(stack.size)
17
+ stack.each{|e|
18
+ payload << Bitcoin::Protocol.pack_var_int(e.htb.bytesize)
19
+ payload << e.htb
20
+ }
21
+ payload
22
+ end
23
+ end
data/lib/segwit/tx.rb ADDED
@@ -0,0 +1,76 @@
1
+ # extension for Bitcoin::Protocol::Tx to support segwit
2
+ class Bitcoin::Protocol::Tx
3
+ include Bitcoin::Util
4
+
5
+ attr_reader :witness
6
+
7
+ def initialize(data=nil)
8
+ @ver, @lock_time, @in, @out, @scripts, @witness = 1, 0, [], [], [], Bitcoin::Protocol::TxWitness.new
9
+ @enable_bitcoinconsensus = !!ENV['USE_BITCOINCONSENSUS']
10
+ if data
11
+ begin
12
+ parse_data_from_io(data) # parse no witness data
13
+ rescue StandardError
14
+ parse_witness_data_from_io(data) # parse witness data
15
+ end
16
+ end
17
+ end
18
+
19
+ # get witness hash
20
+ def witness_hash
21
+ hash_from_payload(to_witness_payload)
22
+ end
23
+
24
+ # parse raw data which include witness data
25
+ # serialization format is defined by https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki
26
+ def parse_witness_data_from_io(data)
27
+ buf = data.is_a?(String) ? StringIO.new(data) : data
28
+
29
+ @ver = buf.read(4).unpack("V").first
30
+
31
+ @marker = buf.read(1).unpack("c").first
32
+
33
+ @flag = buf.read(1).unpack("c").first
34
+
35
+ in_size = Bitcoin::Protocol.unpack_var_int_from_io(buf)
36
+ @in = []
37
+ in_size.times{
38
+ break if buf.eof?
39
+ @in << Bitcoin::Protocol::TxIn.from_io(buf)
40
+ }
41
+
42
+ out_size = Bitcoin::Protocol.unpack_var_int_from_io(buf)
43
+ @out = []
44
+ out_size.times{
45
+ break if buf.eof?
46
+ @out << Bitcoin::Protocol::TxOut.from_io(buf)
47
+ }
48
+
49
+ @witness = Bitcoin::Protocol::TxWitness.new
50
+ in_size.times{
51
+ witness_count = Bitcoin::Protocol.unpack_var_int_from_io(buf)
52
+ in_witness = Bitcoin::Protocol::TxInWitness.new
53
+ witness_count.times{
54
+ length = Bitcoin::Protocol.unpack_var_int_from_io(buf)
55
+ in_witness.add_stack(buf.read(length).unpack("H*").first)
56
+ }
57
+ @witness.add_witness(in_witness)
58
+ }
59
+
60
+ @lock_time = buf.read(4).unpack("V").first
61
+
62
+ @hash = hash_from_payload(to_payload)
63
+ end
64
+
65
+ # output transaction in raw binary format with witness
66
+ def to_witness_payload
67
+ pin = ""
68
+ @in.each{|input| pin << input.to_payload }
69
+ pout = ""
70
+ @out.each{|output| pout << output.to_payload }
71
+ payload = [@ver].pack("V") << [0].pack("c") << [1].pack("c") << Bitcoin::Protocol.pack_var_int(@in.size) << pin <<
72
+ Bitcoin::Protocol.pack_var_int(@out.size) << pout << @witness.to_payload << [@lock_time].pack("V")
73
+ payload
74
+ end
75
+
76
+ end
@@ -0,0 +1,22 @@
1
+ class Bitcoin::Protocol::TxInWitness
2
+
3
+ attr_reader :script_witness
4
+
5
+ def initialize
6
+ @script_witness = Bitcoin::Protocol::ScriptWitness.new
7
+ end
8
+
9
+ def add_stack(script)
10
+ script_witness.stack << script
11
+ end
12
+
13
+ # output witness script in raw binary format with witness
14
+ def to_payload
15
+ script_witness.to_payload
16
+ end
17
+
18
+ def stack
19
+ script_witness.stack
20
+ end
21
+
22
+ end
@@ -0,0 +1,22 @@
1
+ class Bitcoin::Protocol::TxWitness
2
+
3
+ attr_reader :tx_in_wit
4
+
5
+ def initialize
6
+ @tx_in_wit = []
7
+ end
8
+
9
+ # Add witness
10
+ # @param[Bitcoin::Protocol::TxInWitness] tx_in_wit witness object
11
+ def add_witness(tx_in_wit)
12
+ (@tx_in_wit ||= []) << tx_in_wit
13
+ end
14
+
15
+ # output witness in raw binary format
16
+ def to_payload
17
+ payload = ""
18
+ tx_in_wit.each{|w|payload << w.to_payload}
19
+ payload
20
+ end
21
+
22
+ end
@@ -23,11 +23,11 @@ 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"
26
+ spec.add_runtime_dependency "leb128", '0.1.1'
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"
30
30
  spec.add_development_dependency "timecop"
31
- spec.add_development_dependency "octorelease"
31
+ spec.add_development_dependency "travis"
32
32
 
33
33
  end
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.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-09 00:00:00.000000000 Z
11
+ date: 2016-11-13 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: 0.1.1
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: 0.1.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: bundler
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -151,7 +151,7 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: octorelease
154
+ name: travis
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
@@ -219,6 +219,11 @@ files:
219
219
  - lib/openassets/transaction/transfer_parameters.rb
220
220
  - lib/openassets/util.rb
221
221
  - lib/openassets/version.rb
222
+ - lib/segwit.rb
223
+ - lib/segwit/script_witness.rb
224
+ - lib/segwit/tx.rb
225
+ - lib/segwit/tx_in_witness.rb
226
+ - lib/segwit/tx_witness.rb
222
227
  - openassets-ruby.gemspec
223
228
  homepage: https://github.com/haw-itn/openassets-ruby
224
229
  licenses:
@@ -240,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
245
  version: '0'
241
246
  requirements: []
242
247
  rubyforge_project:
243
- rubygems_version: 2.4.6
248
+ rubygems_version: 2.5.1
244
249
  signing_key:
245
250
  specification_version: 4
246
251
  summary: The implementation of the Open Assets Protocol for Ruby.