openassets-ruby 0.2.4 → 0.2.5

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: a02703514bb6c61cd1bf4f7eaad7402855dead43
4
- data.tar.gz: f78d71f011dab41f68dc60a3ccdb751bf8a0f9c2
3
+ metadata.gz: 14a0524ecd885560924bce4da7804e6aa39f176d
4
+ data.tar.gz: 2a726966732a748b5645eb58272df80922660d63
5
5
  SHA512:
6
- metadata.gz: 4229ca4a625d8f1d76503829b7fd3646e36ee945cde151930f0ed0d6cae4d80c768729da2055a19b957b57acd22daaabf57251ac556856b31a3196c9cd01e440
7
- data.tar.gz: f1a1339a39e8e368a579339b89a1ec0900ecd927d1fa97cbd5d9538d2a16d57e9ce445959aa49536d6aa3d728633640cf03234a09e034d8e480bb888d402d913
6
+ metadata.gz: ae77d53785ec2b31a2692e96b5580e2dbdb5021cb2011228e26a33ca060c96fee45adf4a45dee1fc0a2b37234363f879db632315b6fbe58b589b191c48ccd602
7
+ data.tar.gz: d188e2415a112a7d3d34bd3bd1c513a3672dd30f7d57c7fdef772d7ada7156796ac3ffb3e0e49bc29bc7d19d297d5bf6b6534d3fb2fc9ae145d3b16c048e3c15
data/README.md CHANGED
@@ -164,6 +164,25 @@ This transaction inputs use only uncolored outputs.
164
164
  If specified ``output_qty``, the send output is divided by the number of output_qty.
165
165
  Ex, amount = 60000 and output_qty = 2, send TxOut is two (each value is 30000, 30000) and change TxOut one.
166
166
 
167
+ * **get_outputs_from_txid**
168
+ Get tx outputs. (use for debug)
169
+ ```ruby
170
+ api.get_outputs_from_txid('3fba8bfb157ae29c293d5bd65c178fec169a87f880e2e62537fcce26612a6aa3')
171
+ > [{
172
+ "address": "14M4kbAtn71P1nnNYuhBDFTNYxa19t1XP6",
173
+ "oa_address": "akEJwzkzEFau4t2wjbXoMs7MwtZkB8xixmH",
174
+ "script": "76a91424b3d405bc60bd9628691fe28bb00f6800e1480688ac",
175
+ "amount": "0.00000600",
176
+ "asset_id": "AWo3R89p5REmoSyMWB8AeUmud8456bRxZL",
177
+ "asset_quantity": "1",
178
+ "asset_amount": "1",
179
+ "account": null,
180
+ "asset_definition_url": "",
181
+ "txid": "3fba8bfb157ae29c293d5bd65c178fec169a87f880e2e62537fcce26612a6aa3",
182
+ "vout": 1
183
+ },..
184
+ ```
185
+
167
186
  ## License
168
187
 
169
188
  The MIT License (MIT)
@@ -43,24 +43,7 @@ module OpenAssets
43
43
  def list_unspent(oa_address_list = [])
44
44
  btc_address_list = oa_address_list.map { |oa_address| oa_address_to_address(oa_address)}
45
45
  outputs = get_unspent_outputs(btc_address_list)
46
- result = outputs.map{|out|
47
- address = script_to_address(out.output.script)
48
- script = out.output.script.to_payload.bth
49
- {
50
- 'txid' => out.out_point.hash,
51
- 'vout' => out.out_point.index,
52
- 'address' => address,
53
- 'oa_address' => address.nil? ? nil : address_to_oa_address(address),
54
- 'script' => script,
55
- 'amount' => satoshi_to_coin(out.output.value),
56
- 'confirmations' => out.confirmations,
57
- 'asset_id' => out.output.asset_id,
58
- 'account' => out.output.account,
59
- 'asset_quantity' => out.output.asset_quantity.to_s,
60
- 'asset_amount' => out.output.asset_amount.to_s,
61
- 'asset_definition_url' => out.output.asset_definition_url
62
- }
63
- }
46
+ result = outputs.map{|out| out.to_hash}
64
47
  result
65
48
  end
66
49
 
@@ -179,12 +162,12 @@ module OpenAssets
179
162
  decode_tx = provider.get_transaction(txid, 0)
180
163
  raise OpenAssets::Transaction::TransactionBuildError, "txid #{txid} could not be retrieved." if decode_tx.nil?
181
164
  tx = Bitcoin::Protocol::Tx.new(decode_tx.htb)
182
- colored_outputs = get_color_transaction(tx)
165
+ colored_outputs = get_color_outputs_from_tx(tx)
183
166
  colored_outputs.each_with_index { |o, index | @cache[txid + index.to_s] = o}
184
167
  colored_outputs[output_index]
185
168
  end
186
169
 
187
- def get_color_transaction(tx)
170
+ def get_color_outputs_from_tx(tx)
188
171
  unless tx.is_coinbase?
189
172
  tx.outputs.each_with_index { |out, i|
190
173
  marker_output_payload = OpenAssets::Protocol::MarkerOutput.parse_script(out.pk_script)
@@ -201,10 +184,21 @@ module OpenAssets
201
184
  tx.outputs.map{|out| OpenAssets::Protocol::TransactionOutput.new(out.value, out.parsed_script, nil, 0, OpenAssets::Protocol::OutputType::UNCOLORED)}
202
185
  end
203
186
 
187
+ # Get tx outputs. (use for debug)
188
+ # @param[String] txid Transaction ID.
189
+ # @return[Array] Return array of the transaction output Hash with coloring information.
190
+ def get_outputs_from_txid(txid)
191
+ decode_tx = provider.get_transaction(txid, 0)
192
+ raise OpenAssets::Transaction::TransactionBuildError, "txid #{txid} could not be retrieved." if decode_tx.nil?
193
+ tx = Bitcoin::Protocol::Tx.new(decode_tx.htb)
194
+ outputs = get_color_outputs_from_tx(tx)
195
+ outputs.map.with_index{|out, i|out.to_hash.merge({'txid' => tx.hash, 'vout' => i})}
196
+ end
197
+
204
198
  private
205
199
  # @param [Array[OpenAssets::Protocol::TransactionOutput] inputs The outputs referenced by the inputs of the transaction.
206
200
  # @param [Integer] marker_output_index The position of the marker output in the transaction.
207
- # @param [Array[Bitcoin::Protocol::TxOUt]] outputs The outputs of the transaction.
201
+ # @param [Array[Bitcoin::Protocol::TxOut]] outputs The outputs of the transaction.
208
202
  # @param [Array[OpenAssets::Protocol::TransactionOutput]] asset_quantities The list of asset quantities of the outputs.
209
203
  def compute_asset_ids(inputs, marker_output_index, outputs, asset_quantities)
210
204
  return nil if asset_quantities.length > outputs.length - 1 || inputs.length == 0
@@ -4,6 +4,8 @@ module OpenAssets
4
4
  # Represents a transaction output and its asset ID and asset quantity.
5
5
  class TransactionOutput
6
6
 
7
+ include OpenAssets::Util
8
+
7
9
  attr_accessor :value
8
10
  attr_accessor :script
9
11
  attr_accessor :asset_id
@@ -46,6 +48,22 @@ module OpenAssets
46
48
  @asset_definition.divisibility
47
49
  end
48
50
 
51
+ # convert to hash object.
52
+ def to_hash
53
+ address = script_to_address(@script)
54
+ {
55
+ 'address' => address,
56
+ 'oa_address' => address.nil? ? nil : address_to_oa_address(address),
57
+ 'script' => @script.to_payload.bth,
58
+ 'amount' => satoshi_to_coin(@value),
59
+ 'asset_id' => @asset_id,
60
+ 'asset_quantity' => @asset_quantity.to_s,
61
+ 'asset_amount' => asset_amount.to_s,
62
+ 'account' => @account,
63
+ 'asset_definition_url' => @asset_definition_url
64
+ }
65
+ end
66
+
49
67
  private
50
68
 
51
69
  @@definition_cache = {}
@@ -16,6 +16,13 @@ module OpenAssets
16
16
  def initialize(out_point, output)
17
17
  @out_point = out_point
18
18
  @output = output
19
+ @confirmations = nil
20
+ end
21
+
22
+ # convert to hash.
23
+ def to_hash
24
+ return {} if @output.nil?
25
+ {'txid' => @out_point.hash, 'vout' => @out_point.index, 'confirmations' => @confirmations}.merge(@output.to_hash)
19
26
  end
20
27
 
21
28
  end
@@ -1,3 +1,3 @@
1
1
  module OpenAssets
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.5'
3
3
  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.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: 2015-12-21 00:00:00.000000000 Z
11
+ date: 2015-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bitcoin-ruby