mixin_bot 0.3.1 → 0.3.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: 7d2493d906df4d0e0619c860f2b8260cb7b461e0c0aff489706e38d2126cf52a
4
- data.tar.gz: a8106a0086282b5f8eb09feab36f1885715ba51c09285413dabc66d8fcd6f00d
3
+ metadata.gz: bec70596fc9cd40814bcdfd8693573173472db142523131f44c28057f7eae2dd
4
+ data.tar.gz: 52ddbfa9ab68e4340b39c8299383dadf82e14b4ce8dee3c1fd785b5843ac6672
5
5
  SHA512:
6
- metadata.gz: 30442db3e5c4ac450500fb6c0b09023ac36c249c4b12fa2226bbd438076d7e6f9708ac4a93665524cdc28890d0ff22886ef317f1cac1ff38a393e69ca8e127be
7
- data.tar.gz: 827e08df53317fbfb3441ecb476b4d665013eaaff843e6a7ef6f2776da24979ddb72544976efbf28fad4035a34f8ad1d5968df15ecbf4b0f03ba934853db5174
6
+ metadata.gz: bdf202a7fad3fd4e6101288a0fd821b45f9945047ef03e01177dd72942f7c94af225be54e12ff6a7f1fc092d9939e0defcd8e5d6eba2c7b8b683d510ef486ab5
7
+ data.tar.gz: 2058403228454b3b1f4764a7a4ea4756e463648650ee9bfabd12073fe88465eb3d7b478a3583cd4e73f829ef60605e8952aff56a706922b19beb00554d2cfbd6
@@ -9,6 +9,7 @@ require 'jose'
9
9
  require 'msgpack'
10
10
  require 'open3'
11
11
  require 'openssl'
12
+ require 'rbnacl'
12
13
  require_relative './mixin_bot/api'
13
14
  require_relative './mixin_bot/cli'
14
15
  require_relative './mixin_bot/version'
@@ -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
@@ -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.1'
4
+ VERSION = '0.3.6'
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.1
4
+ version: 0.3.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: 2020-12-10 00:00:00.000000000 Z
11
+ date: 2021-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rbnacl
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '7.1'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '7.1'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: thor
113
127
  requirement: !ruby/object:Gem::Requirement