peatio-bitgo 1.1.0 → 2.6.0
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/Gemfile.lock +62 -22
- data/configs/wallets.yml +9 -9
- data/docs/configuration.md +36 -0
- data/docs/images/.DS_Store +0 -0
- data/docs/images/access_token.png +0 -0
- data/docs/images/choose_wallet.png +0 -0
- data/docs/images/create_wallet.png +0 -0
- data/docs/images/create_wallet_access_token.png +0 -0
- data/docs/images/setup_wallet.png +0 -0
- data/docs/images/wallet_access_token.png +0 -0
- data/docs/images/wallet_id.png +0 -0
- data/docs/images/wallet_name.png +0 -0
- data/docs/images/wallet_secret.png +0 -0
- data/docs/images/webhook.png +0 -0
- data/docs/images/webhook_creating.png +0 -0
- data/lib/peatio/bitgo/client.rb +6 -4
- data/lib/peatio/bitgo/version.rb +1 -1
- data/lib/peatio/bitgo/wallet.rb +83 -32
- data/peatio-bitgo.gemspec +2 -2
- metadata +19 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 274572ccfc7d17e3150b4271d2872fda747aff0684a50e21c8bb74382e0c437f
|
|
4
|
+
data.tar.gz: f90adec7c757956565af265400011033a73902348ee1a1d98393ea51e83e2ab1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 58ec57b436b4e5d43d71d3b6db335e36cb4e0c49fac46a9495c2bfdfc1bcf3909577ba1367641bc3a3357adb2779bb515270d285662fdfa9ed0cef62526c49b7
|
|
7
|
+
data.tar.gz: 8fc3e3d276680e91140264bc3ab9d32648632598484dd23ddebdb36d4b79612eb14a585d902ac12585a8b92831e4db4712b3d6444e6ef0ed12c932fab98ae71a
|
data/Gemfile.lock
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
peatio-bitgo (
|
|
4
|
+
peatio-bitgo (2.6.0)
|
|
5
5
|
activesupport (~> 5.2.3)
|
|
6
6
|
better-faraday (~> 1.0.5)
|
|
7
|
-
faraday (~> 0.
|
|
7
|
+
faraday (~> 0.17)
|
|
8
8
|
memoist (~> 0.16.0)
|
|
9
9
|
net-http-persistent (~> 3.0.1)
|
|
10
10
|
peatio (>= 0.6.3)
|
|
@@ -12,75 +12,108 @@ PATH
|
|
|
12
12
|
GEM
|
|
13
13
|
remote: https://rubygems.org/
|
|
14
14
|
specs:
|
|
15
|
-
activemodel (5.2.4.
|
|
16
|
-
activesupport (= 5.2.4.
|
|
17
|
-
activesupport (5.2.4.
|
|
15
|
+
activemodel (5.2.4.2)
|
|
16
|
+
activesupport (= 5.2.4.2)
|
|
17
|
+
activesupport (5.2.4.2)
|
|
18
18
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
19
19
|
i18n (>= 0.7, < 2)
|
|
20
20
|
minitest (~> 5.1)
|
|
21
21
|
tzinfo (~> 1.1)
|
|
22
22
|
addressable (2.7.0)
|
|
23
23
|
public_suffix (>= 2.0.2, < 5.0)
|
|
24
|
-
amq-protocol (2.3.
|
|
24
|
+
amq-protocol (2.3.1)
|
|
25
25
|
amqp (1.8.0)
|
|
26
26
|
amq-protocol (>= 2.2.0)
|
|
27
27
|
eventmachine
|
|
28
28
|
better-faraday (1.0.8)
|
|
29
29
|
activesupport (>= 4.0, < 6.0)
|
|
30
30
|
faraday (~> 0.12)
|
|
31
|
-
bunny (2.
|
|
32
|
-
amq-protocol (~> 2.3, >= 2.3.
|
|
31
|
+
bunny (2.15.0)
|
|
32
|
+
amq-protocol (~> 2.3, >= 2.3.1)
|
|
33
33
|
byebug (11.1.1)
|
|
34
34
|
clamp (1.3.1)
|
|
35
35
|
coderay (1.1.2)
|
|
36
36
|
concurrent-ruby (1.1.6)
|
|
37
37
|
connection_pool (2.2.2)
|
|
38
|
+
cookiejar (0.3.3)
|
|
38
39
|
crack (0.4.3)
|
|
39
40
|
safe_yaml (~> 1.0.0)
|
|
41
|
+
daemons (1.3.1)
|
|
40
42
|
diff-lcs (1.3)
|
|
43
|
+
em-http-request (1.1.5)
|
|
44
|
+
addressable (>= 2.3.4)
|
|
45
|
+
cookiejar (!= 0.3.1)
|
|
46
|
+
em-socksify (>= 0.3)
|
|
47
|
+
eventmachine (>= 1.0.3)
|
|
48
|
+
http_parser.rb (>= 0.6.0)
|
|
49
|
+
em-socksify (0.3.2)
|
|
50
|
+
eventmachine (>= 1.0.0.beta.4)
|
|
51
|
+
em-synchrony (1.0.6)
|
|
52
|
+
eventmachine (>= 1.0.0.beta.1)
|
|
41
53
|
em-websocket (0.5.1)
|
|
42
54
|
eventmachine (>= 0.12.9)
|
|
43
55
|
http_parser.rb (~> 0.6.0)
|
|
44
56
|
eventmachine (1.2.7)
|
|
45
|
-
faraday (0.
|
|
57
|
+
faraday (0.17.3)
|
|
46
58
|
multipart-post (>= 1.2, < 3)
|
|
59
|
+
faraday_middleware (0.13.1)
|
|
60
|
+
faraday (>= 0.7.4, < 1.0)
|
|
61
|
+
faye (1.2.5)
|
|
62
|
+
cookiejar (>= 0.3.0)
|
|
63
|
+
em-http-request (>= 0.3.0)
|
|
64
|
+
eventmachine (>= 0.12.0)
|
|
65
|
+
faye-websocket (>= 0.9.1)
|
|
66
|
+
multi_json (>= 1.0.0)
|
|
67
|
+
rack (>= 1.0.0)
|
|
68
|
+
websocket-driver (>= 0.5.1)
|
|
69
|
+
faye-websocket (0.10.9)
|
|
70
|
+
eventmachine (>= 0.12.0)
|
|
71
|
+
websocket-driver (>= 0.5.1)
|
|
47
72
|
hashdiff (1.0.1)
|
|
48
73
|
http_parser.rb (0.6.0)
|
|
49
74
|
i18n (1.8.2)
|
|
50
75
|
concurrent-ruby (~> 1.0)
|
|
51
76
|
jwt (2.2.1)
|
|
52
77
|
memoist (0.16.2)
|
|
53
|
-
method_source (0.
|
|
78
|
+
method_source (1.0.0)
|
|
54
79
|
minitest (5.14.0)
|
|
55
80
|
mocha (1.11.2)
|
|
81
|
+
multi_json (1.14.1)
|
|
56
82
|
multipart-post (2.1.1)
|
|
57
83
|
mysql2 (0.5.3)
|
|
58
84
|
net-http-persistent (3.0.1)
|
|
59
85
|
connection_pool (~> 2.2)
|
|
60
|
-
peatio (
|
|
86
|
+
peatio (2.4.4)
|
|
61
87
|
activemodel (> 5.2, <= 6.0.0)
|
|
62
88
|
amqp
|
|
63
89
|
bunny
|
|
64
90
|
clamp
|
|
91
|
+
em-synchrony (~> 1.0)
|
|
65
92
|
em-websocket
|
|
66
93
|
eventmachine
|
|
94
|
+
faraday_middleware (~> 0.13.1)
|
|
95
|
+
faye (~> 1.2)
|
|
67
96
|
jwt
|
|
68
97
|
mysql2
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
pry
|
|
98
|
+
prometheus-client
|
|
99
|
+
thin
|
|
100
|
+
prometheus-client (2.0.0)
|
|
101
|
+
pry (0.13.0)
|
|
102
|
+
coderay (~> 1.1)
|
|
103
|
+
method_source (~> 1.0)
|
|
104
|
+
pry-byebug (3.9.0)
|
|
73
105
|
byebug (~> 11.0)
|
|
74
|
-
pry (~> 0.
|
|
75
|
-
public_suffix (4.0.
|
|
76
|
-
|
|
106
|
+
pry (~> 0.13.0)
|
|
107
|
+
public_suffix (4.0.4)
|
|
108
|
+
rack (2.2.2)
|
|
109
|
+
rake (13.0.1)
|
|
77
110
|
rspec (3.9.0)
|
|
78
111
|
rspec-core (~> 3.9.0)
|
|
79
112
|
rspec-expectations (~> 3.9.0)
|
|
80
113
|
rspec-mocks (~> 3.9.0)
|
|
81
114
|
rspec-core (3.9.1)
|
|
82
115
|
rspec-support (~> 3.9.1)
|
|
83
|
-
rspec-expectations (3.9.
|
|
116
|
+
rspec-expectations (3.9.1)
|
|
84
117
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
85
118
|
rspec-support (~> 3.9.0)
|
|
86
119
|
rspec-mocks (3.9.1)
|
|
@@ -88,13 +121,20 @@ GEM
|
|
|
88
121
|
rspec-support (~> 3.9.0)
|
|
89
122
|
rspec-support (3.9.2)
|
|
90
123
|
safe_yaml (1.0.5)
|
|
124
|
+
thin (1.7.2)
|
|
125
|
+
daemons (~> 1.0, >= 1.0.9)
|
|
126
|
+
eventmachine (~> 1.0, >= 1.0.4)
|
|
127
|
+
rack (>= 1, < 3)
|
|
91
128
|
thread_safe (0.3.6)
|
|
92
|
-
tzinfo (1.2.
|
|
129
|
+
tzinfo (1.2.7)
|
|
93
130
|
thread_safe (~> 0.1)
|
|
94
|
-
webmock (3.8.
|
|
131
|
+
webmock (3.8.3)
|
|
95
132
|
addressable (>= 2.3.6)
|
|
96
133
|
crack (>= 0.3.2)
|
|
97
134
|
hashdiff (>= 0.4.0, < 2.0.0)
|
|
135
|
+
websocket-driver (0.7.1)
|
|
136
|
+
websocket-extensions (>= 0.1.0)
|
|
137
|
+
websocket-extensions (0.1.4)
|
|
98
138
|
|
|
99
139
|
PLATFORMS
|
|
100
140
|
ruby
|
|
@@ -104,7 +144,7 @@ DEPENDENCIES
|
|
|
104
144
|
mocha (~> 1.8)
|
|
105
145
|
peatio-bitgo!
|
|
106
146
|
pry-byebug
|
|
107
|
-
rake (~>
|
|
147
|
+
rake (~> 13.0)
|
|
108
148
|
rspec (~> 3.0)
|
|
109
149
|
webmock (~> 3.5)
|
|
110
150
|
|
data/configs/wallets.yml
CHANGED
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
# Geth gateway client settings.
|
|
14
14
|
uri: http://127.0.0.1:8545
|
|
15
15
|
secret: 'changeme'
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
testnet: true
|
|
17
|
+
access_token: 'v2x659261647b540ee3acda5c50ae4e878we323474eea5cbff9b9615139629'
|
|
18
|
+
wallet_id: '5e5388ad80334347ceb3540c741d'
|
|
19
19
|
|
|
20
20
|
- name: Ethereum Hot Wallet
|
|
21
21
|
blockchain_key: eth-rinkeby
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
# Geth gateway client settings.
|
|
32
32
|
uri: http://127.0.0.1:8545
|
|
33
33
|
secret: 'test'
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
testnet: true
|
|
35
|
+
access_token: 'v2x659261647b540ee3acda5c50ae4e878we323474eea5cbff9b9615139629'
|
|
36
|
+
wallet_id: '5e5388ad80334347ceb3540c741d'
|
|
37
37
|
|
|
38
38
|
- name: Ethereum Warm Wallet
|
|
39
39
|
blockchain_key: eth-rinkeby
|
|
@@ -49,6 +49,6 @@
|
|
|
49
49
|
# Geth gateway client settings.
|
|
50
50
|
uri: http://127.0.0.1:8545
|
|
51
51
|
secret: 'test'
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
testnet: true
|
|
53
|
+
access_token: 'v2x659261647b540ee3acda5c50ae4e878we323474eea5cbff9b9615139629'
|
|
54
|
+
wallet_id: '5e5388ad80334347ceb3540c741d'
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
## Bitgo wallet configuration
|
|
2
|
+
|
|
3
|
+
1. Login to your bitgo account
|
|
4
|
+
2. Click in create wallet button
|
|
5
|
+

|
|
6
|
+
3. Choose wallet for appropriate currency
|
|
7
|
+

|
|
8
|
+
4. Setup your wallet
|
|
9
|
+

|
|
10
|
+
5. Put name of your wallet
|
|
11
|
+

|
|
12
|
+
6. Put password of your wallet
|
|
13
|
+

|
|
14
|
+
P.S. You should save this password for future wallet configuration
|
|
15
|
+
|
|
16
|
+
## Peatio BITGO wallet configuration
|
|
17
|
+
|
|
18
|
+
1. Go to tower admin panel Settings -> Wallets -> Add wallet
|
|
19
|
+
* Uri == Bitgo service URI
|
|
20
|
+
* Secret == Wallet password
|
|
21
|
+
* Bitgo Wallet Id
|
|
22
|
+

|
|
23
|
+
* Bitgo Access Token
|
|
24
|
+

|
|
25
|
+

|
|
26
|
+

|
|
27
|
+
|
|
28
|
+
## Webhook configuration
|
|
29
|
+
|
|
30
|
+

|
|
31
|
+

|
|
32
|
+
|
|
33
|
+
Where url should be "https://{host_url}/api/v2/peatio/public/webhooks/{event}"
|
|
34
|
+
|
|
35
|
+
* For deposit wallets event should be 'deposit'
|
|
36
|
+
* For hot wallets event should be 'withdraw'
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/peatio/bitgo/client.rb
CHANGED
|
@@ -5,7 +5,7 @@ module Peatio
|
|
|
5
5
|
module Bitgo
|
|
6
6
|
class Client
|
|
7
7
|
Error = Class.new(StandardError)
|
|
8
|
-
|
|
8
|
+
ConnectionError = Class.new(Error)
|
|
9
9
|
|
|
10
10
|
class ResponseError < Error
|
|
11
11
|
def initialize(msg)
|
|
@@ -43,9 +43,11 @@ module Peatio
|
|
|
43
43
|
response['error'].tap { |error| raise ResponseError.new(error) if error }
|
|
44
44
|
response
|
|
45
45
|
rescue Faraday::Error => e
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
if e.is_a?(Faraday::ConnectionFailed) || e.is_a?(Faraday::TimeoutError)
|
|
47
|
+
raise ConnectionError, e
|
|
48
|
+
else
|
|
49
|
+
raise ConnectionError, JSON.parse(e.response.body)['message']
|
|
50
|
+
end
|
|
49
51
|
end
|
|
50
52
|
end
|
|
51
53
|
end
|
data/lib/peatio/bitgo/version.rb
CHANGED
data/lib/peatio/bitgo/wallet.rb
CHANGED
|
@@ -14,7 +14,7 @@ module Peatio
|
|
|
14
14
|
|
|
15
15
|
@wallet = @settings.fetch(:wallet) do
|
|
16
16
|
raise Peatio::Wallet::MissingSettingError, :wallet
|
|
17
|
-
end.slice(:uri, :address, :secret, :
|
|
17
|
+
end.slice(:uri, :address, :secret, :access_token, :wallet_id, :testnet)
|
|
18
18
|
|
|
19
19
|
@currency = @settings.fetch(:currency) do
|
|
20
20
|
raise Peatio::Wallet::MissingSettingError, :currency
|
|
@@ -22,11 +22,13 @@ module Peatio
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def create_address!(options = {})
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
currency = erc20_currency_id
|
|
26
|
+
options.deep_symbolize_keys!
|
|
27
|
+
if options.dig(:pa_details,:address_id).present?
|
|
28
|
+
response = client.rest_api(:get, "#{currency}/wallet/#{wallet_id}/address/#{options.dig(:pa_details, :address_id)}")
|
|
27
29
|
{ address: response['address'], secret: bitgo_wallet_passphrase }
|
|
28
30
|
else
|
|
29
|
-
response = client.rest_api(:post, "/wallet/#{
|
|
31
|
+
response = client.rest_api(:post, "#{currency}/wallet/#{wallet_id}/address")
|
|
30
32
|
{ address: response['address'], secret: bitgo_wallet_passphrase, details: { address_id: response['id'] }}
|
|
31
33
|
end
|
|
32
34
|
rescue Bitgo::Client::Error => e
|
|
@@ -34,7 +36,7 @@ module Peatio
|
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
def create_transaction!(transaction, options = {})
|
|
37
|
-
currency_options = @currency.fetch(:options).slice(:gas_limit, :gas_price)
|
|
39
|
+
currency_options = @currency.fetch(:options).slice(:gas_limit, :gas_price, :erc20_contract_address)
|
|
38
40
|
|
|
39
41
|
if currency_options[:gas_limit].present? && currency_options[:gas_price].present?
|
|
40
42
|
options.merge!(currency_options)
|
|
@@ -49,10 +51,11 @@ module Peatio
|
|
|
49
51
|
amount -= fee.to_i
|
|
50
52
|
end
|
|
51
53
|
|
|
52
|
-
txid = client.rest_api(:post, "/wallet/#{
|
|
54
|
+
txid = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
|
|
53
55
|
address: transaction.to_address.to_s,
|
|
54
56
|
amount: amount.to_s,
|
|
55
|
-
walletPassphrase: bitgo_wallet_passphrase
|
|
57
|
+
walletPassphrase: bitgo_wallet_passphrase,
|
|
58
|
+
memo: xlm_memo(transaction.to_address.to_s)
|
|
56
59
|
}.compact).fetch('txid')
|
|
57
60
|
|
|
58
61
|
transaction.hash = normalize_txid(txid)
|
|
@@ -64,7 +67,7 @@ module Peatio
|
|
|
64
67
|
|
|
65
68
|
|
|
66
69
|
def build_raw_transaction(transaction)
|
|
67
|
-
client.rest_api(:post, "/wallet/#{
|
|
70
|
+
client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/tx/build", {
|
|
68
71
|
recipients: [{
|
|
69
72
|
address: transaction.to_address,
|
|
70
73
|
amount: convert_to_base_unit(transaction.amount).to_s
|
|
@@ -74,14 +77,15 @@ module Peatio
|
|
|
74
77
|
|
|
75
78
|
def create_eth_transaction(transaction, options = {})
|
|
76
79
|
amount = convert_to_base_unit(transaction.amount)
|
|
77
|
-
|
|
80
|
+
hop = true unless options.slice(:erc20_contract_address).present?
|
|
78
81
|
|
|
79
|
-
txid = client.rest_api(:post, "/wallet/#{
|
|
82
|
+
txid = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
|
|
80
83
|
address: transaction.to_address.to_s,
|
|
81
84
|
amount: amount.to_s,
|
|
82
85
|
walletPassphrase: bitgo_wallet_passphrase,
|
|
83
86
|
gas: options.fetch(:gas_limit).to_i,
|
|
84
|
-
gasPrice: options.fetch(:gas_price).to_i
|
|
87
|
+
gasPrice: options.fetch(:gas_price).to_i,
|
|
88
|
+
hop: hop
|
|
85
89
|
}.compact).fetch('txid')
|
|
86
90
|
|
|
87
91
|
transaction.hash = normalize_txid(txid)
|
|
@@ -89,15 +93,26 @@ module Peatio
|
|
|
89
93
|
end
|
|
90
94
|
|
|
91
95
|
def load_balance!
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
if @currency.fetch(:options).slice(:erc20_contract_address).present?
|
|
97
|
+
load_erc20_balance!
|
|
98
|
+
else
|
|
99
|
+
response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}")
|
|
100
|
+
convert_from_base_unit(response.fetch('balanceString'))
|
|
101
|
+
end
|
|
102
|
+
rescue Bitgo::Client::Error => e
|
|
103
|
+
raise Peatio::Wallet::ClientError, e
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def load_erc20_balance!
|
|
107
|
+
response = client.rest_api(:get, "#{erc20_currency_id}/wallet/#{wallet_id}?allTokens=true")
|
|
108
|
+
convert_from_base_unit(response.dig('tokens', currency_id, 'balanceString'))
|
|
94
109
|
rescue Bitgo::Client::Error => e
|
|
95
110
|
raise Peatio::Wallet::ClientError, e
|
|
96
111
|
end
|
|
97
112
|
|
|
98
113
|
def trigger_webhook_event(event)
|
|
99
|
-
currency_id = @wallet.fetch(:
|
|
100
|
-
return unless currency_id == event['coin'] && @wallet.fetch(:
|
|
114
|
+
currency_id = @wallet.fetch(:testnet).present? ? 't' + @currency.fetch(:id) : @currency.fetch(:id)
|
|
115
|
+
return unless currency_id == event['coin'] && @wallet.fetch(:wallet_id) == event['wallet']
|
|
101
116
|
|
|
102
117
|
if event['type'] == 'transfer'
|
|
103
118
|
transactions = fetch_transfer!(event['transfer'])
|
|
@@ -114,18 +129,16 @@ module Peatio
|
|
|
114
129
|
|
|
115
130
|
def fetch_transfer!(id)
|
|
116
131
|
# TODO: Add Rspecs for this one
|
|
117
|
-
response = client.rest_api(:get, "/wallet/#{
|
|
132
|
+
response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}/transfer/#{id}")
|
|
118
133
|
parse_entries(response['entries']).map do |entry|
|
|
119
134
|
to_address = if response.dig('coinSpecific', 'memo').present?
|
|
120
|
-
|
|
135
|
+
memo = response.dig('coinSpecific', 'memo')
|
|
136
|
+
memo_type = memo.kind_of?(Array) ? memo.first : memo
|
|
137
|
+
build_address(entry['address'], memo_type)
|
|
121
138
|
else
|
|
122
139
|
entry['address']
|
|
123
140
|
end
|
|
124
|
-
state =
|
|
125
|
-
'pending'
|
|
126
|
-
elsif response['state'] == 'confirmed'
|
|
127
|
-
'success'
|
|
128
|
-
end
|
|
141
|
+
state = define_transaction_state(response['state'])
|
|
129
142
|
|
|
130
143
|
transaction = Peatio::Transaction.new(
|
|
131
144
|
currency_id: @currency.fetch(:id),
|
|
@@ -145,7 +158,7 @@ module Peatio
|
|
|
145
158
|
end
|
|
146
159
|
|
|
147
160
|
def transfer_webhook(url)
|
|
148
|
-
client.rest_api(:post, "/wallet/#{
|
|
161
|
+
client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
|
|
149
162
|
type: 'transfer',
|
|
150
163
|
allToken: true,
|
|
151
164
|
url: url,
|
|
@@ -155,7 +168,7 @@ module Peatio
|
|
|
155
168
|
end
|
|
156
169
|
|
|
157
170
|
def address_confirmation_webhook(url)
|
|
158
|
-
client.rest_api(:post, "/wallet/#{
|
|
171
|
+
client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
|
|
159
172
|
type: 'address_confirmation_webhook',
|
|
160
173
|
allToken: true,
|
|
161
174
|
url: url,
|
|
@@ -173,25 +186,52 @@ module Peatio
|
|
|
173
186
|
private
|
|
174
187
|
|
|
175
188
|
def client
|
|
176
|
-
currency_id = @currency.fetch(:id) { raise Peatio::Wallet::MissingSettingError, :id }
|
|
177
189
|
uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
|
|
178
|
-
access_token = @wallet.fetch(:
|
|
190
|
+
access_token = @wallet.fetch(:access_token) { raise Peatio::Wallet::MissingSettingError, :access_token }
|
|
179
191
|
|
|
180
|
-
currency_code_prefix = @wallet.fetch(:
|
|
181
|
-
uri = uri.gsub(/\/+\z/, '') + '/' + currency_code_prefix
|
|
192
|
+
currency_code_prefix = @wallet.fetch(:testnet) ? 't' : ''
|
|
193
|
+
uri = uri.gsub(/\/+\z/, '') + '/' + currency_code_prefix
|
|
182
194
|
@client ||= Client.new(uri, access_token)
|
|
183
195
|
end
|
|
184
196
|
|
|
185
|
-
def build_address(memo)
|
|
186
|
-
"#{
|
|
197
|
+
def build_address(address, memo)
|
|
198
|
+
"#{address}?memoId=#{memo['value']}"
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
# All these functions will have to be done with the coin set to eth or teth
|
|
202
|
+
# since that is the actual coin type being used.
|
|
203
|
+
def erc20_currency_id
|
|
204
|
+
return 'eth' if @currency.fetch(:options).slice(:erc20_contract_address).present?
|
|
205
|
+
|
|
206
|
+
currency_id
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def xlm_memo(address)
|
|
210
|
+
if @currency.fetch(:id) == 'xlm'
|
|
211
|
+
{
|
|
212
|
+
type: "id",
|
|
213
|
+
value: "#{memo_id_from(address)}"
|
|
214
|
+
}
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def memo_id_from(address)
|
|
219
|
+
memo_id = address.partition('memoId=').last
|
|
220
|
+
memo_id = 0 if memo_id.empty?
|
|
221
|
+
|
|
222
|
+
memo_id
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def currency_id
|
|
226
|
+
@currency.fetch(:id) { raise Peatio::Wallet::MissingSettingError, :id }
|
|
187
227
|
end
|
|
188
228
|
|
|
189
229
|
def bitgo_wallet_passphrase
|
|
190
230
|
@wallet.fetch(:secret)
|
|
191
231
|
end
|
|
192
232
|
|
|
193
|
-
def
|
|
194
|
-
@wallet.fetch(:
|
|
233
|
+
def wallet_id
|
|
234
|
+
@wallet.fetch(:wallet_id)
|
|
195
235
|
end
|
|
196
236
|
|
|
197
237
|
def normalize_txid(txid)
|
|
@@ -211,6 +251,17 @@ module Peatio
|
|
|
211
251
|
end
|
|
212
252
|
x.to_i
|
|
213
253
|
end
|
|
254
|
+
|
|
255
|
+
def define_transaction_state(state)
|
|
256
|
+
case state
|
|
257
|
+
when 'unconfrimed'
|
|
258
|
+
'pending'
|
|
259
|
+
when 'confirmed'
|
|
260
|
+
'success'
|
|
261
|
+
when 'failed','rejected'
|
|
262
|
+
'failed'
|
|
263
|
+
end
|
|
264
|
+
end
|
|
214
265
|
end
|
|
215
266
|
end
|
|
216
267
|
end
|
data/peatio-bitgo.gemspec
CHANGED
|
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
|
25
25
|
|
|
26
26
|
spec.add_dependency "activesupport", "~> 5.2.3"
|
|
27
27
|
spec.add_dependency "better-faraday", "~> 1.0.5"
|
|
28
|
-
spec.add_dependency "faraday", "~> 0.
|
|
28
|
+
spec.add_dependency "faraday", "~> 0.17"
|
|
29
29
|
spec.add_dependency "memoist", "~> 0.16.0"
|
|
30
30
|
spec.add_dependency "peatio", ">= 0.6.3"
|
|
31
31
|
spec.add_dependency 'net-http-persistent', '~> 3.0.1'
|
|
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
|
|
|
33
33
|
spec.add_development_dependency "bundler", "~> 1.16"
|
|
34
34
|
spec.add_development_dependency "mocha", "~> 1.8"
|
|
35
35
|
spec.add_development_dependency "pry-byebug"
|
|
36
|
-
spec.add_development_dependency "rake", "~>
|
|
36
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
|
37
37
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
38
38
|
spec.add_development_dependency "webmock", "~> 3.5"
|
|
39
39
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: peatio-bitgo
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nadia Ch., Maksym N.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-05-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -44,14 +44,14 @@ dependencies:
|
|
|
44
44
|
requirements:
|
|
45
45
|
- - "~>"
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 0.
|
|
47
|
+
version: '0.17'
|
|
48
48
|
type: :runtime
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: 0.
|
|
54
|
+
version: '0.17'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: memoist
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -142,14 +142,14 @@ dependencies:
|
|
|
142
142
|
requirements:
|
|
143
143
|
- - "~>"
|
|
144
144
|
- !ruby/object:Gem::Version
|
|
145
|
-
version: '
|
|
145
|
+
version: '13.0'
|
|
146
146
|
type: :development
|
|
147
147
|
prerelease: false
|
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
|
149
149
|
requirements:
|
|
150
150
|
- - "~>"
|
|
151
151
|
- !ruby/object:Gem::Version
|
|
152
|
-
version: '
|
|
152
|
+
version: '13.0'
|
|
153
153
|
- !ruby/object:Gem::Dependency
|
|
154
154
|
name: rspec
|
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -198,6 +198,19 @@ files:
|
|
|
198
198
|
- configs/blockchains.yml
|
|
199
199
|
- configs/currencies.yml
|
|
200
200
|
- configs/wallets.yml
|
|
201
|
+
- docs/configuration.md
|
|
202
|
+
- docs/images/.DS_Store
|
|
203
|
+
- docs/images/access_token.png
|
|
204
|
+
- docs/images/choose_wallet.png
|
|
205
|
+
- docs/images/create_wallet.png
|
|
206
|
+
- docs/images/create_wallet_access_token.png
|
|
207
|
+
- docs/images/setup_wallet.png
|
|
208
|
+
- docs/images/wallet_access_token.png
|
|
209
|
+
- docs/images/wallet_id.png
|
|
210
|
+
- docs/images/wallet_name.png
|
|
211
|
+
- docs/images/wallet_secret.png
|
|
212
|
+
- docs/images/webhook.png
|
|
213
|
+
- docs/images/webhook_creating.png
|
|
201
214
|
- docs/integration.md
|
|
202
215
|
- lib/peatio/bitgo.rb
|
|
203
216
|
- lib/peatio/bitgo/blockchain.rb
|