mixin_bot 0.3.12 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d0f85363cf5bcf73177e4907d62969f5b011161c84ad4be2b784ba3eac3033e
4
- data.tar.gz: 49e49920927d7e49c1bbc28142afac789ea5bcf538180a6fe9ddfb7df81cf42b
3
+ metadata.gz: 769e68c946637d91db6a89c5583ab7c49763193ca8c7088fbd95038cb2bf5f20
4
+ data.tar.gz: 31405213d094fb3a3d39c4f2e1b2f4e51ce7555c591148c539eb669c7b9d7ccb
5
5
  SHA512:
6
- metadata.gz: 4cb54d94f570833f2f64b4eaef485dd5caecd16c9ffa6fc5bc379d71cef2e4f305ccbdbe0620d82e36eb2a110d7ddb0d23888c429857ef49ca193d4b3527ddd7
7
- data.tar.gz: bd4b56118e2bd182b896668734a0b70379dbf2695caa25afa2be40cea869cf6404bf16f4e439643a94f6766ad67895a770f3596aca6afe0d71831b433120dd30
6
+ metadata.gz: 1105ff54db0cb2eef406ebeaed844227fbb009006ddc71c4ca96bd45967b87fadd8e4a596c2f383e6c4f37558c22fec33111aa051546abf046a2944f0a3d100e
7
+ data.tar.gz: 5bfce8c2db0ddfc6f204babffd5314988055a59529634d16657943c69373130640e706bb25c339c2dbb8e5f6045b796e636b76cea870746db04d3548086a52d4
data/lib/mixin_bot/api.rb CHANGED
@@ -13,6 +13,7 @@ require_relative './api/multisig'
13
13
  require_relative './api/payment'
14
14
  require_relative './api/pin'
15
15
  require_relative './api/snapshot'
16
+ require_relative './api/transaction'
16
17
  require_relative './api/transfer'
17
18
  require_relative './api/user'
18
19
  require_relative './api/withdraw'
@@ -65,6 +66,7 @@ module MixinBot
65
66
  include MixinBot::API::Payment
66
67
  include MixinBot::API::Pin
67
68
  include MixinBot::API::Snapshot
69
+ include MixinBot::API::Transaction
68
70
  include MixinBot::API::Transfer
69
71
  include MixinBot::API::User
70
72
  include MixinBot::API::Withdraw
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MixinBot
4
+ class API
5
+ module Transaction
6
+ MULTISIG_TRANSACTION_ARGUMENTS = %i[asset_id receivers threshold amount].freeze
7
+ def create_multisig_transaction(pin, options = {})
8
+ raise ArgumentError, "#{MULTISIG_TRANSACTION_ARGUMENTS.join(', ')} are needed for create multisig transaction" unless MULTISIG_TRANSACTION_ARGUMENTS.all? { |param| options.keys.include? param }
9
+
10
+ asset_id = options[:asset_id]
11
+ receivers = options[:receivers]
12
+ threshold = options[:threshold]
13
+ amount = options[:amount].to_f
14
+ memo = options[:memo]
15
+ trace_id = options[:trace_id] || SecureRandom.uuid
16
+ encrypted_pin = options[:encrypted_pin] || encrypt_pin(pin)
17
+
18
+ path = '/transactions'
19
+ payload = {
20
+ asset_id: asset_id,
21
+ opponent_multisig: {
22
+ receivers: receivers,
23
+ threshold: threshold
24
+ },
25
+ pin: encrypted_pin,
26
+ amount: amount.to_s,
27
+ trace_id: trace_id,
28
+ memo: memo
29
+ }
30
+
31
+ access_token = options[:access_token]
32
+ access_token ||= access_token('POST', path, payload.to_json)
33
+ authorization = format('Bearer %<access_token>s', access_token: access_token)
34
+ client.post(path, headers: { 'Authorization': authorization }, json: payload)
35
+ end
36
+
37
+ MAINNET_TRANSACTION_ARGUMENTS = %i[asset_id opponent_key amount].freeze
38
+ def create_mainnet_transaction(pin, options = {})
39
+ raise ArgumentError, "#{MAINNET_TRANSACTION_ARGUMENTS.join(', ')} are needed for create main net transactions" unless MAINNET_TRANSACTION_ARGUMENTS.all? { |param| options.keys.include? param }
40
+
41
+ asset_id = options[:asset_id]
42
+ opponent_key = options[:opponent_key]
43
+ amount = options[:amount].to_f
44
+ memo = options[:memo]
45
+ trace_id = options[:trace_id] || SecureRandom.uuid
46
+ encrypted_pin = options[:encrypted_pin] || encrypt_pin(pin)
47
+
48
+ path = '/transactions'
49
+ payload = {
50
+ asset_id: asset_id,
51
+ opponent_key: opponent_key,
52
+ pin: encrypted_pin,
53
+ amount: amount.to_s,
54
+ trace_id: trace_id,
55
+ memo: memo
56
+ }
57
+
58
+ access_token = options[:access_token]
59
+ access_token ||= access_token('POST', path, payload.to_json)
60
+ authorization = format('Bearer %<access_token>s', access_token: access_token)
61
+ client.post(path, headers: { 'Authorization': authorization }, json: payload)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MixinBot
4
- VERSION = '0.3.12'
4
+ VERSION = '0.4.0'
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.12
4
+ version: 0.4.0
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-03-31 00:00:00.000000000 Z
11
+ date: 2021-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -258,6 +258,7 @@ files:
258
258
  - lib/mixin_bot/api/payment.rb
259
259
  - lib/mixin_bot/api/pin.rb
260
260
  - lib/mixin_bot/api/snapshot.rb
261
+ - lib/mixin_bot/api/transaction.rb
261
262
  - lib/mixin_bot/api/transfer.rb
262
263
  - lib/mixin_bot/api/user.rb
263
264
  - lib/mixin_bot/api/withdraw.rb
@@ -286,7 +287,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
287
  - !ruby/object:Gem::Version
287
288
  version: '0'
288
289
  requirements: []
289
- rubygems_version: 3.0.3
290
+ rubygems_version: 3.0.3.1
290
291
  signing_key:
291
292
  specification_version: 4
292
293
  summary: An API wrapper for Mixin Nexwork