peatio-bitgo 1.1.4 → 2.6.2

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: 0bf98903c7304e77f6cdc28f1f41c15a8bb8fb247e6edde49e146f0dc49c5690
4
- data.tar.gz: 1848b2e16408c9d2ea516388e77fb6c16a314bbc5b4ae6c300da1f492e545c57
3
+ metadata.gz: 863d387c7b57c73ce93ec4157f024f866ae5535605c4e65806b2becfe9251015
4
+ data.tar.gz: 59513ea996a0a5fb87abe27492d8944b7ce2d8557a89f75814622f437b189ffd
5
5
  SHA512:
6
- metadata.gz: 70a230d27976389a7eaeed25506bd1385508bb95fd82742487b39861b31854301856c65ef772ccc0a43d82359f37a9464fa70981254d42ebf80ead10acab6dd7
7
- data.tar.gz: e4987b11326c0c8d1f7d2b7b58bb8c1fa8e1becc88772aff96d72d4e0b47b987e17e8930179b3b286ad76ee0dd43aebb6e3adaec9faa06ed32d4a1170e020a98
6
+ metadata.gz: f9b4ea980fe2f0fa19c4f10991b3017d0e4cbff8273fe411c945d0a82004578ec1b12fd9d31f8081544a914509bd92d246083c36cd9444b75ab82f591f7a8cd8
7
+ data.tar.gz: 2987a6430253bb2e6882980760f5a14423b102f47d8b3daa07d8daaa094c6ec41cfb443fe4fe39471a1be647855096608176d0caf547a2e41876ebe57c5c685f
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- peatio-bitgo (1.1.4)
4
+ peatio-bitgo (2.6.2)
5
5
  activesupport (~> 5.2.3)
6
6
  better-faraday (~> 1.0.5)
7
- faraday (~> 0.15.4)
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,9 +12,9 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- activemodel (5.2.4.2)
16
- activesupport (= 5.2.4.2)
17
- activesupport (5.2.4.2)
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)
@@ -34,13 +34,13 @@ GEM
34
34
  clamp (1.3.1)
35
35
  coderay (1.1.2)
36
36
  concurrent-ruby (1.1.6)
37
- connection_pool (2.2.2)
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
42
  diff-lcs (1.3)
43
- em-http-request (1.1.5)
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,11 +54,11 @@ GEM
54
54
  eventmachine (>= 0.12.9)
55
55
  http_parser.rb (~> 0.6.0)
56
56
  eventmachine (1.2.7)
57
- faraday (0.15.4)
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.2.5)
61
+ faye (1.3.0)
62
62
  cookiejar (>= 0.3.0)
63
63
  em-http-request (>= 0.3.0)
64
64
  eventmachine (>= 0.12.0)
@@ -71,19 +71,19 @@ GEM
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.2)
74
+ i18n (1.8.3)
75
75
  concurrent-ruby (~> 1.0)
76
76
  jwt (2.2.1)
77
77
  memoist (0.16.2)
78
78
  method_source (1.0.0)
79
- minitest (5.14.0)
79
+ minitest (5.14.1)
80
80
  mocha (1.11.2)
81
81
  multi_json (1.14.1)
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.4.4)
86
+ peatio (2.6.1)
87
87
  activemodel (> 5.2, <= 6.0.0)
88
88
  amqp
89
89
  bunny
@@ -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.1)
135
+ websocket-driver (0.7.2)
136
136
  websocket-extensions (>= 0.1.0)
137
- websocket-extensions (0.1.4)
137
+ websocket-extensions (0.1.5)
138
138
 
139
139
  PLATFORMS
140
140
  ruby
@@ -5,7 +5,7 @@ module Peatio
5
5
  module Bitgo
6
6
  class Client
7
7
  Error = Class.new(StandardError)
8
- class ConnectionError < Error; end
8
+ ConnectionError = Class.new(Error)
9
9
 
10
10
  class ResponseError < Error
11
11
  def initialize(msg)
@@ -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
@@ -48,8 +48,6 @@ module Peatio
48
48
  else
49
49
  raise ConnectionError, JSON.parse(e.response.body)['message']
50
50
  end
51
- rescue StandardError => e
52
- raise Error, e
53
51
  end
54
52
  end
55
53
  end
@@ -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 = "1.1.4"
3
+ VERSION = "2.6.2".freeze
4
4
  end
5
5
  end
@@ -1,9 +1,13 @@
1
1
  module Peatio
2
2
  module Bitgo
3
3
  class Wallet < Peatio::Wallet::Abstract
4
+ TIME_DIFFERENCE_IN_MINUTES = 10
4
5
 
5
- def initialize(settings = {})
6
- @settings = settings
6
+ DEFAULT_FEATURES = { skip_deposit_collection: false }.freeze
7
+
8
+ def initialize(custom_features = {})
9
+ @features = DEFAULT_FEATURES.merge(custom_features).slice(*SUPPORTED_FEATURES)
10
+ @settings = {}
7
11
  end
8
12
 
9
13
  def configure(settings = {})
@@ -24,10 +28,14 @@ module Peatio
24
28
  def create_address!(options = {})
25
29
  currency = erc20_currency_id
26
30
  options.deep_symbolize_keys!
27
- if options.dig(:pa_details,:address_id).present?
31
+
32
+ if options.dig(:pa_details, :address_id).present? &&
33
+ options.dig(:pa_details, :updated_at).present? &&
34
+ time_difference_in_minutes(options.dig(:pa_details, :updated_at)) >= TIME_DIFFERENCE_IN_MINUTES
35
+
28
36
  response = client.rest_api(:get, "#{currency}/wallet/#{wallet_id}/address/#{options.dig(:pa_details, :address_id)}")
29
37
  { address: response['address'], secret: bitgo_wallet_passphrase }
30
- else
38
+ elsif options.dig(:pa_details, :address_id).blank?
31
39
  response = client.rest_api(:post, "#{currency}/wallet/#{wallet_id}/address")
32
40
  { address: response['address'], secret: bitgo_wallet_passphrase, details: { address_id: response['id'] }}
33
41
  end
@@ -111,14 +119,15 @@ module Peatio
111
119
  end
112
120
 
113
121
  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']
122
+ currency = @wallet.fetch(:testnet).present? ? 't' + @currency.fetch(:id) : @currency.fetch(:id)
123
+ return unless currency == event['coin'] && @wallet.fetch(:wallet_id) == event['wallet']
116
124
 
117
125
  if event['type'] == 'transfer'
118
126
  transactions = fetch_transfer!(event['transfer'])
119
127
  return { transfers: transactions }
120
- elsif event['address_confirmation']
121
- # TODO Add Address confirmation
128
+ elsif event['type'] == 'address_confirmation'
129
+ address_id = fetch_address_id(event['address'])
130
+ return { address_id: address_id, currency_id: currency_id }
122
131
  end
123
132
  end
124
133
 
@@ -127,6 +136,14 @@ module Peatio
127
136
  address_confirmation_webhook(url)
128
137
  end
129
138
 
139
+ def fetch_address_id(address)
140
+ currency = erc20_currency_id
141
+ client.rest_api(:get, "#{currency}/wallet/#{wallet_id}/address/#{address}")
142
+ .fetch('id')
143
+ rescue Bitgo::Client::Error => e
144
+ raise Peatio::Wallet::ClientError, e
145
+ end
146
+
130
147
  def fetch_transfer!(id)
131
148
  # TODO: Add Rspecs for this one
132
149
  response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}/transfer/#{id}")
@@ -169,7 +186,7 @@ module Peatio
169
186
 
170
187
  def address_confirmation_webhook(url)
171
188
  client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
172
- type: 'address_confirmation_webhook',
189
+ type: 'address_confirmation',
173
190
  allToken: true,
174
191
  url: url,
175
192
  label: "webhook for #{url}",
@@ -252,9 +269,13 @@ module Peatio
252
269
  x.to_i
253
270
  end
254
271
 
272
+ def time_difference_in_minutes(updated_at)
273
+ (Time.now - updated_at)/60
274
+ end
275
+
255
276
  def define_transaction_state(state)
256
277
  case state
257
- when 'unconfrimed'
278
+ when 'unconfirmed'
258
279
  'pending'
259
280
  when 'confirmed'
260
281
  'success'
@@ -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.15.4"
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: 1.1.4
4
+ version: 2.6.2
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-11 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
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.15.4
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.15.4
54
+ version: '0.17'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: memoist
57
57
  requirement: !ruby/object:Gem::Requirement