openassets-ruby 0.5.3 → 0.5.4

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: d950356fa5997f18ac1dddd5d46893e2ddb190d4
4
- data.tar.gz: ea9446f8d3e5c8c87fd734d85d22975a1ff160e4
3
+ metadata.gz: d7799eb6ff465493ef1873435b320f4700499128
4
+ data.tar.gz: 2a30a7092e1d2bdfc301f208c692ca617a0ae95b
5
5
  SHA512:
6
- metadata.gz: 022199ce2008f3cc6b1a8b41ba3c2cbb3edfd0b4534ffdb3f540ad9b1d38e32b5bd2d51e1fe8fb4ebd46223b2e908d3b4827243515caf2b7f4b601c9c81fb98e
7
- data.tar.gz: 59023c2a558f29193df1ef762bd15924e0d3d68504402b5cf339823d1d500ea4344806233770d493cec4e589fc7fc247d4852679888c39d27aa72e0635b1d1cc
6
+ metadata.gz: d5bb413b7fe229ea47230bb5b1da509693f0502132ba4383cfc0dee6af146e3b16c84bc7aa42136f13b8dcedb825072d2e53e350f2c94986dfc3b04a089d173f
7
+ data.tar.gz: 77ebd36b208b46b2c88d16be49256d822a56b69eed147a374ce7a73195ecbefcab45d52cee1600b5aa26972215b50c4274a5759407cce8ae7027165d227dc82f
data/README.md CHANGED
@@ -205,18 +205,31 @@ Get tx outputs. (use for debug)
205
205
  ```
206
206
 
207
207
  * **send_assets**
208
- Creates a transaction for sending **multiple** asset from the open asset address to another.
208
+ Creates a transaction for sending **multiple** asset from the open asset address(es) to another.
209
+ `<from open asset address>` is used to send bitcoins **if** needed, and receive bitcoin change **if** any.
209
210
  ```ruby
210
211
  # send assets
211
212
  # api.send_assets(<from open asset address>, <The array of send Asset information(see OpenAssets::SendAssetParam).>, <fees (The fess in satoshis for the transaction. use 10000 satoshi if specified nil)>, <mode=('broadcast', 'signed', 'unsigned')>, <output_qty default value is 1.>)
212
213
 
213
214
  # example
214
- from = address_to_oa_address('mrxpeizRrF8ymNx5FrvcGGZVecZjtUFVP3')
215
- to = address_to_oa_address('n4MEsSUN8GktDFZzU3V55mP3jWGMN7e4wE')
215
+ from = api.address_to_oa_address('mrxpeizRrF8ymNx5FrvcGGZVecZjtUFVP3')
216
+ to = api.address_to_oa_address('n4MEsSUN8GktDFZzU3V55mP3jWGMN7e4wE')
216
217
  params = []
217
218
  params << OpenAssets::SendAssetParam.new('oGu4VXx2TU97d9LmPP8PMCkHckkcPqC5RY', 50, to)
218
219
  params << OpenAssets::SendAssetParam.new('oUygwarZqNGrjDvcZUpZdvEc7es6dcs1vs', 4, to)
219
220
  tx = api.send_assets(from, params)
221
+
222
+ # send assets from multiple addresses.
223
+ change_address = 'mwxeANpckdbdgZCpUMTceQhbbhLPJiqpfD'
224
+ from = [
225
+ api.address_to_oa_address("mrxpeizRrF8ymNx5FrvcGGZVecZjtUFVP3"),
226
+ api.address_to_oa_address("mvYbB238p3rFYFjM56cHhNNHeQb5ypQJ3T")
227
+ ]
228
+ to = api.address_to_oa_address('n4MEsSUN8GktDFZzU3V55mP3jWGMN7e4wE')
229
+ params = []
230
+ params << OpenAssets::SendAssetParam.new('oGu4VXx2TU97d9LmPP8PMCkHckkcPqC5RY', 100, to, from[0])
231
+ params << OpenAssets::SendAssetParam.new('oUygwarZqNGrjDvcZUpZdvEc7es6dcs1vs', 100, to, from[1])
232
+ tx = api.send_assets(change_address, params)
220
233
  ```
221
234
 
222
235
  * **send_bitcoins**
@@ -125,19 +125,22 @@ module OpenAssets
125
125
  end
126
126
 
127
127
  # Creates a transaction for sending multiple asset from an address to another.
128
- # @param[String] from The open asset address to send the asset from.
129
- # @param[Array[OpenAssets::SendAssetParam]] send_asset_params The send Asset information(asset_id, amount, to).
128
+ # @param[String] from The open asset address to send the asset from when send_asset_param hasn't from.
129
+ # to send the bitcoins from, if needed. where to send bitcoin change, if any.
130
+ # @param[Array[OpenAssets::SendAssetParam]] send_asset_params The send Asset information(asset_id, amount, to, from).
130
131
  # @param[Integer] fees The fess in satoshis for the transaction.
131
132
  # @param[String] mode 'broadcast' (default) for signing and broadcasting the transaction,
132
133
  # 'signed' for signing the transaction without broadcasting,
133
134
  # 'unsigned' for getting the raw unsigned transaction without broadcasting"""='broadcast'
134
135
  # @return[Bitcoin::Protocol:Tx] The resulting transaction.
135
136
  def send_assets(from, send_asset_params, fees = nil, mode = 'broadcast')
136
- colored_outputs = get_unspent_outputs([oa_address_to_address(from)])
137
- transfer_specs = send_asset_params.map{|param|
138
- [param.asset_id, OpenAssets::Transaction::TransferParameters.new(colored_outputs, param.to, from, param.amount)]
137
+ transfer_specs = send_asset_params.map{ |param|
138
+ colored_outputs = get_unspent_outputs([oa_address_to_address(param.from || from)])
139
+ [param.asset_id, OpenAssets::Transaction::TransferParameters.new(colored_outputs, param.to, param.from || from, param.amount)]
139
140
  }
140
- tx = create_tx_builder.transfer_assets(transfer_specs, from, fees.nil? ? @config[:default_fees]: fees)
141
+ btc_transfer_spec = OpenAssets::Transaction::TransferParameters.new(
142
+ get_unspent_outputs([oa_address_to_address(from)]), nil, oa_address_to_address(from), 0)
143
+ tx = create_tx_builder.transfer_assets(transfer_specs, btc_transfer_spec, fees.nil? ? @config[:default_fees]: fees)
141
144
  tx = process_transaction(tx, mode)
142
145
  tx
143
146
  end
@@ -205,6 +208,8 @@ module OpenAssets
205
208
  output = OpenAssets::Transaction::SpendableOutput.new(
206
209
  OpenAssets::Transaction::OutPoint.new(item['txid'], item['vout']), output_result)
207
210
  output.confirmations = item['confirmations']
211
+ output.spendable = item['spendable']
212
+ output.solvable = item['solvable']
208
213
  output
209
214
  }
210
215
  result
@@ -14,7 +14,7 @@ module OpenAssets
14
14
  # load Asset Definition File
15
15
  # @return[OpenAssets::Protocol::AssetDefinition] loaded asset definition object
16
16
  def load_definition
17
- @loader.load
17
+ @loader.load if @loader
18
18
  end
19
19
 
20
20
  end
@@ -4,11 +4,13 @@ module OpenAssets
4
4
  attr_accessor :asset_id
5
5
  attr_accessor :amount
6
6
  attr_accessor :to
7
+ attr_accessor :from
7
8
 
8
- def initialize(asset_id, amount, to)
9
+ def initialize(asset_id, amount, to, from = nil)
9
10
  @asset_id = asset_id
10
11
  @amount = amount
11
12
  @to = to
13
+ @from = from
12
14
  end
13
15
  end
14
16
 
@@ -10,6 +10,8 @@ module OpenAssets
10
10
  attr_accessor :output
11
11
 
12
12
  attr_accessor :confirmations
13
+ attr_accessor :spendable
14
+ attr_accessor :solvable
13
15
 
14
16
  # @param [OpenAssets::Transaction::OutPoint] out_point
15
17
  # @param [OpenAssets::Protocol::TransactionOutput] output
@@ -17,12 +19,17 @@ module OpenAssets
17
19
  @out_point = out_point
18
20
  @output = output
19
21
  @confirmations = nil
22
+ @solvable = nil
23
+ @spendable = nil
20
24
  end
21
25
 
22
26
  # convert to hash.
23
27
  def to_hash
24
28
  return {} if @output.nil?
25
- {'txid' => @out_point.hash, 'vout' => @out_point.index, 'confirmations' => @confirmations}.merge(@output.to_hash)
29
+ h = {'txid' => @out_point.hash, 'vout' => @out_point.index, 'confirmations' => @confirmations}.merge(@output.to_hash)
30
+ h['solvable'] = @solvable unless @solvable.nil?
31
+ h['spendable'] = @spendable unless @spendable.nil?
32
+ h
26
33
  end
27
34
 
28
35
  end
@@ -66,9 +66,7 @@ module OpenAssets
66
66
  # @param[String] btc_change_script The script where to send bitcoin change, if any.
67
67
  # @param[Integer] fees The fees to include in the transaction.
68
68
  # @return[Bitcoin::Protocol:Tx] The resulting unsigned transaction.
69
- def transfer_assets(transfer_specs, btc_change_script, fees)
70
- btc_transfer_spec = OpenAssets::Transaction::TransferParameters.new(
71
- transfer_specs[0][1].unspent_outputs, nil, oa_address_to_address(btc_change_script), 0)
69
+ def transfer_assets(transfer_specs, btc_transfer_spec, fees)
72
70
  transfer(transfer_specs, [btc_transfer_spec], fees)
73
71
  end
74
72
 
@@ -1,3 +1,3 @@
1
1
  module OpenAssets
2
- VERSION = '0.5.3'
2
+ VERSION = '0.5.4'
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.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-10 00:00:00.000000000 Z
11
+ date: 2016-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bitcoin-ruby
@@ -226,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
226
  version: '0'
227
227
  requirements: []
228
228
  rubyforge_project:
229
- rubygems_version: 2.4.5
229
+ rubygems_version: 2.4.6
230
230
  signing_key:
231
231
  specification_version: 4
232
232
  summary: The implementation of the Open Assets Protocol for Ruby.