peatio-bitgo 1.1.4 → 2.5.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: acdc8edfa1495b5fe9d11d0396c34c36e086dd4594289745e66c506a61b72194
4
+ data.tar.gz: ec04b54eb43a007e4e0bd02c9ec3efbc333b76da239b876ba73c251ac23563a4
5
5
  SHA512:
6
- metadata.gz: 70a230d27976389a7eaeed25506bd1385508bb95fd82742487b39861b31854301856c65ef772ccc0a43d82359f37a9464fa70981254d42ebf80ead10acab6dd7
7
- data.tar.gz: e4987b11326c0c8d1f7d2b7b58bb8c1fa8e1becc88772aff96d72d4e0b47b987e17e8930179b3b286ad76ee0dd43aebb6e3adaec9faa06ed32d4a1170e020a98
6
+ metadata.gz: 44d662cd396e174301f130c25e2904fef5f1cfcbd47aa9090c81ed65a6b1422682ebf78ef80c8d9c34008763252b9432cc6aef72748f615361d94da0bb77bccd
7
+ data.tar.gz: 40ba65fa72eeaf02f69153a394a8ac4a177f50ea06ed4ce86217209865c82d6e37e8d6c13c5056d877dd40719bd53ffbe2d3331e2faf14383a39aa00dffefa78
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- peatio-bitgo (1.1.4)
4
+ peatio-bitgo (2.5.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,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.5)
16
+ activesupport (= 5.2.4.5)
17
+ activesupport (5.2.4.5)
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.1)
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.15.0)
31
+ bunny (2.17.0)
32
32
  amq-protocol (~> 2.3, >= 2.3.1)
33
- byebug (11.1.1)
34
- clamp (1.3.1)
35
- coderay (1.1.2)
36
- concurrent-ruby (1.1.6)
37
- connection_pool (2.2.2)
33
+ byebug (11.1.3)
34
+ clamp (1.3.2)
35
+ coderay (1.1.3)
36
+ concurrent-ruby (1.1.8)
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.3)
43
- em-http-request (1.1.5)
42
+ diff-lcs (1.4.4)
43
+ em-http-request (1.1.7)
44
44
  addressable (>= 2.3.4)
45
45
  cookiejar (!= 0.3.1)
46
46
  em-socksify (>= 0.3)
@@ -50,40 +50,40 @@ GEM
50
50
  eventmachine (>= 1.0.0.beta.4)
51
51
  em-synchrony (1.0.6)
52
52
  eventmachine (>= 1.0.0.beta.1)
53
- em-websocket (0.5.1)
53
+ em-websocket (0.5.2)
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.4)
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.4.0)
62
62
  cookiejar (>= 0.3.0)
63
- em-http-request (>= 0.3.0)
63
+ em-http-request (>= 1.1.6)
64
64
  eventmachine (>= 0.12.0)
65
- faye-websocket (>= 0.9.1)
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.10.9)
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.2)
74
+ i18n (1.8.9)
75
75
  concurrent-ruby (~> 1.0)
76
- jwt (2.2.1)
76
+ jwt (2.2.2)
77
77
  memoist (0.16.2)
78
78
  method_source (1.0.0)
79
- minitest (5.14.0)
79
+ minitest (5.14.4)
80
80
  mocha (1.11.2)
81
- multi_json (1.14.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.4.4)
86
+ peatio (2.6.3)
87
87
  activemodel (> 5.2, <= 6.0.0)
88
88
  amqp
89
89
  bunny
@@ -97,44 +97,44 @@ GEM
97
97
  mysql2
98
98
  prometheus-client
99
99
  thin
100
- prometheus-client (2.0.0)
101
- pry (0.13.0)
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.4)
108
- rack (2.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.1)
115
- rspec-support (~> 3.9.1)
116
- rspec-expectations (3.9.1)
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.2)
122
+ rspec-support (3.9.3)
123
123
  safe_yaml (1.0.5)
124
- thin (1.7.2)
124
+ thin (1.8.0)
125
125
  daemons (~> 1.0, >= 1.0.9)
126
126
  eventmachine (~> 1.0, >= 1.0.4)
127
127
  rack (>= 1, < 3)
128
128
  thread_safe (0.3.6)
129
- tzinfo (1.2.7)
129
+ tzinfo (1.2.9)
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.3)
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.4"
3
+ VERSION = "2.5.2"
4
4
  end
5
5
  end
@@ -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
- if options.dig(:pa_details,:address_id).present?
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
- else
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
@@ -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)
@@ -111,14 +117,15 @@ module Peatio
111
117
  end
112
118
 
113
119
  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']
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']
116
122
 
117
123
  if event['type'] == 'transfer'
118
124
  transactions = fetch_transfer!(event['transfer'])
119
125
  return { transfers: transactions }
120
- elsif event['address_confirmation']
121
- # TODO Add Address confirmation
126
+ elsif event['type'] == 'address_confirmation'
127
+ address_id = fetch_address_id(event['address'])
128
+ return { address_id: address_id, currency_id: currency_id }
122
129
  end
123
130
  end
124
131
 
@@ -127,6 +134,14 @@ module Peatio
127
134
  address_confirmation_webhook(url)
128
135
  end
129
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
+
130
145
  def fetch_transfer!(id)
131
146
  # TODO: Add Rspecs for this one
132
147
  response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}/transfer/#{id}")
@@ -146,8 +161,7 @@ module Peatio
146
161
  hash: normalize_txid(response['txid']),
147
162
  to_address: to_address,
148
163
  block_number: response['height'],
149
- # TODO: Add sendmany support
150
- txout: 0,
164
+ txout: response['index'].to_i,
151
165
  status: state
152
166
  )
153
167
 
@@ -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}",
@@ -207,19 +221,25 @@ module Peatio
207
221
  end
208
222
 
209
223
  def xlm_memo(address)
210
- if @currency.fetch(:id) == 'xlm'
211
- {
212
- type: "id",
213
- value: "#{memo_id_from(address)}"
214
- }
215
- end
224
+ build_xlm_memo(address) if @currency.fetch(:id) == 'xlm'
216
225
  end
217
226
 
218
- def memo_id_from(address)
219
- memo_id = address.partition('memoId=').last
220
- memo_id = 0 if memo_id.empty?
227
+ def build_xlm_memo(address)
228
+ case address.split('?').last.split('=').first
229
+ when 'memoId'
230
+ memo_value_from(address, 'memoId')
231
+ when 'memoText'
232
+ memo_value_from(address, 'memoText')
233
+ when 'memoHash'
234
+ memo_value_from(address, 'memoHash')
235
+ when 'memoReturn'
236
+ memo_value_from(address, 'memoReturn')
237
+ end
238
+ end
221
239
 
222
- memo_id
240
+ def memo_value_from(address, type)
241
+ memo_value = address.partition(type + '=').last
242
+ return { type: XLM_MEMO_TYPES[type.to_sym], value: memo_value } if memo_value.present?
223
243
  end
224
244
 
225
245
  def currency_id
@@ -234,6 +254,14 @@ module Peatio
234
254
  @wallet.fetch(:wallet_id)
235
255
  end
236
256
 
257
+ def normalize_address(address)
258
+ if @currency.fetch(:id) == 'xlm'
259
+ address.split('?').first
260
+ else
261
+ address
262
+ end
263
+ end
264
+
237
265
  def normalize_txid(txid)
238
266
  txid.downcase
239
267
  end
@@ -252,9 +280,13 @@ module Peatio
252
280
  x.to_i
253
281
  end
254
282
 
283
+ def time_difference_in_minutes(updated_at)
284
+ (Time.now - updated_at)/60
285
+ end
286
+
255
287
  def define_transaction_state(state)
256
288
  case state
257
- when 'unconfrimed'
289
+ when 'unconfirmed'
258
290
  'pending'
259
291
  when 'confirmed'
260
292
  '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.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.5.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: 2021-03-15 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