openassets-ruby 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/openassets/api.rb +7 -7
- data/lib/openassets/transaction/transaction_builder.rb +25 -18
- data/lib/openassets/transaction/transfer_parameters.rb +3 -1
- data/lib/openassets/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab88032ced409505e81e4ce0ed7ec27e59b61e3c
|
4
|
+
data.tar.gz: d2b86f52973527638af824c70fbd2a57c734b5cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a95fda64c3b67b08c1f8496628a095800f79a23fb323362f5d4d8813a4cdb44e62890eecf78ef7908344c36a9a63ad28e16a04d79c925bf45e22286adfc82df
|
7
|
+
data.tar.gz: efd6548365827737a57d08dde0740bfaa0c2c8ba9426c4357ad5b02e4176f56935edccb81f553e2d45de3e5f2d778470a17a7755459c8bc27f612aeae72250f3
|
data/README.md
CHANGED
@@ -54,7 +54,7 @@ Creates a transaction for issuing an asset.
|
|
54
54
|
address = 'akEJwzkzEFau4t2wjbXoMs7MwtZkB8xixmH'
|
55
55
|
api.issue_asset(address, 150, 'u=https://goo.gl/bmVEuw', address, nil, 'broadcast')
|
56
56
|
```
|
57
|
-
If specified output_qty
|
57
|
+
If specified ``output_qty``, the issue output is divided by the number of output_qty.
|
58
58
|
Ex, amount = 125 and output_qty = 2, the marker output asset quantity is [62, 63] and issue TxOut is two.
|
59
59
|
|
60
60
|
* **send_asset**
|
@@ -70,7 +70,8 @@ Creates a transaction for sending an asset from the open asset address to anothe
|
|
70
70
|
```
|
71
71
|
|
72
72
|
* **send_bitcoin**
|
73
|
-
Creates a transaction for sending bitcoins from an address to another.
|
73
|
+
Creates a transaction for sending bitcoins from an address to another.
|
74
|
+
This transaction inputs use only uncolored outputs.
|
74
75
|
```ruby
|
75
76
|
# send bitcoin
|
76
77
|
# api.send_bitcoin(<from btc address>, <amount (satoshi)>, <to btc address>, <fees (The fess in satoshis for the transaction. use 10000 satoshi if specified nil)>, <mode=('broadcast', 'signed', 'unsigned')>, <output_qty default value is 1.>)
|
@@ -80,8 +81,7 @@ Creates a transaction for sending bitcoins from an address to another.
|
|
80
81
|
to = '1MFW7BTwiNbAkmVz4SzAMQXboKYKGSzkq2'
|
81
82
|
api.send_bitcoin(from, 60000, to)
|
82
83
|
```
|
83
|
-
|
84
|
-
If specified output_qty, the send output is divided by the number of output_qty.
|
84
|
+
If specified ``output_qty``, the send output is divided by the number of output_qty.
|
85
85
|
Ex, amount = 60000 and output_qty = 2, send TxOut is two (each value is 30000, 30000) and change TxOut one.
|
86
86
|
|
87
87
|
## License
|
data/lib/openassets/api.rb
CHANGED
@@ -103,8 +103,8 @@ module OpenAssets
|
|
103
103
|
to = from if to.nil?
|
104
104
|
builder = OpenAssets::Transaction::TransactionBuilder.new(@config[:dust_limit])
|
105
105
|
colored_outputs = get_unspent_outputs([oa_address_to_address(from)])
|
106
|
-
issue_param = OpenAssets::Transaction::TransferParameters.new(colored_outputs, to, from, amount)
|
107
|
-
tx = builder.issue_asset(issue_param, metadata, fees.nil? ? @config[:default_fees]: fees
|
106
|
+
issue_param = OpenAssets::Transaction::TransferParameters.new(colored_outputs, to, from, amount, output_qty)
|
107
|
+
tx = builder.issue_asset(issue_param, metadata, fees.nil? ? @config[:default_fees]: fees)
|
108
108
|
tx = process_transaction(tx, mode)
|
109
109
|
tx
|
110
110
|
end
|
@@ -119,11 +119,11 @@ module OpenAssets
|
|
119
119
|
# 'signed' for signing the transaction without broadcasting,
|
120
120
|
# 'unsigned' for getting the raw unsigned transaction without broadcasting"""='broadcast'
|
121
121
|
# @return[Bitcoin::Protocol:Tx] The resulting transaction.
|
122
|
-
def send_asset(from, asset_id, amount, to, fees = nil, mode = 'broadcast')
|
122
|
+
def send_asset(from, asset_id, amount, to, fees = nil, mode = 'broadcast', output_qty = 1)
|
123
123
|
builder = OpenAssets::Transaction::TransactionBuilder.new(@config[:dust_limit])
|
124
124
|
colored_outputs = get_unspent_outputs([oa_address_to_address(from)])
|
125
|
-
|
126
|
-
tx = builder.transfer_assets(asset_id,
|
125
|
+
asset_transfer_spec = OpenAssets::Transaction::TransferParameters.new(colored_outputs, to, from, amount, output_qty)
|
126
|
+
tx = builder.transfer_assets(asset_id, asset_transfer_spec, from, fees.nil? ? @config[:default_fees]: fees)
|
127
127
|
tx = process_transaction(tx, mode)
|
128
128
|
tx
|
129
129
|
end
|
@@ -143,8 +143,8 @@ module OpenAssets
|
|
143
143
|
validate_address([from, to])
|
144
144
|
builder = OpenAssets::Transaction::TransactionBuilder.new(@config[:dust_limit])
|
145
145
|
colored_outputs = get_unspent_outputs([from])
|
146
|
-
|
147
|
-
tx = builder.transfer_btc(
|
146
|
+
btc_transfer_spec = OpenAssets::Transaction::TransferParameters.new(colored_outputs, to, from, amount, output_qty)
|
147
|
+
tx = builder.transfer_btc(btc_transfer_spec, fees.nil? ? @config[:default_fees]: fees)
|
148
148
|
process_transaction(tx, mode)
|
149
149
|
end
|
150
150
|
|
@@ -16,7 +16,7 @@ module OpenAssets
|
|
16
16
|
# @param [bytes] metadata The metadata to be embedded in the transaction.
|
17
17
|
# @param [Integer] fees The fees to include in the transaction.
|
18
18
|
# @return[Bitcoin:Protocol:Tx] An unsigned transaction for issuing asset.
|
19
|
-
def issue_asset(issue_spec, metadata, fees
|
19
|
+
def issue_asset(issue_spec, metadata, fees)
|
20
20
|
inputs, total_amount =
|
21
21
|
TransactionBuilder.collect_uncolored_outputs(issue_spec.unspent_outputs, 2 * @amount + fees)
|
22
22
|
tx = Bitcoin::Protocol::Tx.new
|
@@ -30,11 +30,11 @@ module OpenAssets
|
|
30
30
|
from_address = oa_address_to_address(issue_spec.change_script)
|
31
31
|
validate_address([issue_address, from_address])
|
32
32
|
asset_quantities =[]
|
33
|
-
output_qty.times {|index|
|
34
|
-
if index == output_qty - 1
|
35
|
-
asset_quantities[index] = issue_spec.amount / output_qty + issue_spec.amount % output_qty
|
33
|
+
issue_spec.output_qty.times {|index|
|
34
|
+
if index == issue_spec.output_qty - 1
|
35
|
+
asset_quantities[index] = issue_spec.amount / issue_spec.output_qty + issue_spec.amount % issue_spec.output_qty
|
36
36
|
else
|
37
|
-
asset_quantities[index] = issue_spec.amount / output_qty
|
37
|
+
asset_quantities[index] = issue_spec.amount / issue_spec.output_qty
|
38
38
|
end
|
39
39
|
tx.add_out(create_colored_output(issue_address))
|
40
40
|
}
|
@@ -45,22 +45,22 @@ module OpenAssets
|
|
45
45
|
|
46
46
|
# Creates a transaction for sending an asset.
|
47
47
|
# @param[String] asset_id The ID of the asset being sent.
|
48
|
-
# @param[OpenAssets::Transaction::TransferParameters]
|
48
|
+
# @param[OpenAssets::Transaction::TransferParameters] asset_transfer_spec The parameters of the asset being transferred.
|
49
49
|
# @param[String] btc_change_script The script where to send bitcoin change, if any.
|
50
50
|
# @param[Integer] fees The fees to include in the transaction.
|
51
51
|
# @return[Bitcoin::Protocol:Tx] The resulting unsigned transaction.
|
52
|
-
def transfer_assets(asset_id,
|
52
|
+
def transfer_assets(asset_id, asset_transfer_spec, btc_change_script, fees)
|
53
53
|
btc_transfer_spec = OpenAssets::Transaction::TransferParameters.new(
|
54
|
-
|
55
|
-
transfer([[asset_id,
|
54
|
+
asset_transfer_spec.unspent_outputs, nil, oa_address_to_address(btc_change_script), 0)
|
55
|
+
transfer([[asset_id, asset_transfer_spec]], btc_transfer_spec, fees)
|
56
56
|
end
|
57
57
|
|
58
58
|
# Creates a transaction for sending bitcoins.
|
59
59
|
# @param[OpenAssets::Transaction::TransferParameters] btc_transfer_spec The parameters of the bitcoins being transferred.
|
60
60
|
# @param[Integer] fees The fees to include in the transaction.
|
61
61
|
# @return[Bitcoin::Protocol:Tx] The resulting unsigned transaction.
|
62
|
-
def transfer_btc(btc_transfer_spec, fees
|
63
|
-
transfer([], btc_transfer_spec, fees
|
62
|
+
def transfer_btc(btc_transfer_spec, fees)
|
63
|
+
transfer([], btc_transfer_spec, fees)
|
64
64
|
end
|
65
65
|
|
66
66
|
# collect uncolored outputs in unspent outputs(contains colored output).
|
@@ -127,7 +127,7 @@ module OpenAssets
|
|
127
127
|
Bitcoin::Protocol::TxOut.new(value, Bitcoin::Script.new(Bitcoin::Script.to_hash160_script(hash160)).to_payload)
|
128
128
|
end
|
129
129
|
|
130
|
-
def transfer(asset_transfer_specs, btc_transfer_spec, fees
|
130
|
+
def transfer(asset_transfer_specs, btc_transfer_spec, fees)
|
131
131
|
inputs = []
|
132
132
|
outputs = []
|
133
133
|
asset_quantities = []
|
@@ -136,8 +136,15 @@ module OpenAssets
|
|
136
136
|
inputs = inputs + colored_outputs
|
137
137
|
|
138
138
|
# add asset transfer output
|
139
|
-
|
140
|
-
|
139
|
+
transfer_spec.output_qty.times{|index|
|
140
|
+
if index == transfer_spec.output_qty - 1
|
141
|
+
amount = transfer_spec.amount / transfer_spec.output_qty + transfer_spec.amount % transfer_spec.output_qty
|
142
|
+
else
|
143
|
+
amount = transfer_spec.amount / transfer_spec.output_qty
|
144
|
+
end
|
145
|
+
outputs << create_colored_output(oa_address_to_address(transfer_spec.to_script))
|
146
|
+
asset_quantities << amount
|
147
|
+
}
|
141
148
|
|
142
149
|
# add the rest of the asset to the origin address
|
143
150
|
if total_amount > transfer_spec.amount
|
@@ -161,11 +168,11 @@ module OpenAssets
|
|
161
168
|
end
|
162
169
|
|
163
170
|
if btc_transfer_spec.amount > 0
|
164
|
-
|
165
|
-
if index ==
|
166
|
-
amount = btc_transfer_spec.amount /
|
171
|
+
btc_transfer_spec.output_qty.times {|index|
|
172
|
+
if index == btc_transfer_spec.output_qty - 1
|
173
|
+
amount = btc_transfer_spec.amount / btc_transfer_spec.output_qty + btc_transfer_spec.amount % btc_transfer_spec.output_qty
|
167
174
|
else
|
168
|
-
amount = btc_transfer_spec.amount /
|
175
|
+
amount = btc_transfer_spec.amount / btc_transfer_spec.output_qty
|
169
176
|
end
|
170
177
|
outputs << create_uncolored_output(btc_transfer_spec.to_script, amount)
|
171
178
|
}
|
@@ -8,17 +8,19 @@ module OpenAssets
|
|
8
8
|
attr_accessor :amount
|
9
9
|
attr_accessor :change_script
|
10
10
|
attr_accessor :to_script
|
11
|
+
attr_accessor :output_qty
|
11
12
|
|
12
13
|
# initialize
|
13
14
|
# @param [Array[OpenAssets::Transaction::SpendableOutput]] unspent_outputs Array of the unspent outputs available for the transaction.
|
14
15
|
# @param [String] to_script the output script to which to send the assets or bitcoins.
|
15
16
|
# @param [String] change_script the output script to which to send any remaining change.
|
16
17
|
# @param [Integer] amount The asset quantity or amount of the satoshi sent in the transaction.
|
17
|
-
def initialize(unspent_outputs, to_script, change_script, amount)
|
18
|
+
def initialize(unspent_outputs, to_script, change_script, amount, output_qty = 1)
|
18
19
|
@unspent_outputs = unspent_outputs
|
19
20
|
@to_script = to_script
|
20
21
|
@change_script = change_script
|
21
22
|
@amount = amount
|
23
|
+
@output_qty = output_qty
|
22
24
|
end
|
23
25
|
|
24
26
|
end
|
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.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- azuchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bitcoin-ruby
|