peatio-bitgo 1.1.3 → 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: 8308298f5cd4459b9d14ce7d7a142c8684d19ceb60f4f48656cbc3acfcf39d58
4
- data.tar.gz: fceb8e50206eb0bf641fb1e52f6741328d3019388211297f8b76c6cdff8fa406
3
+ metadata.gz: 6fd69cb9355753e4b4dfcd36af40b937c4dbf6b673e565ee2263dafd0f02dc97
4
+ data.tar.gz: 073411c6f80b338c7aafed028cf3ab13b4570bb825eda0c39c9ff6a6106af666
5
5
  SHA512:
6
- metadata.gz: 06f8b0f3352e04437ccfd8ed8e9260b78a6c7af2b80350ebe1c6ee2f97fbf109a353a62d1c2ceee31e4c57b30ad666f7f5697fa80420de755618bd8985709e67
7
- data.tar.gz: 61568aa6be7fe158d0b34245b7dd35cba09972f7e63102fdf9e08d355c15691646d4f992288d17e2a778eb657f646af350bd89844568748cd351d264d75bdd4d
6
+ metadata.gz: 7381d4c8ee6d975024a25184067ef83e77cb41cf541a21d2d7acb289b78747bc26f4ac377aed951ac61ff4bf1c60f2e95e6ad1272e2f9840ef3b8a7ba9573c10
7
+ data.tar.gz: 3df1fcd729d750b4fb37afb44b054a7a19e7d36c129786561a6832b7095dbeabd84796f331fcb1a11fe1721707c7647666bb6a6019be1f14842b3b27048895a1
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- peatio-bitgo (1.1.3)
4
+ peatio-bitgo (2.6.1)
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)
@@ -54,7 +54,7 @@ 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)
@@ -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.3"
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
@@ -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,6 +82,7 @@ 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,
@@ -84,7 +90,7 @@ module Peatio
84
90
  walletPassphrase: bitgo_wallet_passphrase,
85
91
  gas: options.fetch(:gas_limit).to_i,
86
92
  gasPrice: options.fetch(:gas_price).to_i,
87
- hop: true
93
+ hop: hop
88
94
  }.compact).fetch('txid')
89
95
 
90
96
  transaction.hash = normalize_txid(txid)
@@ -110,14 +116,15 @@ module Peatio
110
116
  end
111
117
 
112
118
  def trigger_webhook_event(event)
113
- currency_id = @wallet.fetch(:testnet).present? ? 't' + @currency.fetch(:id) : @currency.fetch(:id)
114
- 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']
115
121
 
116
122
  if event['type'] == 'transfer'
117
123
  transactions = fetch_transfer!(event['transfer'])
118
124
  return { transfers: transactions }
119
- elsif event['address_confirmation']
120
- # 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 }
121
128
  end
122
129
  end
123
130
 
@@ -126,6 +133,14 @@ module Peatio
126
133
  address_confirmation_webhook(url)
127
134
  end
128
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
+
129
144
  def fetch_transfer!(id)
130
145
  # TODO: Add Rspecs for this one
131
146
  response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}/transfer/#{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}",
@@ -251,9 +266,13 @@ module Peatio
251
266
  x.to_i
252
267
  end
253
268
 
269
+ def time_difference_in_minutes(updated_at)
270
+ (Time.now - updated_at)/60
271
+ end
272
+
254
273
  def define_transaction_state(state)
255
274
  case state
256
- when 'unconfrimed'
275
+ when 'unconfirmed'
257
276
  'pending'
258
277
  when 'confirmed'
259
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.3
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-07 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