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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 274572ccfc7d17e3150b4271d2872fda747aff0684a50e21c8bb74382e0c437f
4
- data.tar.gz: f90adec7c757956565af265400011033a73902348ee1a1d98393ea51e83e2ab1
3
+ metadata.gz: 6fd69cb9355753e4b4dfcd36af40b937c4dbf6b673e565ee2263dafd0f02dc97
4
+ data.tar.gz: 073411c6f80b338c7aafed028cf3ab13b4570bb825eda0c39c9ff6a6106af666
5
5
  SHA512:
6
- metadata.gz: 58ec57b436b4e5d43d71d3b6db335e36cb4e0c49fac46a9495c2bfdfc1bcf3909577ba1367641bc3a3357adb2779bb515270d285662fdfa9ed0cef62526c49b7
7
- data.tar.gz: 8fc3e3d276680e91140264bc3ab9d32648632598484dd23ddebdb36d4b79612eb14a585d902ac12585a8b92831e4db4712b3d6444e6ef0ed12c932fab98ae71a
6
+ metadata.gz: 7381d4c8ee6d975024a25184067ef83e77cb41cf541a21d2d7acb289b78747bc26f4ac377aed951ac61ff4bf1c60f2e95e6ad1272e2f9840ef3b8a7ba9573c10
7
+ data.tar.gz: 3df1fcd729d750b4fb37afb44b054a7a19e7d36c129786561a6832b7095dbeabd84796f331fcb1a11fe1721707c7647666bb6a6019be1f14842b3b27048895a1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- peatio-bitgo (2.6.0)
4
+ peatio-bitgo (2.6.1)
5
5
  activesupport (~> 5.2.3)
6
6
  better-faraday (~> 1.0.5)
7
7
  faraday (~> 0.17)
@@ -22,7 +22,7 @@ module Peatio
22
22
  args = [@endpoint.to_s + path]
23
23
 
24
24
  if data
25
- if %i[ post put patch ].include?(verb)
25
+ if %i[post put patch].include?(verb)
26
26
  args << data.compact.to_json
27
27
  args << { 'Content-Type' => 'application/json' }
28
28
  else
@@ -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 requiremnt was not suttisfied by Peatio::Blockchain.",
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 requiremnt was not suttisfied by Peatio::Wallet.",
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 }
@@ -1,5 +1,5 @@
1
1
  module Peatio
2
2
  module Bitgo
3
- VERSION = "2.6.0".freeze
3
+ VERSION = "2.6.1".freeze
4
4
  end
5
5
  end
@@ -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
- if options.dig(:pa_details,:address_id).present?
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
- else
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
- 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']
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
- # TODO Add Address confirmation
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: 'address_confirmation_webhook',
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 'unconfrimed'
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.0
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-05-15 00:00:00.000000000 Z
11
+ date: 2020-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport