peatio-bitgo 2.6.0 → 2.6.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 +1 -1
- data/lib/peatio/bitgo/client.rb +1 -1
- data/lib/peatio/bitgo/hooks.rb +2 -2
- data/lib/peatio/bitgo/version.rb +1 -1
- data/lib/peatio/bitgo/wallet.rb +26 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fd69cb9355753e4b4dfcd36af40b937c4dbf6b673e565ee2263dafd0f02dc97
|
4
|
+
data.tar.gz: 073411c6f80b338c7aafed028cf3ab13b4570bb825eda0c39c9ff6a6106af666
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7381d4c8ee6d975024a25184067ef83e77cb41cf541a21d2d7acb289b78747bc26f4ac377aed951ac61ff4bf1c60f2e95e6ad1272e2f9840ef3b8a7ba9573c10
|
7
|
+
data.tar.gz: 3df1fcd729d750b4fb37afb44b054a7a19e7d36c129786561a6832b7095dbeabd84796f331fcb1a11fe1721707c7647666bb6a6019be1f14842b3b27048895a1
|
data/Gemfile.lock
CHANGED
data/lib/peatio/bitgo/client.rb
CHANGED
data/lib/peatio/bitgo/hooks.rb
CHANGED
@@ -9,7 +9,7 @@ module Peatio
|
|
9
9
|
unless Gem::Requirement.new(BLOCKCHAIN_VERSION_REQUIREMENT)
|
10
10
|
.satisfied_by?(Gem::Version.new(Peatio::Blockchain::VERSION))
|
11
11
|
[
|
12
|
-
"Bitgo blockchain version
|
12
|
+
"Bitgo blockchain version requirement was not satisfied by Peatio::Blockchain.",
|
13
13
|
"Bitgo blockchain requires #{BLOCKCHAIN_VERSION_REQUIREMENT}.",
|
14
14
|
"Peatio::Blockchain version is #{Peatio::Blockchain::VERSION}"
|
15
15
|
].join('\n').tap { |s| Kernel.abort s }
|
@@ -18,7 +18,7 @@ module Peatio
|
|
18
18
|
unless Gem::Requirement.new(WALLET_VERSION_REQUIREMENT)
|
19
19
|
.satisfied_by?(Gem::Version.new(Peatio::Wallet::VERSION))
|
20
20
|
[
|
21
|
-
"Bitgo wallet version
|
21
|
+
"Bitgo wallet version requirement was not satisfied by Peatio::Wallet.",
|
22
22
|
"Bitgo wallet requires #{WALLET_VERSION_REQUIREMENT}.",
|
23
23
|
"Peatio::Wallet version is #{Peatio::Wallet::VERSION}"
|
24
24
|
].join('\n').tap { |s| Kernel.abort s }
|
data/lib/peatio/bitgo/version.rb
CHANGED
data/lib/peatio/bitgo/wallet.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Peatio
|
2
2
|
module Bitgo
|
3
3
|
class Wallet < Peatio::Wallet::Abstract
|
4
|
+
TIME_DIFFERENCE_IN_MINUTES = 10
|
4
5
|
|
5
6
|
def initialize(settings = {})
|
6
7
|
@settings = settings
|
@@ -24,10 +25,14 @@ module Peatio
|
|
24
25
|
def create_address!(options = {})
|
25
26
|
currency = erc20_currency_id
|
26
27
|
options.deep_symbolize_keys!
|
27
|
-
|
28
|
+
|
29
|
+
if options.dig(:pa_details, :address_id).present? &&
|
30
|
+
options.dig(:pa_details, :updated_at).present? &&
|
31
|
+
time_difference_in_minutes(options.dig(:pa_details, :updated_at)) >= TIME_DIFFERENCE_IN_MINUTES
|
32
|
+
|
28
33
|
response = client.rest_api(:get, "#{currency}/wallet/#{wallet_id}/address/#{options.dig(:pa_details, :address_id)}")
|
29
34
|
{ address: response['address'], secret: bitgo_wallet_passphrase }
|
30
|
-
|
35
|
+
elsif options.dig(:pa_details, :address_id).blank?
|
31
36
|
response = client.rest_api(:post, "#{currency}/wallet/#{wallet_id}/address")
|
32
37
|
{ address: response['address'], secret: bitgo_wallet_passphrase, details: { address_id: response['id'] }}
|
33
38
|
end
|
@@ -111,14 +116,15 @@ module Peatio
|
|
111
116
|
end
|
112
117
|
|
113
118
|
def trigger_webhook_event(event)
|
114
|
-
|
115
|
-
return unless
|
119
|
+
currency = @wallet.fetch(:testnet).present? ? 't' + @currency.fetch(:id) : @currency.fetch(:id)
|
120
|
+
return unless currency == event['coin'] && @wallet.fetch(:wallet_id) == event['wallet']
|
116
121
|
|
117
122
|
if event['type'] == 'transfer'
|
118
123
|
transactions = fetch_transfer!(event['transfer'])
|
119
124
|
return { transfers: transactions }
|
120
|
-
elsif event['address_confirmation'
|
121
|
-
|
125
|
+
elsif event['type'] == 'address_confirmation'
|
126
|
+
address_id = fetch_address_id(event['address'])
|
127
|
+
return { address_id: address_id, currency_id: currency_id }
|
122
128
|
end
|
123
129
|
end
|
124
130
|
|
@@ -127,6 +133,14 @@ module Peatio
|
|
127
133
|
address_confirmation_webhook(url)
|
128
134
|
end
|
129
135
|
|
136
|
+
def fetch_address_id(address)
|
137
|
+
currency = erc20_currency_id
|
138
|
+
client.rest_api(:get, "#{currency}/wallet/#{wallet_id}/address/#{address}")
|
139
|
+
.fetch('id')
|
140
|
+
rescue Bitgo::Client::Error => e
|
141
|
+
raise Peatio::Wallet::ClientError, e
|
142
|
+
end
|
143
|
+
|
130
144
|
def fetch_transfer!(id)
|
131
145
|
# TODO: Add Rspecs for this one
|
132
146
|
response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}/transfer/#{id}")
|
@@ -169,7 +183,7 @@ module Peatio
|
|
169
183
|
|
170
184
|
def address_confirmation_webhook(url)
|
171
185
|
client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
|
172
|
-
type: '
|
186
|
+
type: 'address_confirmation',
|
173
187
|
allToken: true,
|
174
188
|
url: url,
|
175
189
|
label: "webhook for #{url}",
|
@@ -252,9 +266,13 @@ module Peatio
|
|
252
266
|
x.to_i
|
253
267
|
end
|
254
268
|
|
269
|
+
def time_difference_in_minutes(updated_at)
|
270
|
+
(Time.now - updated_at)/60
|
271
|
+
end
|
272
|
+
|
255
273
|
def define_transaction_state(state)
|
256
274
|
case state
|
257
|
-
when '
|
275
|
+
when 'unconfirmed'
|
258
276
|
'pending'
|
259
277
|
when 'confirmed'
|
260
278
|
'success'
|
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: 2.6.
|
4
|
+
version: 2.6.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-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|