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 +4 -4
- data/README.md +16 -3
- data/lib/openassets/api.rb +11 -6
- data/lib/openassets/protocol/asset_definition_loader.rb +1 -1
- data/lib/openassets/send_asset_param.rb +3 -1
- data/lib/openassets/transaction/spendable_output.rb +8 -1
- data/lib/openassets/transaction/transaction_builder.rb +1 -3
- data/lib/openassets/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7799eb6ff465493ef1873435b320f4700499128
|
4
|
+
data.tar.gz: 2a30a7092e1d2bdfc301f208c692ca617a0ae95b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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**
|
data/lib/openassets/api.rb
CHANGED
@@ -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
|
-
#
|
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
|
-
|
137
|
-
|
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
|
-
|
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
|
@@ -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,
|
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
|
|
data/lib/openassets/version.rb
CHANGED
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.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-
|
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.
|
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.
|