mixin_bot 0.3.2 → 0.3.7

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: 11583daf7567ac673396219c79076e30a6694848e9d9887cc214c8db3a12c7cb
4
- data.tar.gz: 668a5ffd78cfa55628e3fa49f44e0f1e028f74bf850265ec27b8ef7b95dfb49b
3
+ metadata.gz: ed2fac4118078dffd141f4147ffd7dfea3bc529180cea2a6136622ceafe1b70b
4
+ data.tar.gz: cd147227f703ecb292819e137cf6c625563bb339fc7da996a2adbc1db0cc466a
5
5
  SHA512:
6
- metadata.gz: 01be5ec88fcc8f9b6b511d0f0ae6f679075aa965a3993133cdd31c5e7fd463d4c2864075a105c4034d35fad5b787940befa6fd602b486e8433139422475184f4
7
- data.tar.gz: 5e86eff08885ea64958d2e79e51de906e2c727cb70b87437927c495933efa90756a0df38e712c40c1e4666fe8c8b6fe81345121fcd2eafa7e35dbb1da03fd4cd
6
+ metadata.gz: 982f3caa95756397116ea9c3a559f574dc1881be80325d02961c2f8f62943273726714d54f5bf019d4d599be31f8200637822b5f0229a0857253e62add6f69ce
7
+ data.tar.gz: 2f433ee6e767e1c8a3176f55c8806687dbae560cc4376ca9f2b110644fe444976a209e81f9dab475a1ed28068ac351ca17706e3581cea82784636767a50888d0
data/lib/mixin_bot/api.rb CHANGED
@@ -25,9 +25,14 @@ module MixinBot
25
25
  @client_id = options[:client_id] || MixinBot.client_id
26
26
  @client_secret = options[:client_secret] || MixinBot.client_secret
27
27
  @session_id = options[:session_id] || MixinBot.session_id
28
- @pin_token = Base64.urlsafe_decode64 options[:pin_token] || MixinBot.pin_token
29
28
  @client = Client.new(MixinBot.api_host || 'api.mixin.one')
30
29
  @blaze_host = MixinBot.blaze_host || 'blaze.mixin.one'
30
+ @pin_token =
31
+ begin
32
+ Base64.urlsafe_decode64 options[:pin_token] || MixinBot.pin_token
33
+ rescue StandardError
34
+ ''
35
+ end
31
36
  _private_key = options[:private_key] || MixinBot.private_key
32
37
  @private_key =
33
38
  if /^-----BEGIN RSA PRIVATE KEY-----/.match? _private_key
@@ -6,7 +6,7 @@ module MixinBot
6
6
  def add_favorite_app(app_id, access_token: nil)
7
7
  path = format('/apps/%<id>s/favorite', id: app_id)
8
8
 
9
- access_token ||= access_token('POST', path, {})
9
+ access_token ||= access_token('POST', path)
10
10
  authorization = format('Bearer %<access_token>s', access_token: access_token)
11
11
  client.post(path, headers: { 'Authorization': authorization })
12
12
  end
@@ -14,7 +14,7 @@ module MixinBot
14
14
  def remove_favorite_app(app_id, access_token: nil)
15
15
  path = format('/apps/%<id>s/unfavorite', id: app_id)
16
16
 
17
- access_token ||= access_token('POST', path, '')
17
+ access_token ||= access_token('POST', path)
18
18
  authorization = format('Bearer %<access_token>s', access_token: access_token)
19
19
  client.post(path, headers: { 'Authorization': authorization })
20
20
  end
@@ -4,7 +4,7 @@ module MixinBot
4
4
  class API
5
5
  module Auth
6
6
  def access_token(method, uri, body = '', exp_in: 600, scp: 'FULL')
7
- sig = Digest::SHA256.hexdigest(method + uri + body)
7
+ sig = Digest::SHA256.hexdigest(method + uri + body.to_s)
8
8
  iat = Time.now.utc.to_i
9
9
  exp = (Time.now.utc + exp_in).to_i
10
10
  jti = SecureRandom.uuid
@@ -54,7 +54,7 @@ module MixinBot
54
54
  end
55
55
 
56
56
  ws = nil
57
- start_blaze_connect(&block) if reconnect
57
+ start_blaze_connect(&_block) if reconnect
58
58
  end
59
59
  end
60
60
  end
@@ -119,19 +119,19 @@ module MixinBot
119
119
 
120
120
  # pay to the multisig address
121
121
  # used for create multisig payment code_id
122
- def create_multisig_payment(params)
122
+ def create_multisig_payment(**kwargs)
123
123
  path = '/payments'
124
124
  payload = {
125
- asset_id: params[:asset_id],
126
- amount: params[:amount].to_s,
127
- trace_id: params[:trace_id] || SecureRandom.uuid,
128
- memo: params[:memo],
125
+ asset_id: kwargs[:asset_id],
126
+ amount: kwargs[:amount].to_s,
127
+ trace_id: kwargs[:trace_id] || SecureRandom.uuid,
128
+ memo: kwargs[:memo],
129
129
  opponent_multisig: {
130
- receivers: params[:receivers],
131
- threshold: params[:threshold]
130
+ receivers: kwargs[:receivers],
131
+ threshold: kwargs[:threshold]
132
132
  }
133
133
  }
134
- access_token = params[:access_token]
134
+ access_token = kwargs[:access_token]
135
135
  access_token ||= access_token('POST', path, payload.to_json)
136
136
  authorization = format('Bearer %<access_token>s', access_token: access_token)
137
137
  client.post(path, headers: { 'Authorization': authorization }, json: payload)
@@ -166,37 +166,37 @@ module MixinBot
166
166
  end
167
167
 
168
168
  # filter utxo by members, asset_id and threshold
169
- def filter_utxos(params)
170
- utxos = all_multisigs(access_token: params[:access_token])
169
+ def filter_utxos(**kwargs)
170
+ utxos = all_multisigs(access_token: kwargs[:access_token])
171
171
 
172
- unless params[:members].nil?
172
+ unless kwargs[:members].nil?
173
173
  utxos = utxos.filter(
174
174
  &lambda { |utxo|
175
- utxo['members'].sort == params[:members].sort
175
+ utxo['members'].sort == kwargs[:members].sort
176
176
  }
177
177
  )
178
178
  end
179
179
 
180
- unless params[:asset_id].nil?
180
+ unless kwargs[:asset_id].nil?
181
181
  utxos = utxos.filter(
182
182
  &lambda { |utxo|
183
- utxo['asset_id'] == params[:asset_id]
183
+ utxo['asset_id'] == kwargs[:asset_id]
184
184
  }
185
185
  )
186
186
  end
187
187
 
188
- unless params[:threshold].nil?
188
+ unless kwargs[:threshold].nil?
189
189
  utxos = utxos.filter(
190
190
  &lambda { |utxo|
191
- utxo['threshold'] == params[:threshold]
191
+ utxo['threshold'] == kwargs[:threshold]
192
192
  }
193
193
  )
194
194
  end
195
195
 
196
- unless params[:state].nil?
196
+ unless kwargs[:state].nil?
197
197
  utxos = utxos.filter(
198
198
  &lambda { |utxo|
199
- utxo['state'] == params[:state]
199
+ utxo['state'] == kwargs[:state]
200
200
  }
201
201
  )
202
202
  end
@@ -204,7 +204,7 @@ module MixinBot
204
204
  utxos
205
205
  end
206
206
 
207
- # params:
207
+ # kwargs:
208
208
  # {
209
209
  # senders: [ uuid ],
210
210
  # receivers: [ uuid ],
@@ -214,16 +214,16 @@ module MixinBot
214
214
  # amount: string / float,
215
215
  # memo: string,
216
216
  # }
217
- def build_raw_transaction(params)
218
- senders = params[:senders]
219
- receivers = params[:receivers]
220
- asset_id = params[:asset_id]
221
- asset_mixin_id = params[:asset_mixin_id]
222
- amount = params[:amount]
223
- memo = params[:memo]
224
- threshold = params[:threshold]
225
- access_token = params[:access_token]
226
- utxos = params[:utxos]
217
+ def build_raw_transaction(kwargs)
218
+ senders = kwargs[:senders]
219
+ receivers = kwargs[:receivers]
220
+ asset_id = kwargs[:asset_id]
221
+ asset_mixin_id = kwargs[:asset_mixin_id]
222
+ amount = kwargs[:amount]
223
+ memo = kwargs[:memo]
224
+ threshold = kwargs[:threshold]
225
+ access_token = kwargs[:access_token]
226
+ utxos = kwargs[:utxos]
227
227
 
228
228
  raise 'access_token required!' if access_token.nil? && !senders.include?(client_id)
229
229
 
@@ -261,15 +261,21 @@ module MixinBot
261
261
 
262
262
  outputs = []
263
263
  output0 = create_output(receivers: receivers, index: 0)['data']
264
- output0['amount'] = format('%<amount>.8f', amount: amount)
265
- output0['script'] = build_threshold_script(receivers.length)
266
- outputs << output0
264
+ outputs << {
265
+ 'amount': format('%<amount>.8f', amount: amount),
266
+ 'script': build_threshold_script(receivers.length),
267
+ 'mask': output0['mask'],
268
+ 'keys': output0['keys']
269
+ }
267
270
 
268
271
  if input_amount > amount
269
272
  output1 = create_output(receivers: senders, index: 1)['data']
270
- output1['amount'] = format('%<amount>.8f', amount: input_amount - amount)
271
- output1['script'] = build_threshold_script(utxos[0]['threshold'].to_i)
272
- outputs << output1
273
+ outputs << {
274
+ 'amount': format('%<amount>.8f', amount: input_amount - amount),
275
+ 'script': build_threshold_script(threshold.to_i),
276
+ 'mask': output1['mask'],
277
+ 'keys': output1['keys']
278
+ }
273
279
  end
274
280
 
275
281
  extra = Digest.hexencode memo.to_s.slice(0, 140)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MixinBot
4
- VERSION = '0.3.2'
4
+ VERSION = '0.3.7'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixin_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - an-lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-10 00:00:00.000000000 Z
11
+ date: 2021-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print