mixin_bot 0.6.2 → 0.6.3

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: 3f9d0653ed53008afca7e4b5fb60b5121992f4ec1e33d874e7c03610083490e2
4
- data.tar.gz: 6c129dc49aa616fbf6de2cb898bb798fcf025cfd5e46f612693fead1c85d0580
3
+ metadata.gz: '0482fa8ed14e5435679aba1bd40e8f9d13a4db3c4f96f2b7fe97f2639d7d55d1'
4
+ data.tar.gz: 506032e530c347644b878d1f1ba7a520208ca9c5ee1450351657291af46c9153
5
5
  SHA512:
6
- metadata.gz: 7738c8d91ce4c6f9b9a13946a8a04443d01f73b85cfa67a5e60e0b5a453111c6b403b08102c1854c2f40b848f0e8ec514de3e0553104fca507b812996027eaf7
7
- data.tar.gz: d2d210103d602e87a3e980d5c72bf224194fc54e256047c171e7db0f3be0096926e826d62f80ae4657dce4254473df54335a4cd3aa9ba23ba6eaa39773b5c79e
6
+ metadata.gz: b855af1cda16ae26a7b224593adabadc5f9636f364ad36bccbcba4117ad631a38ff70abc35c3cac05df81a6bf14235d923029699df8256c8f05b59a0c697d46a
7
+ data.tar.gz: 7cd57b5eabe7726b5fe4d751e85ad1a4a36754b8b547a0a27baad26ccffff16a7731dc0dd3151be011e872b79a34444a6bd74b22ec550d4e567231a0b85a8552
@@ -156,16 +156,20 @@ module MixinBot
156
156
  def build_raw_transaction(**kwargs)
157
157
  raise ArgumentError, "#{RAW_TRANSACTION_ARGUMENTS.join(', ')} are needed for build raw transaction" unless RAW_TRANSACTION_ARGUMENTS.all? { |param| kwargs.keys.include? param }
158
158
 
159
- senders = kwargs[:senders]
160
- receivers = kwargs[:receivers]
161
- amount = kwargs[:amount]
162
- threshold = kwargs[:threshold]
163
- asset_id = kwargs[:asset_id]
164
- asset_mixin_id = kwargs[:asset_mixin_id]
165
- utxos = kwargs[:utxos]
166
- memo = kwargs[:memo]
167
- extra = kwargs[:extra]
168
- access_token = kwargs[:access_token]
159
+ senders = kwargs[:senders]
160
+ threshold = kwargs[:threshold]
161
+ receivers = kwargs[:receivers]
162
+ receivers_threshold = kwargs[:receivers_threshold]
163
+ amount = kwargs[:amount]
164
+ threshold = kwargs[:threshold]
165
+ asset_id = kwargs[:asset_id]
166
+ asset_mixin_id = kwargs[:asset_mixin_id]
167
+ utxos = kwargs[:utxos]
168
+ memo = kwargs[:memo]
169
+ extra = kwargs[:extra]
170
+ access_token = kwargs[:access_token]
171
+ outputs = kwargs[:outputs] || []
172
+ hint = kwargs[:hint]
169
173
 
170
174
  raise 'access_token required!' if access_token.nil? && !senders.include?(client_id)
171
175
 
@@ -193,23 +197,27 @@ module MixinBot
193
197
  }
194
198
  )
195
199
 
196
- outputs = []
197
- output0 = create_output(receivers: receivers, index: 0)['data']
198
- outputs << {
199
- 'amount': format('%<amount>.8f', amount: amount),
200
- 'script': build_threshold_script(receivers.length),
201
- 'mask': output0['mask'],
202
- 'keys': output0['keys']
203
- }
200
+ if outputs.empty?
201
+ receivers_threshold = 1 if receivers.size == 1
202
+ output0 = build_output(
203
+ receivers: receivers,
204
+ index: 0,
205
+ amount: amount,
206
+ threshold: receivers_threshold,
207
+ hint: hint
208
+ )
209
+ outputs.push output0
204
210
 
205
- if input_amount > amount
206
- output1 = create_output(receivers: senders, index: 1)['data']
207
- outputs << {
208
- 'amount': format('%<amount>.8f', amount: input_amount - amount),
209
- 'script': build_threshold_script(threshold.to_i),
210
- 'mask': output1['mask'],
211
- 'keys': output1['keys']
212
- }
211
+ if input_amount > amount
212
+ output1 = build_output(
213
+ receivers: senders,
214
+ index: 1,
215
+ amount: (input_amount - amount),
216
+ threshold: threshold,
217
+ hint: hint
218
+ )
219
+ outputs.push output1
220
+ end
213
221
  end
214
222
 
215
223
  extra = extra || Digest.hexencode(memo.to_s.slice(0, 140))
@@ -225,31 +233,22 @@ module MixinBot
225
233
  tx.to_json
226
234
  end
227
235
 
236
+ def build_output(receivers:, index:, amount:, threshold:, hint: nil)
237
+ _output = create_output receivers: receivers, index: index, hint: hint
238
+ {
239
+ amount: format('%.8f', amount.to_f),
240
+ script: build_threshold_script(threshold),
241
+ mask: _output['mask'],
242
+ keys: _output['keys']
243
+ }
244
+ end
245
+
228
246
  def str_to_bin(str)
229
247
  return if str.nil?
230
248
 
231
249
  str.scan(/../).map(&:hex).pack('c*')
232
250
  end
233
251
 
234
- def build_inputs(inputs)
235
- res = []
236
- prototype = {
237
- 'Hash' => nil,
238
- 'Index' => nil,
239
- 'Genesis' => nil,
240
- 'Deposit' => nil,
241
- 'Mint' => nil
242
- }
243
- inputs.each do |input|
244
- struc = prototype.dup
245
- struc['Hash'] = str_to_bin input['hash']
246
- struc['Index'] = input['index']
247
- res << struc
248
- end
249
-
250
- res
251
- end
252
-
253
252
  def generate_trace_from_hash(hash, output_index = 0)
254
253
  MixinBot::Utils.generate_trace_from_hash hash, output_index
255
254
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MixinBot
4
- VERSION = '0.6.2'
4
+ VERSION = '0.6.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixin_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - an-lee