peatio-bitgo 1.0.0 → 1.1.3
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 +61 -21
- 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 +5 -1
- data/lib/peatio/bitgo/hooks.rb +2 -2
- data/lib/peatio/bitgo/version.rb +1 -1
- data/lib/peatio/bitgo/wallet.rb +84 -33
- data/peatio-bitgo.gemspec +1 -1
- metadata +17 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8308298f5cd4459b9d14ce7d7a142c8684d19ceb60f4f48656cbc3acfcf39d58
|
|
4
|
+
data.tar.gz: fceb8e50206eb0bf641fb1e52f6741328d3019388211297f8b76c6cdff8fa406
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 06f8b0f3352e04437ccfd8ed8e9260b78a6c7af2b80350ebe1c6ee2f97fbf109a353a62d1c2ceee31e4c57b30ad666f7f5697fa80420de755618bd8985709e67
|
|
7
|
+
data.tar.gz: 61568aa6be7fe158d0b34245b7dd35cba09972f7e63102fdf9e08d355c15691646d4f992288d17e2a778eb657f646af350bd89844568748cd351d264d75bdd4d
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
peatio-bitgo (1.
|
|
4
|
+
peatio-bitgo (1.1.3)
|
|
5
5
|
activesupport (~> 5.2.3)
|
|
6
6
|
better-faraday (~> 1.0.5)
|
|
7
7
|
faraday (~> 0.15.4)
|
|
@@ -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
57
|
faraday (0.15.4)
|
|
46
58
|
multipart-post (>= 1.2, < 3)
|
|
47
|
-
|
|
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)
|
|
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
|
@@ -43,7 +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
|
-
|
|
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
|
|
47
51
|
rescue StandardError => e
|
|
48
52
|
raise Error, e
|
|
49
53
|
end
|
data/lib/peatio/bitgo/hooks.rb
CHANGED
|
@@ -26,8 +26,8 @@ module Peatio
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def register
|
|
29
|
-
Peatio::Blockchain.registry[:bitgo] = Bitgo::Blockchain
|
|
30
|
-
Peatio::Wallet.registry[:bitgo] = Bitgo::Wallet
|
|
29
|
+
Peatio::Blockchain.registry[:bitgo] = Bitgo::Blockchain
|
|
30
|
+
Peatio::Wallet.registry[:bitgo] = Bitgo::Wallet
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
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
|
|
@@ -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,14 @@ module Peatio
|
|
|
74
77
|
|
|
75
78
|
def create_eth_transaction(transaction, options = {})
|
|
76
79
|
amount = convert_to_base_unit(transaction.amount)
|
|
77
|
-
amount -= options.fetch(:gas_limit).to_i * options.fetch(:gas_price).to_i if options.dig(:subtract_fee)
|
|
78
80
|
|
|
79
|
-
txid = client.rest_api(:post, "/wallet/#{
|
|
81
|
+
txid = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
|
|
80
82
|
address: transaction.to_address.to_s,
|
|
81
83
|
amount: amount.to_s,
|
|
82
84
|
walletPassphrase: bitgo_wallet_passphrase,
|
|
83
85
|
gas: options.fetch(:gas_limit).to_i,
|
|
84
|
-
gasPrice: options.fetch(:gas_price).to_i
|
|
86
|
+
gasPrice: options.fetch(:gas_price).to_i,
|
|
87
|
+
hop: true
|
|
85
88
|
}.compact).fetch('txid')
|
|
86
89
|
|
|
87
90
|
transaction.hash = normalize_txid(txid)
|
|
@@ -89,15 +92,26 @@ module Peatio
|
|
|
89
92
|
end
|
|
90
93
|
|
|
91
94
|
def load_balance!
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
if @currency.fetch(:options).slice(:erc20_contract_address).present?
|
|
96
|
+
load_erc20_balance!
|
|
97
|
+
else
|
|
98
|
+
response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}")
|
|
99
|
+
convert_from_base_unit(response.fetch('balanceString'))
|
|
100
|
+
end
|
|
101
|
+
rescue Bitgo::Client::Error => e
|
|
102
|
+
raise Peatio::Wallet::ClientError, e
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def load_erc20_balance!
|
|
106
|
+
response = client.rest_api(:get, "#{erc20_currency_id}/wallet/#{wallet_id}?allTokens=true")
|
|
107
|
+
convert_from_base_unit(response.dig('tokens', currency_id, 'balanceString'))
|
|
94
108
|
rescue Bitgo::Client::Error => e
|
|
95
109
|
raise Peatio::Wallet::ClientError, e
|
|
96
110
|
end
|
|
97
111
|
|
|
98
112
|
def trigger_webhook_event(event)
|
|
99
|
-
currency_id = @wallet.fetch(:
|
|
100
|
-
return unless currency_id == event['coin'] && @wallet.fetch(:
|
|
113
|
+
currency_id = @wallet.fetch(:testnet).present? ? 't' + @currency.fetch(:id) : @currency.fetch(:id)
|
|
114
|
+
return unless currency_id == event['coin'] && @wallet.fetch(:wallet_id) == event['wallet']
|
|
101
115
|
|
|
102
116
|
if event['type'] == 'transfer'
|
|
103
117
|
transactions = fetch_transfer!(event['transfer'])
|
|
@@ -114,29 +128,28 @@ module Peatio
|
|
|
114
128
|
|
|
115
129
|
def fetch_transfer!(id)
|
|
116
130
|
# TODO: Add Rspecs for this one
|
|
117
|
-
response = client.rest_api(:get, "/wallet/#{
|
|
131
|
+
response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}/transfer/#{id}")
|
|
118
132
|
parse_entries(response['entries']).map do |entry|
|
|
119
133
|
to_address = if response.dig('coinSpecific', 'memo').present?
|
|
120
|
-
|
|
134
|
+
memo = response.dig('coinSpecific', 'memo')
|
|
135
|
+
memo_type = memo.kind_of?(Array) ? memo.first : memo
|
|
136
|
+
build_address(entry['address'], memo_type)
|
|
121
137
|
else
|
|
122
138
|
entry['address']
|
|
123
139
|
end
|
|
124
|
-
state =
|
|
125
|
-
'pending'
|
|
126
|
-
elsif response['state'] == 'confirmed'
|
|
127
|
-
'success'
|
|
128
|
-
end
|
|
140
|
+
state = define_transaction_state(response['state'])
|
|
129
141
|
|
|
130
142
|
transaction = Peatio::Transaction.new(
|
|
131
143
|
currency_id: @currency.fetch(:id),
|
|
132
|
-
amount: convert_from_base_unit(
|
|
133
|
-
hash: response['txid'],
|
|
144
|
+
amount: convert_from_base_unit(entry['valueString']),
|
|
145
|
+
hash: normalize_txid(response['txid']),
|
|
134
146
|
to_address: to_address,
|
|
135
147
|
block_number: response['height'],
|
|
136
148
|
# TODO: Add sendmany support
|
|
137
149
|
txout: 0,
|
|
138
150
|
status: state
|
|
139
151
|
)
|
|
152
|
+
|
|
140
153
|
transaction if transaction.valid?
|
|
141
154
|
end.compact
|
|
142
155
|
rescue Bitgo::Client::Error => e
|
|
@@ -144,7 +157,7 @@ module Peatio
|
|
|
144
157
|
end
|
|
145
158
|
|
|
146
159
|
def transfer_webhook(url)
|
|
147
|
-
client.rest_api(:post, "/wallet/#{
|
|
160
|
+
client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
|
|
148
161
|
type: 'transfer',
|
|
149
162
|
allToken: true,
|
|
150
163
|
url: url,
|
|
@@ -154,7 +167,7 @@ module Peatio
|
|
|
154
167
|
end
|
|
155
168
|
|
|
156
169
|
def address_confirmation_webhook(url)
|
|
157
|
-
client.rest_api(:post, "/wallet/#{
|
|
170
|
+
client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
|
|
158
171
|
type: 'address_confirmation_webhook',
|
|
159
172
|
allToken: true,
|
|
160
173
|
url: url,
|
|
@@ -172,25 +185,52 @@ module Peatio
|
|
|
172
185
|
private
|
|
173
186
|
|
|
174
187
|
def client
|
|
175
|
-
currency_id = @currency.fetch(:id) { raise Peatio::Wallet::MissingSettingError, :id }
|
|
176
188
|
uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
|
|
177
|
-
access_token = @wallet.fetch(:
|
|
189
|
+
access_token = @wallet.fetch(:access_token) { raise Peatio::Wallet::MissingSettingError, :access_token }
|
|
178
190
|
|
|
179
|
-
currency_code_prefix = @wallet.fetch(:
|
|
180
|
-
uri = uri.gsub(/\/+\z/, '') + '/' + currency_code_prefix
|
|
191
|
+
currency_code_prefix = @wallet.fetch(:testnet) ? 't' : ''
|
|
192
|
+
uri = uri.gsub(/\/+\z/, '') + '/' + currency_code_prefix
|
|
181
193
|
@client ||= Client.new(uri, access_token)
|
|
182
194
|
end
|
|
183
195
|
|
|
184
|
-
def build_address(memo)
|
|
185
|
-
"#{
|
|
196
|
+
def build_address(address, memo)
|
|
197
|
+
"#{address}?memoId=#{memo['value']}"
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# All these functions will have to be done with the coin set to eth or teth
|
|
201
|
+
# since that is the actual coin type being used.
|
|
202
|
+
def erc20_currency_id
|
|
203
|
+
return 'eth' if @currency.fetch(:options).slice(:erc20_contract_address).present?
|
|
204
|
+
|
|
205
|
+
currency_id
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def xlm_memo(address)
|
|
209
|
+
if @currency.fetch(:id) == 'xlm'
|
|
210
|
+
{
|
|
211
|
+
type: "id",
|
|
212
|
+
value: "#{memo_id_from(address)}"
|
|
213
|
+
}
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def memo_id_from(address)
|
|
218
|
+
memo_id = address.partition('memoId=').last
|
|
219
|
+
memo_id = 0 if memo_id.empty?
|
|
220
|
+
|
|
221
|
+
memo_id
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def currency_id
|
|
225
|
+
@currency.fetch(:id) { raise Peatio::Wallet::MissingSettingError, :id }
|
|
186
226
|
end
|
|
187
227
|
|
|
188
228
|
def bitgo_wallet_passphrase
|
|
189
229
|
@wallet.fetch(:secret)
|
|
190
230
|
end
|
|
191
231
|
|
|
192
|
-
def
|
|
193
|
-
@wallet.fetch(:
|
|
232
|
+
def wallet_id
|
|
233
|
+
@wallet.fetch(:wallet_id)
|
|
194
234
|
end
|
|
195
235
|
|
|
196
236
|
def normalize_txid(txid)
|
|
@@ -210,6 +250,17 @@ module Peatio
|
|
|
210
250
|
end
|
|
211
251
|
x.to_i
|
|
212
252
|
end
|
|
253
|
+
|
|
254
|
+
def define_transaction_state(state)
|
|
255
|
+
case state
|
|
256
|
+
when 'unconfrimed'
|
|
257
|
+
'pending'
|
|
258
|
+
when 'confirmed'
|
|
259
|
+
'success'
|
|
260
|
+
when 'failed','rejected'
|
|
261
|
+
'failed'
|
|
262
|
+
end
|
|
263
|
+
end
|
|
213
264
|
end
|
|
214
265
|
end
|
|
215
266
|
end
|
data/peatio-bitgo.gemspec
CHANGED
|
@@ -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: 1.
|
|
4
|
+
version: 1.1.3
|
|
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-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -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
|