glueby 0.6.4 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 017fd6425f25bc8b48e36ff46456ff42a88dedd43c9e0359c7b39bc06e1fc8df
4
- data.tar.gz: e617c0e9e5d931f795a4ead6d929aac46f2b70f3da5eefbd74434814d85884b2
3
+ metadata.gz: 165b5d6b9fc1cfae9bb7ba852632a0f099ef356bcb52fe0a9937b2c2d1289b51
4
+ data.tar.gz: 6d1a3b9cc1c3668a40ce11920af51cb8af8fc9d94163e43eca295a40d48889f0
5
5
  SHA512:
6
- metadata.gz: 5f93eee936244581432347212864661160c5c9f282009ae1bcb4d0870f344f951d93b2a06df2f680e1ab3227b0be87face08eba17c6539fc286c24b719d8f68e
7
- data.tar.gz: 18df860bc145726f1cbf133f9f3df9f099c01bcba6f3f8c2817e19686c906938df455c2346dd55d21a5ebed99e30e9204ae4dd50ea0bf18043f0ee6a83caec08
6
+ metadata.gz: d7d6f4cf39f9b2c4580d1360817baa960bf72fe77075a038a7784b2f9191bb0cb9925c27d8b697c5d0a75e0d0bc31d35cfda14e3a88e18da88dba09e38aa5246
7
+ data.tar.gz: 691dd9cec6eb183f537c70efab553bd9224bea93fe21da6cb8ce2afea14549e74bd02fa8e73dd3518703b6b390f217d0b02ad3d85649b8eea4e6b6583c1fd196
@@ -175,6 +175,26 @@ module Glueby
175
175
  [color_id, tx]
176
176
  end
177
177
 
178
+ # Send the tokens to multiple wallets
179
+ #
180
+ # @param sender [Glueby::Wallet] wallet to send this token
181
+ # @param receivers [Array<Hash>] array of hash, which keys are :address and :amount
182
+ # @return [Array<String, tx>] Tuple of color_id and tx object
183
+ # @raise [InsufficientFunds] if wallet does not have enough TPC to send transaction.
184
+ # @raise [InsufficientTokens] if wallet does not have enough token to send.
185
+ # @raise [InvalidAmount] if amount is not positive integer.
186
+ def multi_transfer!(sender:, receivers:)
187
+ receivers.each do |r|
188
+ raise Glueby::Contract::Errors::InvalidAmount unless r[:amount].positive?
189
+ end
190
+ funding_tx = create_funding_tx(wallet: sender) if Glueby.configuration.use_utxo_provider?
191
+ funding_tx = sender.internal_wallet.broadcast(funding_tx) if funding_tx
192
+
193
+ tx = create_multi_transfer_tx(funding_tx: funding_tx, color_id: color_id, sender: sender, receivers: receivers)
194
+ sender.internal_wallet.broadcast(tx)
195
+ [color_id, tx]
196
+ end
197
+
178
198
  # Burn token
179
199
  # If amount is not specified or 0, burn all token associated with the wallet.
180
200
  #
@@ -133,15 +133,23 @@ module Glueby
133
133
  end
134
134
 
135
135
  def create_transfer_tx(funding_tx:nil, color_id:, sender:, receiver_address:, amount:, fee_estimator: FixedFeeEstimator.new)
136
+ receivers = [{ address: receiver_address, amount: amount }]
137
+ create_multi_transfer_tx(funding_tx: funding_tx, color_id: color_id, sender: sender, receivers: receivers, fee_estimator: fee_estimator)
138
+ end
139
+
140
+ def create_multi_transfer_tx(funding_tx:nil, color_id:, sender:, receivers:, fee_estimator: FixedFeeEstimator.new)
136
141
  tx = Tapyrus::Tx.new
137
142
 
143
+ amount = receivers.reduce(0) { |sum, r| sum + r[:amount].to_i }
138
144
  utxos = sender.internal_wallet.list_unspent
139
145
  sum_token, outputs = collect_colored_outputs(utxos, color_id, amount)
140
146
  fill_input(tx, outputs)
141
147
 
142
- receiver_script = Tapyrus::Script.parse_from_addr(receiver_address)
143
- receiver_colored_script = receiver_script.add_color(color_id)
144
- tx.outputs << Tapyrus::TxOut.new(value: amount, script_pubkey: receiver_colored_script)
148
+ receivers.each do |r|
149
+ receiver_script = Tapyrus::Script.parse_from_addr(r[:address])
150
+ receiver_colored_script = receiver_script.add_color(color_id)
151
+ tx.outputs << Tapyrus::TxOut.new(value: r[:amount].to_i, script_pubkey: receiver_colored_script)
152
+ end
145
153
 
146
154
  fill_change_token(tx, sender, sum_token - amount, color_id)
147
155
 
@@ -1,3 +1,3 @@
1
1
  module Glueby
2
- VERSION = "0.6.4"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glueby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-20 00:00:00.000000000 Z
11
+ date: 2022-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tapyrus