peatio-bitgo 1.1.3 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +34 -34
- data/lib/peatio/bitgo/version.rb +1 -1
- data/lib/peatio/bitgo/wallet.rb +55 -21
- data/peatio-bitgo.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4253a3ca3970f150214e76a1a31fd3f7d09bc8fbb181abd790048278859c9fcb
|
4
|
+
data.tar.gz: 0fa8a23a04582bc62ca5959a616410b30b1438d2bb1d2d30da317ec2928e4071
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb144800c2f5732e2a19191882157d04ce0f0fd76b7fa1134d3eae3988b9e95df8b2bee3c622355f25558ac545a2f3d924ffbcecec2415f553ac67ecc04479cc
|
7
|
+
data.tar.gz: 3a92e09b6b1e900790caa6aa028fd1a8251012eb45b23a8c3bac151f8b2f2d6e49cdb6915d04a57ed60b0fc85384d10073e5b2031cdd88548e9910e3e7a90b3c
|
data/Gemfile.lock
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
peatio-bitgo (
|
4
|
+
peatio-bitgo (2.5.1)
|
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,35 +12,35 @@ 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.3)
|
16
|
+
activesupport (= 5.2.4.3)
|
17
|
+
activesupport (5.2.4.3)
|
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.2)
|
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.
|
31
|
+
bunny (2.16.1)
|
32
32
|
amq-protocol (~> 2.3, >= 2.3.1)
|
33
|
-
byebug (11.1.
|
34
|
-
clamp (1.3.
|
35
|
-
coderay (1.1.
|
36
|
-
concurrent-ruby (1.1.
|
37
|
-
connection_pool (2.2.
|
33
|
+
byebug (11.1.3)
|
34
|
+
clamp (1.3.2)
|
35
|
+
coderay (1.1.3)
|
36
|
+
concurrent-ruby (1.1.7)
|
37
|
+
connection_pool (2.2.3)
|
38
38
|
cookiejar (0.3.3)
|
39
39
|
crack (0.4.3)
|
40
40
|
safe_yaml (~> 1.0.0)
|
41
41
|
daemons (1.3.1)
|
42
|
-
diff-lcs (1.
|
43
|
-
em-http-request (1.1.
|
42
|
+
diff-lcs (1.4.4)
|
43
|
+
em-http-request (1.1.6)
|
44
44
|
addressable (>= 2.3.4)
|
45
45
|
cookiejar (!= 0.3.1)
|
46
46
|
em-socksify (>= 0.3)
|
@@ -54,36 +54,36 @@ GEM
|
|
54
54
|
eventmachine (>= 0.12.9)
|
55
55
|
http_parser.rb (~> 0.6.0)
|
56
56
|
eventmachine (1.2.7)
|
57
|
-
faraday (0.
|
57
|
+
faraday (0.17.3)
|
58
58
|
multipart-post (>= 1.2, < 3)
|
59
59
|
faraday_middleware (0.13.1)
|
60
60
|
faraday (>= 0.7.4, < 1.0)
|
61
|
-
faye (1.
|
61
|
+
faye (1.4.0)
|
62
62
|
cookiejar (>= 0.3.0)
|
63
|
-
em-http-request (>=
|
63
|
+
em-http-request (>= 1.1.6)
|
64
64
|
eventmachine (>= 0.12.0)
|
65
|
-
faye-websocket (>= 0.
|
65
|
+
faye-websocket (>= 0.11.0)
|
66
66
|
multi_json (>= 1.0.0)
|
67
67
|
rack (>= 1.0.0)
|
68
68
|
websocket-driver (>= 0.5.1)
|
69
|
-
faye-websocket (0.
|
69
|
+
faye-websocket (0.11.0)
|
70
70
|
eventmachine (>= 0.12.0)
|
71
71
|
websocket-driver (>= 0.5.1)
|
72
72
|
hashdiff (1.0.1)
|
73
73
|
http_parser.rb (0.6.0)
|
74
|
-
i18n (1.8.
|
74
|
+
i18n (1.8.5)
|
75
75
|
concurrent-ruby (~> 1.0)
|
76
|
-
jwt (2.2.
|
76
|
+
jwt (2.2.2)
|
77
77
|
memoist (0.16.2)
|
78
78
|
method_source (1.0.0)
|
79
|
-
minitest (5.14.
|
79
|
+
minitest (5.14.1)
|
80
80
|
mocha (1.11.2)
|
81
|
-
multi_json (1.
|
81
|
+
multi_json (1.15.0)
|
82
82
|
multipart-post (2.1.1)
|
83
83
|
mysql2 (0.5.3)
|
84
84
|
net-http-persistent (3.0.1)
|
85
85
|
connection_pool (~> 2.2)
|
86
|
-
peatio (2.
|
86
|
+
peatio (2.6.1)
|
87
87
|
activemodel (> 5.2, <= 6.0.0)
|
88
88
|
amqp
|
89
89
|
bunny
|
@@ -97,29 +97,29 @@ GEM
|
|
97
97
|
mysql2
|
98
98
|
prometheus-client
|
99
99
|
thin
|
100
|
-
prometheus-client (2.
|
101
|
-
pry (0.13.
|
100
|
+
prometheus-client (2.1.0)
|
101
|
+
pry (0.13.1)
|
102
102
|
coderay (~> 1.1)
|
103
103
|
method_source (~> 1.0)
|
104
104
|
pry-byebug (3.9.0)
|
105
105
|
byebug (~> 11.0)
|
106
106
|
pry (~> 0.13.0)
|
107
|
-
public_suffix (4.0.
|
108
|
-
rack (2.2.
|
107
|
+
public_suffix (4.0.5)
|
108
|
+
rack (2.2.3)
|
109
109
|
rake (13.0.1)
|
110
110
|
rspec (3.9.0)
|
111
111
|
rspec-core (~> 3.9.0)
|
112
112
|
rspec-expectations (~> 3.9.0)
|
113
113
|
rspec-mocks (~> 3.9.0)
|
114
|
-
rspec-core (3.9.
|
115
|
-
rspec-support (~> 3.9.
|
116
|
-
rspec-expectations (3.9.
|
114
|
+
rspec-core (3.9.2)
|
115
|
+
rspec-support (~> 3.9.3)
|
116
|
+
rspec-expectations (3.9.2)
|
117
117
|
diff-lcs (>= 1.2.0, < 2.0)
|
118
118
|
rspec-support (~> 3.9.0)
|
119
119
|
rspec-mocks (3.9.1)
|
120
120
|
diff-lcs (>= 1.2.0, < 2.0)
|
121
121
|
rspec-support (~> 3.9.0)
|
122
|
-
rspec-support (3.9.
|
122
|
+
rspec-support (3.9.3)
|
123
123
|
safe_yaml (1.0.5)
|
124
124
|
thin (1.7.2)
|
125
125
|
daemons (~> 1.0, >= 1.0.9)
|
@@ -132,9 +132,9 @@ GEM
|
|
132
132
|
addressable (>= 2.3.6)
|
133
133
|
crack (>= 0.3.2)
|
134
134
|
hashdiff (>= 0.4.0, < 2.0.0)
|
135
|
-
websocket-driver (0.7.
|
135
|
+
websocket-driver (0.7.3)
|
136
136
|
websocket-extensions (>= 0.1.0)
|
137
|
-
websocket-extensions (0.1.
|
137
|
+
websocket-extensions (0.1.5)
|
138
138
|
|
139
139
|
PLATFORMS
|
140
140
|
ruby
|
data/lib/peatio/bitgo/version.rb
CHANGED
data/lib/peatio/bitgo/wallet.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Peatio
|
2
2
|
module Bitgo
|
3
3
|
class Wallet < Peatio::Wallet::Abstract
|
4
|
+
TIME_DIFFERENCE_IN_MINUTES = 10
|
5
|
+
XLM_MEMO_TYPES = { 'memoId': 'id', 'memoText': 'text', 'memoHash': 'hash', 'memoReturn': 'return' }
|
4
6
|
|
5
7
|
def initialize(settings = {})
|
6
8
|
@settings = settings
|
@@ -24,10 +26,14 @@ module Peatio
|
|
24
26
|
def create_address!(options = {})
|
25
27
|
currency = erc20_currency_id
|
26
28
|
options.deep_symbolize_keys!
|
27
|
-
|
29
|
+
|
30
|
+
if options.dig(:pa_details, :address_id).present? &&
|
31
|
+
options.dig(:pa_details, :updated_at).present? &&
|
32
|
+
time_difference_in_minutes(options.dig(:pa_details, :updated_at)) >= TIME_DIFFERENCE_IN_MINUTES
|
33
|
+
|
28
34
|
response = client.rest_api(:get, "#{currency}/wallet/#{wallet_id}/address/#{options.dig(:pa_details, :address_id)}")
|
29
35
|
{ address: response['address'], secret: bitgo_wallet_passphrase }
|
30
|
-
|
36
|
+
elsif options.dig(:pa_details, :address_id).blank?
|
31
37
|
response = client.rest_api(:post, "#{currency}/wallet/#{wallet_id}/address")
|
32
38
|
{ address: response['address'], secret: bitgo_wallet_passphrase, details: { address_id: response['id'] }}
|
33
39
|
end
|
@@ -36,7 +42,7 @@ module Peatio
|
|
36
42
|
end
|
37
43
|
|
38
44
|
def create_transaction!(transaction, options = {})
|
39
|
-
currency_options = @currency.fetch(:options).slice(:gas_limit, :gas_price)
|
45
|
+
currency_options = @currency.fetch(:options).slice(:gas_limit, :gas_price, :erc20_contract_address)
|
40
46
|
|
41
47
|
if currency_options[:gas_limit].present? && currency_options[:gas_price].present?
|
42
48
|
options.merge!(currency_options)
|
@@ -52,7 +58,7 @@ module Peatio
|
|
52
58
|
end
|
53
59
|
|
54
60
|
txid = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
|
55
|
-
address: transaction.to_address.to_s,
|
61
|
+
address: normalize_address(transaction.to_address.to_s),
|
56
62
|
amount: amount.to_s,
|
57
63
|
walletPassphrase: bitgo_wallet_passphrase,
|
58
64
|
memo: xlm_memo(transaction.to_address.to_s)
|
@@ -77,6 +83,7 @@ module Peatio
|
|
77
83
|
|
78
84
|
def create_eth_transaction(transaction, options = {})
|
79
85
|
amount = convert_to_base_unit(transaction.amount)
|
86
|
+
hop = true unless options.slice(:erc20_contract_address).present?
|
80
87
|
|
81
88
|
txid = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
|
82
89
|
address: transaction.to_address.to_s,
|
@@ -84,7 +91,7 @@ module Peatio
|
|
84
91
|
walletPassphrase: bitgo_wallet_passphrase,
|
85
92
|
gas: options.fetch(:gas_limit).to_i,
|
86
93
|
gasPrice: options.fetch(:gas_price).to_i,
|
87
|
-
hop:
|
94
|
+
hop: hop
|
88
95
|
}.compact).fetch('txid')
|
89
96
|
|
90
97
|
transaction.hash = normalize_txid(txid)
|
@@ -110,14 +117,15 @@ module Peatio
|
|
110
117
|
end
|
111
118
|
|
112
119
|
def trigger_webhook_event(event)
|
113
|
-
|
114
|
-
return unless
|
120
|
+
currency = @wallet.fetch(:testnet).present? ? 't' + @currency.fetch(:id) : @currency.fetch(:id)
|
121
|
+
return unless currency == event['coin'] && @wallet.fetch(:wallet_id) == event['wallet']
|
115
122
|
|
116
123
|
if event['type'] == 'transfer'
|
117
124
|
transactions = fetch_transfer!(event['transfer'])
|
118
125
|
return { transfers: transactions }
|
119
|
-
elsif event['address_confirmation'
|
120
|
-
|
126
|
+
elsif event['type'] == 'address_confirmation'
|
127
|
+
address_id = fetch_address_id(event['address'])
|
128
|
+
return { address_id: address_id, currency_id: currency_id }
|
121
129
|
end
|
122
130
|
end
|
123
131
|
|
@@ -126,6 +134,14 @@ module Peatio
|
|
126
134
|
address_confirmation_webhook(url)
|
127
135
|
end
|
128
136
|
|
137
|
+
def fetch_address_id(address)
|
138
|
+
currency = erc20_currency_id
|
139
|
+
client.rest_api(:get, "#{currency}/wallet/#{wallet_id}/address/#{address}")
|
140
|
+
.fetch('id')
|
141
|
+
rescue Bitgo::Client::Error => e
|
142
|
+
raise Peatio::Wallet::ClientError, e
|
143
|
+
end
|
144
|
+
|
129
145
|
def fetch_transfer!(id)
|
130
146
|
# TODO: Add Rspecs for this one
|
131
147
|
response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}/transfer/#{id}")
|
@@ -168,7 +184,7 @@ module Peatio
|
|
168
184
|
|
169
185
|
def address_confirmation_webhook(url)
|
170
186
|
client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
|
171
|
-
type: '
|
187
|
+
type: 'address_confirmation',
|
172
188
|
allToken: true,
|
173
189
|
url: url,
|
174
190
|
label: "webhook for #{url}",
|
@@ -206,19 +222,25 @@ module Peatio
|
|
206
222
|
end
|
207
223
|
|
208
224
|
def xlm_memo(address)
|
209
|
-
if @currency.fetch(:id) == 'xlm'
|
210
|
-
{
|
211
|
-
type: "id",
|
212
|
-
value: "#{memo_id_from(address)}"
|
213
|
-
}
|
214
|
-
end
|
225
|
+
build_xlm_memo(address) if @currency.fetch(:id) == 'xlm'
|
215
226
|
end
|
216
227
|
|
217
|
-
def
|
218
|
-
|
219
|
-
|
228
|
+
def build_xlm_memo(address)
|
229
|
+
case address.split('?').last.split('=').first
|
230
|
+
when 'memoId'
|
231
|
+
memo_value_from(address, 'memoId')
|
232
|
+
when 'memoText'
|
233
|
+
memo_value_from(address, 'memoText')
|
234
|
+
when 'memoHash'
|
235
|
+
memo_value_from(address, 'memoHash')
|
236
|
+
when 'memoReturn'
|
237
|
+
memo_value_from(address, 'memoReturn')
|
238
|
+
end
|
239
|
+
end
|
220
240
|
|
221
|
-
|
241
|
+
def memo_value_from(address, type)
|
242
|
+
memo_value = address.partition(type + '=').last
|
243
|
+
return { type: XLM_MEMO_TYPES[type.to_sym], value: memo_value } if memo_value.present?
|
222
244
|
end
|
223
245
|
|
224
246
|
def currency_id
|
@@ -233,6 +255,14 @@ module Peatio
|
|
233
255
|
@wallet.fetch(:wallet_id)
|
234
256
|
end
|
235
257
|
|
258
|
+
def normalize_address(address)
|
259
|
+
if @currency.fetch(:id) == 'xlm'
|
260
|
+
address.split('?').first
|
261
|
+
else
|
262
|
+
address
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
236
266
|
def normalize_txid(txid)
|
237
267
|
txid.downcase
|
238
268
|
end
|
@@ -251,9 +281,13 @@ module Peatio
|
|
251
281
|
x.to_i
|
252
282
|
end
|
253
283
|
|
284
|
+
def time_difference_in_minutes(updated_at)
|
285
|
+
(Time.now - updated_at)/60
|
286
|
+
end
|
287
|
+
|
254
288
|
def define_transaction_state(state)
|
255
289
|
case state
|
256
|
-
when '
|
290
|
+
when 'unconfirmed'
|
257
291
|
'pending'
|
258
292
|
when 'confirmed'
|
259
293
|
'success'
|
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'
|
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.5.1
|
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-08-24 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
|