mixin_bot 0.3.11 → 0.5.2
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 +4 -4
- data/lib/mixin_bot/api/multisig.rb +2 -2
- data/lib/mixin_bot/api/snapshot.rb +6 -5
- data/lib/mixin_bot/api/transaction.rb +65 -0
- data/lib/mixin_bot/api/transfer.rb +2 -2
- data/lib/mixin_bot/api.rb +3 -1
- data/lib/mixin_bot/client.rb +22 -3
- data/lib/mixin_bot/version.rb +1 -1
- data/lib/mixin_bot.rb +2 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d3dd31f8c2fabff92d7a4a487f65f9028f04069cce1afc65646518b8a7fe624
|
4
|
+
data.tar.gz: 26a4e168bc2b5ad6dfcd3078f26a5eb4d86c1bcc1fd6acd5d50586830c0b2c35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 260004bc953f893b6157b7556950a8ec8253706b3e59ee2170355c5b66e13a6778d19eda33056ea843d1bc883a2d5b830c8b6993b6d11ddf7641f05952835669
|
7
|
+
data.tar.gz: 43c1e0feed465d9a235c111e8661d67d818fd6b07449cdc8cd12b0d34a752e7526198de8426d6ae7733fe026b8b601dab0843ff13422b18c6064f0b40c5b2d1c
|
@@ -197,7 +197,7 @@ module MixinBot
|
|
197
197
|
threshold: threshold,
|
198
198
|
state: 'unspent',
|
199
199
|
access_token: access_token
|
200
|
-
).filter(
|
200
|
+
)['data'].filter(
|
201
201
|
&lambda { |utxo|
|
202
202
|
utxo['asset_id'] == kwargs[:asset_id]
|
203
203
|
}
|
@@ -255,7 +255,7 @@ module MixinBot
|
|
255
255
|
extra: extra
|
256
256
|
}
|
257
257
|
|
258
|
-
|
258
|
+
tx.to_json
|
259
259
|
end
|
260
260
|
|
261
261
|
def str_to_bin(str)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module MixinBot
|
4
4
|
class API
|
5
5
|
module Snapshot
|
6
|
-
def network_snapshots(options
|
6
|
+
def network_snapshots(**options)
|
7
7
|
path = format(
|
8
8
|
'/network/snapshots?limit=%<limit>s&offset=%<offset>s&asset=%<asset>s&order=%<order>s',
|
9
9
|
limit: options[:limit],
|
@@ -18,12 +18,13 @@ module MixinBot
|
|
18
18
|
end
|
19
19
|
alias read_network_snapshots network_snapshots
|
20
20
|
|
21
|
-
def snapshots(options
|
21
|
+
def snapshots(**options)
|
22
22
|
path = format(
|
23
|
-
'/snapshots?limit=%<limit>s&offset=%<offset>s&asset=%<asset>s',
|
23
|
+
'/snapshots?limit=%<limit>s&offset=%<offset>s&asset=%<asset>s&opponent=%<opponent>s',
|
24
24
|
limit: options[:limit],
|
25
25
|
offset: options[:offset],
|
26
|
-
asset: options[:asset]
|
26
|
+
asset: options[:asset],
|
27
|
+
opponent: options[:opponent]
|
27
28
|
)
|
28
29
|
|
29
30
|
access_token = options[:access_token] || access_token('GET', path)
|
@@ -32,7 +33,7 @@ module MixinBot
|
|
32
33
|
end
|
33
34
|
alias read_snapshots snapshots
|
34
35
|
|
35
|
-
def network_snapshot(snapshot_id, options
|
36
|
+
def network_snapshot(snapshot_id, **options)
|
36
37
|
path = format('/network/snapshots/%<snapshot_id>s', snapshot_id: snapshot_id)
|
37
38
|
|
38
39
|
access_token = options[:access_token] || access_token('GET', path)
|
@@ -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: format('%.8f', amount),
|
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: format('%.8f', amount),
|
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
|
@@ -9,7 +9,7 @@ module MixinBot
|
|
9
9
|
|
10
10
|
asset_id = options[:asset_id]
|
11
11
|
opponent_id = options[:opponent_id]
|
12
|
-
amount = options[:amount]
|
12
|
+
amount = options[:amount].to_f
|
13
13
|
memo = options[:memo]
|
14
14
|
trace_id = options[:trace_id] || SecureRandom.uuid
|
15
15
|
encrypted_pin = options[:encrypted_pin] || encrypt_pin(pin)
|
@@ -19,7 +19,7 @@ module MixinBot
|
|
19
19
|
asset_id: asset_id,
|
20
20
|
opponent_id: opponent_id,
|
21
21
|
pin: encrypted_pin,
|
22
|
-
amount: amount
|
22
|
+
amount: format('%.8f', amount),
|
23
23
|
trace_id: trace_id,
|
24
24
|
memo: memo
|
25
25
|
}
|
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'
|
@@ -43,7 +44,7 @@ module MixinBot
|
|
43
44
|
end
|
44
45
|
|
45
46
|
# Use a mixin software to implement transaction build
|
46
|
-
def
|
47
|
+
def sign_raw_transaction(json)
|
47
48
|
ensure_mixin_command_exist
|
48
49
|
command = format("mixin signrawtransaction --raw '%<arg>s'", arg: json)
|
49
50
|
|
@@ -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
|
data/lib/mixin_bot/client.rb
CHANGED
@@ -55,13 +55,32 @@ module MixinBot
|
|
55
55
|
# 500 500 Internal Server Error.
|
56
56
|
# 500 7000 Blaze server error.
|
57
57
|
# 500 7001 The blaze operation timeout.
|
58
|
+
# 202 10002 Illegal request paramters.
|
59
|
+
# 202 20117 Insufficient balance。
|
60
|
+
# 202 20118 PIN format error.
|
61
|
+
# 202 20119 PIN error.
|
62
|
+
# 202 20120 Transfer amount is too small.
|
63
|
+
# 202 20121 Authorization code has expired.
|
64
|
+
# 202 20124 Insufficient withdrawal fee.
|
65
|
+
# 202 20125 The transfer has been paid by someone else.
|
66
|
+
# 202 20127 The withdrawal amount is too small.
|
67
|
+
# 202 20131 Withdrawal Memo format error.
|
68
|
+
# 500 30100 The current asset's public chain synchronization error.
|
69
|
+
# 500 30101 Wrong private key.
|
70
|
+
# 500 30102 Wrong withdrawal address.
|
71
|
+
# 500 7000 WebSocket server error.
|
72
|
+
# 500 7001 WebSocket operation timeout.
|
58
73
|
case result['error']['code']
|
59
|
-
when 401
|
74
|
+
when 401, 20121
|
60
75
|
raise UnauthorizedError, errmsg
|
61
|
-
when 403, 20116
|
76
|
+
when 403, 20116, 10002, 429
|
62
77
|
raise ForbiddenError, errmsg
|
63
|
-
when 400, 404,
|
78
|
+
when 400, 404, 10006, 20133, 500, 7000, 7001
|
64
79
|
raise ResponseError, errmsg
|
80
|
+
when 20117
|
81
|
+
raise InsufficientBalanceError, errmsg
|
82
|
+
when 20118, 20119
|
83
|
+
raise PinError, errmsg
|
65
84
|
else
|
66
85
|
raise ResponseError, errmsg
|
67
86
|
end
|
data/lib/mixin_bot/version.rb
CHANGED
data/lib/mixin_bot.rb
CHANGED
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.
|
4
|
+
version: 0.5.2
|
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-
|
11
|
+
date: 2021-08-27 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
|