peatio-bitgo 1.1.2 → 2.5.0

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: 3562bf66638262a55143d4586f07f5946a9dea93fa2dc7efbb57e7b5cab26ca3
4
- data.tar.gz: da0c1795b7df4f31a89437634a92e2cc4049b9c0dad21db8763bb4ebe1fd27b3
3
+ metadata.gz: fce3c54f47f8933c24b2fef521c89acd4ead3ed48fa49c183fb9f67fb3f042a5
4
+ data.tar.gz: 999ec62e379696270429caf760e02c95a078727539b9f5bb42cbd31435987109
5
5
  SHA512:
6
- metadata.gz: 13b857602c498e74b48f0e671321d146fa55c2ce59eca63e3a2ca74775432e9d8957f19f780dc241ca6919a4654652678088bdb30f4285eb697e0d0447bda623
7
- data.tar.gz: 79ba6ba0074fc9beffa667ebcc1fa9c2ead7c416785e664e8f2f73a0f14ca826f8b857401a700cccd088034ea0ed4bcadd18417ddcd718a159ad266df526aed9
6
+ metadata.gz: 30f38ef6aadce408ecf0cd4a4ec04333175f8eee4ca17a07445149dd6e4d31739836917dd3e7d7645dd2f86c7ab7b750c376dda9c0bc9b4e1b35821157543578
7
+ data.tar.gz: 369b7c7d44c01743f8d32ed77d29f89462873ba1c0383dbc5c66ac67e372098be2a822a937ee9cb736a5ffd390b63f5c07d81aa981b8ff9c2d124ffe378e099f
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- peatio-bitgo (1.1.1)
4
+ peatio-bitgo (2.5.0)
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,35 +12,35 @@ 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)
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.0)
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.14.4)
32
- amq-protocol (~> 2.3, >= 2.3.0)
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
- 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.4)
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.3)
86
+ peatio (2.6.1)
87
87
  activemodel (> 5.2, <= 6.0.0)
88
88
  amqp
89
89
  bunny
@@ -104,7 +104,7 @@ GEM
104
104
  pry-byebug (3.9.0)
105
105
  byebug (~> 11.0)
106
106
  pry (~> 0.13.0)
107
- public_suffix (4.0.3)
107
+ public_suffix (4.0.4)
108
108
  rack (2.2.2)
109
109
  rake (13.0.1)
110
110
  rspec (3.9.0)
@@ -126,15 +126,15 @@ GEM
126
126
  eventmachine (~> 1.0, >= 1.0.4)
127
127
  rack (>= 1, < 3)
128
128
  thread_safe (0.3.6)
129
- tzinfo (1.2.6)
129
+ tzinfo (1.2.7)
130
130
  thread_safe (~> 0.1)
131
131
  webmock (3.8.3)
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
@@ -1,5 +1,5 @@
1
1
  module Peatio
2
2
  module Bitgo
3
- VERSION = "1.1.2"
3
+ VERSION = "2.5.0"
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
@@ -36,7 +41,7 @@ module Peatio
36
41
  end
37
42
 
38
43
  def create_transaction!(transaction, options = {})
39
- currency_options = @currency.fetch(:options).slice(:gas_limit, :gas_price)
44
+ currency_options = @currency.fetch(:options).slice(:gas_limit, :gas_price, :erc20_contract_address)
40
45
 
41
46
  if currency_options[:gas_limit].present? && currency_options[:gas_price].present?
42
47
  options.merge!(currency_options)
@@ -77,13 +82,15 @@ module Peatio
77
82
 
78
83
  def create_eth_transaction(transaction, options = {})
79
84
  amount = convert_to_base_unit(transaction.amount)
85
+ hop = true unless options.slice(:erc20_contract_address).present?
80
86
 
81
87
  txid = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
82
88
  address: transaction.to_address.to_s,
83
89
  amount: amount.to_s,
84
90
  walletPassphrase: bitgo_wallet_passphrase,
85
91
  gas: options.fetch(:gas_limit).to_i,
86
- gasPrice: options.fetch(:gas_price).to_i
92
+ gasPrice: options.fetch(:gas_price).to_i,
93
+ hop: hop
87
94
  }.compact).fetch('txid')
88
95
 
89
96
  transaction.hash = normalize_txid(txid)
@@ -109,14 +116,15 @@ module Peatio
109
116
  end
110
117
 
111
118
  def trigger_webhook_event(event)
112
- currency_id = @wallet.fetch(:testnet).present? ? 't' + @currency.fetch(:id) : @currency.fetch(:id)
113
- 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']
114
121
 
115
122
  if event['type'] == 'transfer'
116
123
  transactions = fetch_transfer!(event['transfer'])
117
124
  return { transfers: transactions }
118
- elsif event['address_confirmation']
119
- # 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 }
120
128
  end
121
129
  end
122
130
 
@@ -125,6 +133,14 @@ module Peatio
125
133
  address_confirmation_webhook(url)
126
134
  end
127
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
+
128
144
  def fetch_transfer!(id)
129
145
  # TODO: Add Rspecs for this one
130
146
  response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}/transfer/#{id}")
@@ -167,7 +183,7 @@ module Peatio
167
183
 
168
184
  def address_confirmation_webhook(url)
169
185
  client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
170
- type: 'address_confirmation_webhook',
186
+ type: 'address_confirmation',
171
187
  allToken: true,
172
188
  url: url,
173
189
  label: "webhook for #{url}",
@@ -250,9 +266,13 @@ module Peatio
250
266
  x.to_i
251
267
  end
252
268
 
269
+ def time_difference_in_minutes(updated_at)
270
+ (Time.now - updated_at)/60
271
+ end
272
+
253
273
  def define_transaction_state(state)
254
274
  case state
255
- when 'unconfrimed'
275
+ when 'unconfirmed'
256
276
  'pending'
257
277
  when 'confirmed'
258
278
  '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.2
4
+ version: 2.5.0
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-04-20 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