peatio-bitgo 2.6.2 → 2.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 863d387c7b57c73ce93ec4157f024f866ae5535605c4e65806b2becfe9251015
4
- data.tar.gz: 59513ea996a0a5fb87abe27492d8944b7ce2d8557a89f75814622f437b189ffd
3
+ metadata.gz: '062810d1807c29ab63130d8bb190de25c2cab3f482829e0abdff61cae4187422'
4
+ data.tar.gz: cb04bdf39f57405c46fb7903db410a55eb269bac1f19300422812c88ea052dae
5
5
  SHA512:
6
- metadata.gz: f9b4ea980fe2f0fa19c4f10991b3017d0e4cbff8273fe411c945d0a82004578ec1b12fd9d31f8081544a914509bd92d246083c36cd9444b75ab82f591f7a8cd8
7
- data.tar.gz: 2987a6430253bb2e6882980760f5a14423b102f47d8b3daa07d8daaa094c6ec41cfb443fe4fe39471a1be647855096608176d0caf547a2e41876ebe57c5c685f
6
+ metadata.gz: b40f51251f29accdcee17938e1dda4c74ccb362dd85664faf979366164f629d80b659de3bd01d95763b3f6629591a95d6fafc97e380ac1eff5f9b080e5b4560b
7
+ data.tar.gz: e2f7372b54ba702d1a845c80e4e3f85daa580c177bcfdcb65bfbbde27f1eeabafa1b8d321b63e91fac9b71c76311a07912d0af1db3be439ad75dc8f06a619154
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- peatio-bitgo (2.6.2)
4
+ peatio-bitgo (2.6.7)
5
5
  activesupport (~> 5.2.3)
6
6
  better-faraday (~> 1.0.5)
7
7
  faraday (~> 0.17)
@@ -12,35 +12,35 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- activemodel (5.2.4.3)
16
- activesupport (= 5.2.4.3)
17
- activesupport (5.2.4.3)
15
+ activemodel (5.2.4.4)
16
+ activesupport (= 5.2.4.4)
17
+ activesupport (5.2.4.4)
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.3)
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.5)
38
38
  cookiejar (0.3.3)
39
39
  crack (0.4.3)
40
40
  safe_yaml (~> 1.0.0)
41
- daemons (1.3.1)
42
- diff-lcs (1.3)
43
- em-http-request (1.1.6)
41
+ daemons (1.4.0)
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.17.3)
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.3.0)
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.3)
74
+ i18n (1.8.10)
75
75
  concurrent-ruby (~> 1.0)
76
- jwt (2.2.1)
76
+ jwt (2.2.3)
77
77
  memoist (0.16.2)
78
78
  method_source (1.0.0)
79
- minitest (5.14.1)
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.6.1)
86
+ peatio (2.6.3)
87
87
  activemodel (> 5.2, <= 6.0.0)
88
88
  amqp
89
89
  bunny
@@ -97,42 +97,42 @@ 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.2)
135
+ websocket-driver (0.7.3)
136
136
  websocket-extensions (>= 0.1.0)
137
137
  websocket-extensions (0.1.5)
138
138
 
@@ -1,5 +1,5 @@
1
1
  module Peatio
2
2
  module Bitgo
3
- VERSION = "2.6.2".freeze
3
+ VERSION = "2.6.7".freeze
4
4
  end
5
5
  end
@@ -2,6 +2,7 @@ module Peatio
2
2
  module Bitgo
3
3
  class Wallet < Peatio::Wallet::Abstract
4
4
  TIME_DIFFERENCE_IN_MINUTES = 10
5
+ XLM_MEMO_TYPES = { 'memoId': 'id', 'memoText': 'text', 'memoHash': 'hash', 'memoReturn': 'return' }
5
6
 
6
7
  DEFAULT_FEATURES = { skip_deposit_collection: false }.freeze
7
8
 
@@ -60,7 +61,7 @@ module Peatio
60
61
  end
61
62
 
62
63
  txid = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
63
- address: transaction.to_address.to_s,
64
+ address: normalize_address(transaction.to_address.to_s),
64
65
  amount: amount.to_s,
65
66
  walletPassphrase: bitgo_wallet_passphrase,
66
67
  memo: xlm_memo(transaction.to_address.to_s)
@@ -85,7 +86,15 @@ module Peatio
85
86
 
86
87
  def create_eth_transaction(transaction, options = {})
87
88
  amount = convert_to_base_unit(transaction.amount)
88
- hop = true unless options.slice(:erc20_contract_address).present?
89
+ hop = options.slice(:erc20_contract_address).present? ? false : true
90
+
91
+ fee_estimate = fee_estimate(amount.to_s, hop)
92
+
93
+ if transaction.options.present?
94
+ options[:gas_price] = transaction.options[:gas_price]
95
+ else
96
+ options[:gas_price] = fee_estimate['minGasPrice'].to_i
97
+ end
89
98
 
90
99
  txid = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
91
100
  address: transaction.to_address.to_s,
@@ -97,9 +106,14 @@ module Peatio
97
106
  }.compact).fetch('txid')
98
107
 
99
108
  transaction.hash = normalize_txid(txid)
109
+ transaction.options = options
100
110
  transaction
101
111
  end
102
112
 
113
+ def fee_estimate(amount, hop)
114
+ client.rest_api(:get, "#{erc20_currency_id}/tx/fee", {amount: amount, hop: hop})
115
+ end
116
+
103
117
  def load_balance!
104
118
  if @currency.fetch(:options).slice(:erc20_contract_address).present?
105
119
  load_erc20_balance!
@@ -118,16 +132,21 @@ module Peatio
118
132
  raise Peatio::Wallet::ClientError, e
119
133
  end
120
134
 
121
- def trigger_webhook_event(event)
135
+ def trigger_webhook_event(request)
122
136
  currency = @wallet.fetch(:testnet).present? ? 't' + @currency.fetch(:id) : @currency.fetch(:id)
123
- return unless currency == event['coin'] && @wallet.fetch(:wallet_id) == event['wallet']
124
-
125
- if event['type'] == 'transfer'
126
- transactions = fetch_transfer!(event['transfer'])
127
- return { transfers: transactions }
128
- elsif event['type'] == 'address_confirmation'
129
- address_id = fetch_address_id(event['address'])
130
- return { address_id: address_id, currency_id: currency_id }
137
+ if request.params['type'] == 'transfer'
138
+ return unless currency == request.params['coin'] &&
139
+ @wallet.fetch(:wallet_id) == request.params['wallet']
140
+ else
141
+ return unless @wallet.fetch(:wallet_id) == request.params['walletId']
142
+ end
143
+
144
+ if request.params['type'] == 'transfer'
145
+ transactions = fetch_transfer!(request.params['transfer'])
146
+ return transactions
147
+ elsif request.params['type'] == 'address_confirmation'
148
+ address_id = fetch_address_id(request.params['address'])
149
+ return { address_id: address_id, address: request.params['address'], currency_id: currency_id }
131
150
  end
132
151
  end
133
152
 
@@ -145,7 +164,6 @@ module Peatio
145
164
  end
146
165
 
147
166
  def fetch_transfer!(id)
148
- # TODO: Add Rspecs for this one
149
167
  response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}/transfer/#{id}")
150
168
  parse_entries(response['entries']).map do |entry|
151
169
  to_address = if response.dig('coinSpecific', 'memo').present?
@@ -157,14 +175,18 @@ module Peatio
157
175
  end
158
176
  state = define_transaction_state(response['state'])
159
177
 
178
+ if response['outputs'].present?
179
+ output = response['outputs'].find { |out| out['address'] == to_address }
180
+ txout = output['index'] if output.present?
181
+ end
182
+
160
183
  transaction = Peatio::Transaction.new(
161
184
  currency_id: @currency.fetch(:id),
162
185
  amount: convert_from_base_unit(entry['valueString']),
163
186
  hash: normalize_txid(response['txid']),
164
187
  to_address: to_address,
165
188
  block_number: response['height'],
166
- # TODO: Add sendmany support
167
- txout: 0,
189
+ txout: txout.to_i,
168
190
  status: state
169
191
  )
170
192
 
@@ -224,19 +246,25 @@ module Peatio
224
246
  end
225
247
 
226
248
  def xlm_memo(address)
227
- if @currency.fetch(:id) == 'xlm'
228
- {
229
- type: "id",
230
- value: "#{memo_id_from(address)}"
231
- }
232
- end
249
+ build_xlm_memo(address) if @currency.fetch(:id) == 'xlm'
233
250
  end
234
251
 
235
- def memo_id_from(address)
236
- memo_id = address.partition('memoId=').last
237
- memo_id = 0 if memo_id.empty?
252
+ def build_xlm_memo(address)
253
+ case address.split('?').last.split('=').first
254
+ when 'memoId'
255
+ memo_value_from(address, 'memoId')
256
+ when 'memoText'
257
+ memo_value_from(address, 'memoText')
258
+ when 'memoHash'
259
+ memo_value_from(address, 'memoHash')
260
+ when 'memoReturn'
261
+ memo_value_from(address, 'memoReturn')
262
+ end
263
+ end
238
264
 
239
- memo_id
265
+ def memo_value_from(address, type)
266
+ memo_value = address.partition(type + '=').last
267
+ return { type: XLM_MEMO_TYPES[type.to_sym], value: memo_value } if memo_value.present?
240
268
  end
241
269
 
242
270
  def currency_id
@@ -251,6 +279,14 @@ module Peatio
251
279
  @wallet.fetch(:wallet_id)
252
280
  end
253
281
 
282
+ def normalize_address(address)
283
+ if @currency.fetch(:id) == 'xlm'
284
+ address.split('?').first
285
+ else
286
+ address
287
+ end
288
+ end
289
+
254
290
  def normalize_txid(txid)
255
291
  txid.downcase
256
292
  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: 2.6.2
4
+ version: 2.6.7
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-06-10 00:00:00.000000000 Z
11
+ date: 2021-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  - !ruby/object:Gem::Version
240
240
  version: '0'
241
241
  requirements: []
242
- rubygems_version: 3.0.3
242
+ rubygems_version: 3.0.3.1
243
243
  signing_key:
244
244
  specification_version: 4
245
245
  summary: Gem for extending Peatio plugable system with Bitgo implementation.