peatio-bitgo 1.1.1 → 1.1.6

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: 77fecc938decb7012e77db67d8334287226c3a3761d0fa6f075c0e93119418d8
4
- data.tar.gz: fb16e7373708ebdf0b08fa85580d335853f64164854cad3ea1744a09277c15b1
3
+ metadata.gz: 0e6ffc9f6a29d20c55aa26f8a994716ce498de62148155aa0c9e913317b22556
4
+ data.tar.gz: c555fb0d1b789975bda7a2c66b5b603495595e2fbd444190a7d09482ecf6a18c
5
5
  SHA512:
6
- metadata.gz: b5a7d4d96979e76c524ba8b5e67304cb497d3f911ed05873b20bbe2df94bda0bd192d7f3896e8437e86889db41844a4b56cbd04246dd71d7058dcf9be7c188c5
7
- data.tar.gz: b86529c189d9399b28b35d493c8db850c9fc6187f50508d9df3131be329b9097fdc2431edbcc579275eda2d2f0cdef31f7455644dc7fc0d81f3ef39cb19b3382
6
+ metadata.gz: 904163faf9796c12fa9ab7865f46f70fb3f84e6974606a1a21f246e99eba68226dc28f4ccdb1c77a6a3cd2282dcc80a6d848e76849c7391664ec83b69175279e
7
+ data.tar.gz: 7e148da7a6b7cea1bbb14593081dceff1decb14d96d004181af925503560b35d47837954d5a9a755e1f73ecaec1f717cf545a13e4d056833920846b18b44df79
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- peatio-bitgo (1.1.1)
4
+ peatio-bitgo (1.1.6)
5
5
  activesupport (~> 5.2.3)
6
6
  better-faraday (~> 1.0.5)
7
7
  faraday (~> 0.15.4)
@@ -21,15 +21,15 @@ GEM
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)
@@ -58,7 +58,7 @@ GEM
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.2.5)
62
62
  cookiejar (>= 0.3.0)
63
63
  em-http-request (>= 0.3.0)
64
64
  eventmachine (>= 0.12.0)
@@ -83,7 +83,7 @@ GEM
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.4.4)
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,7 +126,7 @@ 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)
@@ -43,7 +43,11 @@ module Peatio
43
43
  response['error'].tap { |error| raise ResponseError.new(error) if error }
44
44
  response
45
45
  rescue Faraday::Error => e
46
- raise ConnectionError, e
46
+ if e.is_a?(Faraday::ConnectionFailed) || e.is_a?(Faraday::TimeoutError)
47
+ raise ConnectionError, e
48
+ else
49
+ raise ConnectionError, JSON.parse(e.response.body)['message']
50
+ end
47
51
  rescue StandardError => e
48
52
  raise Error, e
49
53
  end
@@ -1,5 +1,5 @@
1
1
  module Peatio
2
2
  module Bitgo
3
- VERSION = "1.1.1"
3
+ VERSION = "1.1.6"
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)
@@ -54,7 +59,8 @@ module Peatio
54
59
  txid = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
55
60
  address: transaction.to_address.to_s,
56
61
  amount: amount.to_s,
57
- walletPassphrase: bitgo_wallet_passphrase
62
+ walletPassphrase: bitgo_wallet_passphrase,
63
+ memo: xlm_memo(transaction.to_address.to_s)
58
64
  }.compact).fetch('txid')
59
65
 
60
66
  transaction.hash = normalize_txid(txid)
@@ -76,13 +82,15 @@ module Peatio
76
82
 
77
83
  def create_eth_transaction(transaction, options = {})
78
84
  amount = convert_to_base_unit(transaction.amount)
85
+ hop = true unless options.slice(:erc20_contract_address).present?
79
86
 
80
87
  txid = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
81
88
  address: transaction.to_address.to_s,
82
89
  amount: amount.to_s,
83
90
  walletPassphrase: bitgo_wallet_passphrase,
84
91
  gas: options.fetch(:gas_limit).to_i,
85
- gasPrice: options.fetch(:gas_price).to_i
92
+ gasPrice: options.fetch(:gas_price).to_i,
93
+ hop: hop
86
94
  }.compact).fetch('txid')
87
95
 
88
96
  transaction.hash = normalize_txid(txid)
@@ -108,14 +116,15 @@ module Peatio
108
116
  end
109
117
 
110
118
  def trigger_webhook_event(event)
111
- currency_id = @wallet.fetch(:testnet).present? ? 't' + @currency.fetch(:id) : @currency.fetch(:id)
112
- 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']
113
121
 
114
122
  if event['type'] == 'transfer'
115
123
  transactions = fetch_transfer!(event['transfer'])
116
124
  return { transfers: transactions }
117
- elsif event['address_confirmation']
118
- # 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 }
119
128
  end
120
129
  end
121
130
 
@@ -124,20 +133,26 @@ module Peatio
124
133
  address_confirmation_webhook(url)
125
134
  end
126
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
+
127
144
  def fetch_transfer!(id)
128
145
  # TODO: Add Rspecs for this one
129
146
  response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}/transfer/#{id}")
130
147
  parse_entries(response['entries']).map do |entry|
131
148
  to_address = if response.dig('coinSpecific', 'memo').present?
132
- build_address(response.dig('coinSpecific', 'memo').first)
149
+ memo = response.dig('coinSpecific', 'memo')
150
+ memo_type = memo.kind_of?(Array) ? memo.first : memo
151
+ build_address(entry['address'], memo_type)
133
152
  else
134
153
  entry['address']
135
154
  end
136
- state = if response['state'] == 'unconfrimed'
137
- 'pending'
138
- elsif response['state'] == 'confirmed'
139
- 'success'
140
- end
155
+ state = define_transaction_state(response['state'])
141
156
 
142
157
  transaction = Peatio::Transaction.new(
143
158
  currency_id: @currency.fetch(:id),
@@ -168,7 +183,7 @@ module Peatio
168
183
 
169
184
  def address_confirmation_webhook(url)
170
185
  client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
171
- type: 'address_confirmation_webhook',
186
+ type: 'address_confirmation',
172
187
  allToken: true,
173
188
  url: url,
174
189
  label: "webhook for #{url}",
@@ -193,8 +208,8 @@ module Peatio
193
208
  @client ||= Client.new(uri, access_token)
194
209
  end
195
210
 
196
- def build_address(memo)
197
- "#{memo['address']}?memoId=#{memo['value']}"
211
+ def build_address(address, memo)
212
+ "#{address}?memoId=#{memo['value']}"
198
213
  end
199
214
 
200
215
  # All these functions will have to be done with the coin set to eth or teth
@@ -205,6 +220,22 @@ module Peatio
205
220
  currency_id
206
221
  end
207
222
 
223
+ def xlm_memo(address)
224
+ if @currency.fetch(:id) == 'xlm'
225
+ {
226
+ type: "id",
227
+ value: "#{memo_id_from(address)}"
228
+ }
229
+ end
230
+ end
231
+
232
+ def memo_id_from(address)
233
+ memo_id = address.partition('memoId=').last
234
+ memo_id = 0 if memo_id.empty?
235
+
236
+ memo_id
237
+ end
238
+
208
239
  def currency_id
209
240
  @currency.fetch(:id) { raise Peatio::Wallet::MissingSettingError, :id }
210
241
  end
@@ -234,6 +265,21 @@ module Peatio
234
265
  end
235
266
  x.to_i
236
267
  end
268
+
269
+ def time_difference_in_minutes(updated_at)
270
+ (Time.now - updated_at)/60
271
+ end
272
+
273
+ def define_transaction_state(state)
274
+ case state
275
+ when 'unconfirmed'
276
+ 'pending'
277
+ when 'confirmed'
278
+ 'success'
279
+ when 'failed','rejected'
280
+ 'failed'
281
+ end
282
+ end
237
283
  end
238
284
  end
239
285
  end
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.1
4
+ version: 1.1.6
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-03-26 00:00:00.000000000 Z
11
+ date: 2020-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport