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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3804b292002c1e288151b5f5e9b17e271e9a223
4
- data.tar.gz: 7ca178d7e5556ddbc997f09cf05a9dcdb87f7112
3
+ metadata.gz: ab88032ced409505e81e4ce0ed7ec27e59b61e3c
4
+ data.tar.gz: d2b86f52973527638af824c70fbd2a57c734b5cc
5
5
  SHA512:
6
- metadata.gz: 066a91d9c71bc20a8241279ff9f8319c0220d42cc7748847f9bbefabad54e2304f64b7974fc23a27588a05f6075303120c84e7781d35ea80dfba6a5e88b8c537
7
- data.tar.gz: 568042474c3efa701a00672b695dec08dbea170eeda6108a63653a32e61fc40ebd052a548a8eef53ee439fc19599dd3c95dcece6e8436a0ea4b2b1d1545cea06
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, the issue output is divided by the number of 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
@@ -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, output_qty)
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
- send_param = OpenAssets::Transaction::TransferParameters.new(colored_outputs, to, from, amount)
126
- tx = builder.transfer_assets(asset_id, send_param, from, fees.nil? ? @config[:default_fees]: fees)
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
- send_param = OpenAssets::Transaction::TransferParameters.new(colored_outputs, to, from, amount)
147
- tx = builder.transfer_btc(send_param, fees.nil? ? @config[:default_fees]: fees, output_qty)
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, output_qty = 1)
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] transfer_spec The parameters of the asset being transferred.
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, transfer_spec, btc_change_script, fees)
52
+ def transfer_assets(asset_id, asset_transfer_spec, btc_change_script, fees)
53
53
  btc_transfer_spec = OpenAssets::Transaction::TransferParameters.new(
54
- transfer_spec.unspent_outputs, nil, oa_address_to_address(btc_change_script), 0)
55
- transfer([[asset_id, transfer_spec]], btc_transfer_spec, fees)
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, output_qty = 1)
63
- transfer([], btc_transfer_spec, fees, output_qty)
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, btc_output_qty = 1)
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
- outputs << create_colored_output(oa_address_to_address(transfer_spec.to_script))
140
- asset_quantities << transfer_spec.amount
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
- btc_output_qty.times {|index|
165
- if index == btc_output_qty - 1
166
- amount = btc_transfer_spec.amount / btc_output_qty + btc_transfer_spec.amount % btc_output_qty
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 / btc_output_qty
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
@@ -1,3 +1,3 @@
1
1
  module OpenAssets
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
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.1.5
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-27 00:00:00.000000000 Z
11
+ date: 2015-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bitcoin-ruby