peatio-coinpaymentnew 0.0.5 → 0.0.9

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
  SHA1:
3
- metadata.gz: 0a0842764cc5aac0fa320c966685b729d4132d5e
4
- data.tar.gz: f5aadac1423d0c5dbde96faa1fceb8101ec9eef8
3
+ metadata.gz: fba2656c87b177ed9f41a2297a04f343bdaa29c9
4
+ data.tar.gz: 942adceca45cf5d1aadd0d31e957b32a3c88c73b
5
5
  SHA512:
6
- metadata.gz: 491ec36d7ba9d862e6c2db3d6c89dcbe214a2c997021bd7d427c6ac2dcd8193b5767e9ac46273fb987743f649bc4d097e868d4c2ba2f405bbd1abc5b7c68852a
7
- data.tar.gz: 62e0cc7c60f2cdbbbe23d9c0316aeb90b844b478643d3622d6e448a36c6fa2b9b2b40766ce992a6935abe24da5c305902646df49202da590bb5d9852b1c9f7c8
6
+ metadata.gz: 79d32c8700361d9a72cd31075b65aebc452b752e83917b7c92024cbe414f08da86638fe6768da27d2c067f05fe7075092d2704157ea3cb02d0ffd3120707fc15
7
+ data.tar.gz: d8f5d1d4519a9b9434b0c9376b4cebef550c6e196510ee5c1bf2e5cceef0eba6cc1fafa1379e8c6dca17d44c2a1c7625a94f7ed96c37e6fc30fa46783e24e6f6
@@ -25,41 +25,11 @@ module Peatio
25
25
  { version: 1, key: @access_token }
26
26
  end
27
27
 
28
- # def rest_api(verb, path, data = nil)
29
28
  def rest_api(args)
30
- # args = [@endpoint.to_s + path]
31
-
32
- # if data
33
- # if %i[post put patch].include?(verb)
34
- # args << data.compact.to_json
35
- # args << { 'Content-Type' => 'application/json' }
36
- # else
37
- # args << data.compact
38
- # args << {}
39
- # end
40
- # else
41
- # args << nil
42
- # args << {}
43
- # end
44
29
  body = required_params.merge!(args)
45
- # args.last['Accept'] = 'application/json'
46
- # args.last['hmac'] = hmac(body)
47
-
48
- # body = required_params.merge!(cmd: caller[0][/`.*'/][1..-2]).merge!(args)
49
30
  response = HTTParty.post(@endpoint.to_s, body: body, headers: {'hmac' => hmac(body)})
50
31
  response['error'] == 'ok' ? Hashie::Mash.new(response['result']) : response['error']
51
32
 
52
- # response = Faraday.send(verb, *args)
53
- # response.assert_success!
54
- # response = JSON.parse(response.body)
55
- # response['error'].tap { |error| raise ResponseError.new(error) if error }
56
- # response
57
- rescue Faraday::Error => e
58
- if e.is_a?(Faraday::ConnectionFailed) || e.is_a?(Faraday::TimeoutError)
59
- raise ConnectionError, e
60
- else
61
- raise ConnectionError, JSON.parse(e.response.body)['message']
62
- end
63
33
  end
64
34
  end
65
35
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Peatio
4
4
  module Coinpaymentnew
5
- VERSION = "0.0.5"
5
+ VERSION = "0.0.9"
6
6
  end
7
7
  end
@@ -27,60 +27,21 @@ module Peatio
27
27
  end
28
28
 
29
29
  def create_address!(options = {})
30
- currency = erc20_currency_id
31
- options.deep_symbolize_keys!
32
-
33
- if options.dig(:pa_details, :address_id).present? &&
34
- options.dig(:pa_details, :updated_at).present? &&
35
- time_difference_in_minutes(options.dig(:pa_details, :updated_at)) >= TIME_DIFFERENCE_IN_MINUTES
36
- args = { cmd: 'get_deposit_address', currency: currency.code }.merge!(options)
37
- response = client.rest_api(args)
38
- { address: response['address'], secret: coinpayment_wallet_passphrase }
39
- elsif options.dig(:pa_details, :address_id).blank?
40
- args = { cmd: 'get_deposit_address', currency: currency.code }.merge!(options)
41
- response = client.rest_api(args)
42
- # response = client.rest_api(:post, "#{currency}/wallet/#{wallet_id}/address")
43
- { address: response['address'], secret: coinpayment_wallet_passphrase, details: { address_id: response['address'] }}
44
- end
45
- rescue Coinpayment::Client::Error => e
30
+ args = { cmd: 'get_callback_address', ipn_url: "https://v2app.rokes.exchange/api/v2/peatio/public/webhooks/deposit", currency: currency_id.upcase }
31
+ response = client.rest_api(args)
32
+ { address: response['address'] }
33
+ rescue Coinpaymentnew::Client::Error => e
46
34
  raise Peatio::Wallet::ClientError, e
47
35
  end
48
36
 
49
37
  def create_transaction!(transaction, options = {})
50
38
  currency_options = @currency.fetch(:options).slice(:gas_limit, :gas_price, :erc20_contract_address)
51
-
52
- # if currency_options[:gas_limit].present? && currency_options[:gas_price].present?
53
- # options.merge!(currency_options)
54
- # create_eth_transaction(transaction, options)
55
- # else
56
- amount = convert_to_base_unit(transaction.amount)
57
-
58
- # if options[:subtract_fee].to_s == 'true'
59
- # fee = build_raw_transaction(transaction)
60
- # baseFeeInfo = fee['tx_fee']
61
- # # fee = baseFeeInfo.present? ? baseFeeInfo : fee.dig('txInfo','Fee')
62
- # amount -= fee.to_i
63
- # end
64
-
65
- args = { cmd: "create_transaction", amount: amount, currency1: "USD", currency2: currency.code, buyer_email: "joshirockstar007@gmail.com", address: normalize_address(transaction.to_address.to_s) }
66
- response = client.rest_api(args)
67
- # response = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
68
- # address: normalize_address(transaction.to_address.to_s),
69
- # amount: amount.to_s,
70
- # walletPassphrase: coinpayment_wallet_passphrase,
71
- # memo: xlm_memo(transaction.to_address.to_s)
72
- # }.compact)
73
-
74
- if response['feeString'].present?
75
- fee = convert_from_base_unit(response['feeString'])
76
- transaction.fee = fee
77
- end
78
-
79
- transaction.hash = normalize_txid(response['txn_id'])
80
- transaction.fee_currency_id = erc20_currency_id
81
- transaction
82
- # end
83
- rescue Coinpayment::Client::Error => e
39
+ amount = convert_to_base_unit(transaction.amount)
40
+ args = { cmd: "create_transaction", amount: amount, currency1: "USD", currency2: currency_id.upcase, buyer_email: "joshirockstar007@gmail.com", address: normalize_address(transaction.to_address.to_s) }
41
+ response = client.rest_api(args)
42
+ transaction.hash = normalize_txid(response['txn_id'])
43
+ transactio
44
+ rescue Coinpaymentnew::Client::Error => e
84
45
  raise Peatio::Wallet::ClientError, e
85
46
  end
86
47
 
@@ -88,13 +49,7 @@ module Peatio
88
49
  def build_raw_transaction(transaction)
89
50
  args = { cmd: "rates" }
90
51
  response = client.rest_api(args)
91
- response[currency.code]
92
- # client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/tx/build", {
93
- # recipients: [{
94
- # address: transaction.to_address,
95
- # amount: convert_to_base_unit(transaction.amount).to_s
96
- # }]
97
- # }.compact)
52
+ response[currency_id.upcase]
98
53
  end
99
54
 
100
55
  # def create_eth_transaction(transaction, options = {})
@@ -136,14 +91,8 @@ module Peatio
136
91
  def load_balance!
137
92
  args = { cmd: "balances" }
138
93
  response = client.rest_api(args)
139
- response[currency.code]['balancef']
140
- # if @currency.fetch(:options).slice(:erc20_contract_address).present?
141
- # load_erc20_balance!
142
- # else
143
- # response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}")
144
- # convert_from_base_unit(response.fetch('balanceString'))
145
- # end
146
- rescue Coinpayment::Client::Error => e
94
+ response[currency_id.upcase]['balancef']
95
+ rescue Coinpaymentnew::Client::Error => e
147
96
  raise Peatio::Wallet::ClientError, e
148
97
  end
149
98
 
@@ -155,27 +104,24 @@ module Peatio
155
104
  # end
156
105
 
157
106
  def trigger_webhook_event(request)
158
- currency = @wallet.fetch(:testnet).present? ? 't' + @currency.fetch(:id) : @currency.fetch(:id)
159
- if request.params['ipn_type'] == 'transfer'
160
- return unless currency == request.params['coin'] &&
161
- @wallet.fetch(:wallet_id) == request.params['wallet']
162
- else
163
- return unless @wallet.fetch(:wallet_id) == request.params['walletId']
164
- end
107
+ # currency = @wallet.fetch(:testnet).present? ? 't' + @currency.fetch(:id) : @currency.fetch(:id)
108
+ # if request.params['ipn_type'] == 'deposit'
109
+ # return unless currency == request.params['coin'] &&
110
+ # @wallet.fetch(:wallet_id) == request.params['wallet']
111
+ # else
112
+ # return unless @wallet.fetch(:wallet_id) == request.params['walletId']
113
+ # end
165
114
 
166
- if request.params['ipn_type'] == 'transfer'
115
+ if request.params['ipn_type'] == 'deposit'
167
116
  transactions = fetch_transfer!(request.params['txn_id'])
168
117
  return transactions
169
- # elsif request.params['type'] == 'address_confirmation'
170
- # address_id = fetch_address_id(request.params['address'])
171
- # return { address_id: address_id, address: request.params['address'], currency_id: currency_id }
172
118
  end
173
119
  end
174
120
 
175
- def register_webhooks!(url)
176
- transfer_webhook(url)
177
- address_confirmation_webhook(url)
178
- end
121
+ # def register_webhooks!(url)
122
+ # transfer_webhook(url)
123
+ # address_confirmation_webhook(url)
124
+ # end
179
125
 
180
126
  # def fetch_address_id(address)
181
127
  # currency = erc20_currency_id
@@ -188,64 +134,43 @@ module Peatio
188
134
  def fetch_transfer!(id)
189
135
  args = { cmd: "get_tx_info", txid: id }
190
136
  response = client.rest_api(args)
191
- # response[currency.code]['balancef']
192
- # response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}/transfer/#{id}")
193
- # parse_entries(response['entries']).map do |entry|
194
- # to_address = if response.dig('coinSpecific', 'memo').present?
195
- # memo = response.dig('coinSpecific', 'memo')
196
- # memo_type = memo.kind_of?(Array) ? memo.first : memo
197
- # build_address(entry['address'], memo_type)
198
- # else
199
- # entry['address']
200
- # end
201
- state = define_transaction_state(response['status'])
202
-
203
- # if response['outputs'].present?
204
- # output = response['outputs'].find { |out| out['address'] == to_address }
205
- # txout = output['index'] if output.present?
206
- # end
207
-
208
- # if response['feeString'].present?
209
- # fee = convert_from_base_unit(response['feeString']) / response['entries'].count
210
- # end
211
-
212
- transaction = Peatio::Transaction.new(
213
- currency_id: @currency.fetch(:id),
214
- amount: convert_from_base_unit(response['amountf']),
215
- fee: 0,
216
- fee_currency_id: response["coin"],
217
- hash: normalize_txid(response['txid']),
218
- to_address: response["payment_address"],
219
- block_number: 0,
220
- txout: 0,
221
- status: state
222
- )
223
-
224
- transaction if transaction.valid?
225
- # end.compact
226
- rescue Coinpayment::Client::Error => e
137
+ state = define_transaction_state(response['status'])
138
+ transaction = Peatio::Transaction.new(
139
+ currency_id: @currency.fetch(:id),
140
+ amount: convert_from_base_unit(response['amountf']),
141
+ fee: 0,
142
+ fee_currency_id: response["coin"],
143
+ hash: normalize_txid(response['txid']),
144
+ to_address: response["payment_address"],
145
+ block_number: 0,
146
+ txout: 0,
147
+ status: state
148
+ )
149
+
150
+ transaction
151
+ rescue Coinpaymentnew::Client::Error => e
227
152
  raise Peatio::Wallet::ClientError, e
228
153
  end
229
154
 
230
- def transfer_webhook(url)
231
- client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
232
- type: 'transfer',
233
- allToken: true,
234
- url: url,
235
- label: "webhook for #{url}",
236
- listenToFailureStates: false
237
- })
238
- end
155
+ # def transfer_webhook(url)
156
+ # client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
157
+ # type: 'transfer',
158
+ # allToken: true,
159
+ # url: url,
160
+ # label: "webhook for #{url}",
161
+ # listenToFailureStates: false
162
+ # })
163
+ # end
239
164
 
240
- def address_confirmation_webhook(url)
241
- client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
242
- type: 'address_confirmation',
243
- allToken: true,
244
- url: url,
245
- label: "webhook for #{url}",
246
- listenToFailureStates: false
247
- })
248
- end
165
+ # def address_confirmation_webhook(url)
166
+ # client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
167
+ # type: 'address_confirmation',
168
+ # allToken: true,
169
+ # url: url,
170
+ # label: "webhook for #{url}",
171
+ # listenToFailureStates: false
172
+ # })
173
+ # end
249
174
 
250
175
  def parse_entries(entries)
251
176
  entries.map do |e|
@@ -253,15 +178,11 @@ module Peatio
253
178
  end.compact
254
179
  end
255
180
 
256
- private
257
-
258
181
  def client
259
182
  uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
260
183
  access_token = @wallet.fetch(:access_token) { raise Peatio::Wallet::MissingSettingError, :access_token }
261
184
  access_token2 = @wallet.fetch(:access_token2) { raise Peatio::Wallet::MissingSettingError, :access_token2 }
262
185
 
263
- currency_code_prefix = @wallet.fetch(:testnet) ? 't' : ''
264
- uri = uri.gsub(/\/+\z/, '') + '/' + currency_code_prefix
265
186
  @client ||= Client.new(uri, access_token, access_token2)
266
187
  end
267
188
 
@@ -325,7 +246,7 @@ module Peatio
325
246
 
326
247
  def convert_from_base_unit(value)
327
248
  value.to_d / @currency.fetch(:base_factor)
328
- endf
249
+ end
329
250
 
330
251
  def convert_to_base_unit(value)
331
252
  x = value.to_d * @currency.fetch(:base_factor)
@@ -342,9 +263,9 @@ module Peatio
342
263
  end
343
264
 
344
265
  def define_transaction_state(state)
345
- if state >= 100)
266
+ if state >= 100
346
267
  "success"
347
- if else state >= 0 && state <= 99
268
+ elsif state >= 0 and state <= 99
348
269
  'pending'
349
270
  else
350
271
  'failed'
Binary file
Binary file
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peatio-coinpaymentnew
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harishankar Joshi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-27 00:00:00.000000000 Z
11
+ date: 2021-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -215,6 +215,9 @@ files:
215
215
  - peatio-coinpaymentnew-0.0.2.gem
216
216
  - peatio-coinpaymentnew-0.0.3.gem
217
217
  - peatio-coinpaymentnew-0.0.4.gem
218
+ - peatio-coinpaymentnew-0.0.5.gem
219
+ - peatio-coinpaymentnew-0.0.6.gem
220
+ - peatio-coinpaymentnew-0.0.7.gem
218
221
  - peatio-coinpaymentnew.gemspec
219
222
  homepage: https://openware.com/
220
223
  licenses: