mixin_bot 0.6.2 → 0.6.6

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: c1c0fbeabe6a358600bd80d72f66d5c6b80e821cfe6f825d5ca1fea0a760b21f
4
+ data.tar.gz: f6145d9b52a375c483d2e9245de73af120ff8f799c3385e63ca8c4351576bf7f
5
5
  SHA512:
6
- metadata.gz: 7738c8d91ce4c6f9b9a13946a8a04443d01f73b85cfa67a5e60e0b5a453111c6b403b08102c1854c2f40b848f0e8ec514de3e0553104fca507b812996027eaf7
7
- data.tar.gz: d2d210103d602e87a3e980d5c72bf224194fc54e256047c171e7db0f3be0096926e826d62f80ae4657dce4254473df54335a4cd3aa9ba23ba6eaa39773b5c79e
6
+ metadata.gz: 3b5a1d53e447d0a69ab2d6e7eb4d0f326605ef69b08cbefa4f9e4161aac3b52f74db91fc3da009110c1314050c484d5d6abd89a611717a85720e1a347d760c1a
7
+ data.tar.gz: 9ccc513bea19199e6070d04fc95f0c29cdc4371dc167a3990b7645c31cc855eea93a3bac061fac4280c9b36b869b7cae8cc80e999472e36562cfd5a35b8ea8c4
@@ -101,7 +101,7 @@ module MixinBot
101
101
  # receivers_threshold: 1,
102
102
  # state: 'unspent'
103
103
  # }
104
- COLLECTIBLE_TRANSACTION_ARGUMENTS = %i[collectible nfo receivers threshold].freeze
104
+ COLLECTIBLE_TRANSACTION_ARGUMENTS = %i[collectible nfo receivers receivers_threshold].freeze
105
105
  def build_collectible_transaction(**kwargs)
106
106
  raise ArgumentError, "#{COLLECTIBLE_TRANSACTION_ARGUMENTS.join(', ')} are needed for build collectible transaction" unless COLLECTIBLE_TRANSACTION_ARGUMENTS.all? { |param| kwargs.keys.include? param }
107
107
 
@@ -112,11 +112,13 @@ module MixinBot
112
112
  build_raw_transaction(
113
113
  utxos: [collectible],
114
114
  senders: collectible['receivers'],
115
+ senders_threshold: collectible['receivers_threshold'],
115
116
  receivers: kwargs['receivers'],
116
- threshold: kwargs['threshold'],
117
- extra: kwargs["nfo"],
117
+ receivers_threshold: kwargs['receivers_threshold'],
118
+ extra: kwargs['nfo'],
118
119
  amount: 1,
119
- asset_mixin_id: NFT_ASSET_MIXIN_ID
120
+ asset_mixin_id: NFT_ASSET_MIXIN_ID,
121
+ access_token: kwargs['access_token'],
120
122
  )
121
123
  end
122
124
 
@@ -123,6 +123,7 @@ module MixinBot
123
123
  end
124
124
 
125
125
  def unique_uuid(user_id, opponent_id = nil)
126
+ opponent_id ||= client_id
126
127
  MixinBot::Utils.unique_uuid user_id, opponent_id
127
128
  end
128
129
  alias unique_conversation_id unique_uuid
@@ -146,26 +146,30 @@ module MixinBot
146
146
  # kwargs:
147
147
  # {
148
148
  # senders: [ uuid ],
149
+ # senders_threshold: integer,
149
150
  # receivers: [ uuid ],
150
- # threshold: integer,
151
+ # receivers_threshold: integer,
151
152
  # asset_id: uuid,
152
153
  # amount: string / float,
153
154
  # memo: string,
154
155
  # }
155
- RAW_TRANSACTION_ARGUMENTS = %i[utxos senders receivers amount threshold].freeze
156
+ RAW_TRANSACTION_ARGUMENTS = %i[utxos senders senders_threshold receivers receivers_threshold amount].freeze
156
157
  def build_raw_transaction(**kwargs)
157
158
  raise ArgumentError, "#{RAW_TRANSACTION_ARGUMENTS.join(', ')} are needed for build raw transaction" unless RAW_TRANSACTION_ARGUMENTS.all? { |param| kwargs.keys.include? param }
158
159
 
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]
160
+ senders = kwargs[:senders]
161
+ senders_threshold = kwargs[:senders_threshold]
162
+ receivers = kwargs[:receivers]
163
+ receivers_threshold = kwargs[:receivers_threshold]
164
+ amount = kwargs[:amount]
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: senders_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
@@ -17,11 +17,10 @@ module MixinBot
17
17
  NFT_MASK = 0x00
18
18
  NULL_UUID = '00000000-0000-0000-0000-000000000000'
19
19
 
20
- def unique_uuid(user_id, opponent_id = nil)
21
- opponent_id ||= client_id
20
+ def unique_uuid(uuid_1, uuid_2)
22
21
  md5 = Digest::MD5.new
23
- md5 << [user_id, opponent_id].min
24
- md5 << [user_id, opponent_id].max
22
+ md5 << [uuid_1, uuid_2].min
23
+ md5 << [uuid_1, uuid_2].max
25
24
  digest = md5.digest
26
25
  digest6 = (digest[6].ord & 0x0f | 0x30).chr
27
26
  digest8 = (digest[8].ord & 0x3f | 0x80).chr
@@ -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.6'
5
5
  end
metadata CHANGED
@@ -1,29 +1,29 @@
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.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - an-lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-29 00:00:00.000000000 Z
11
+ date: 2021-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '6.1'
19
+ version: '5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '6.1'
26
+ version: '5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: awesome_print
29
29
  requirement: !ruby/object:Gem::Requirement