peatio-coinpaymentnew 0.0.5 → 0.0.9
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 +4 -4
- data/lib/peatio/coinpaymentnew/client.rb +0 -30
- data/lib/peatio/coinpaymentnew/version.rb +1 -1
- data/lib/peatio/coinpaymentnew/wallet.rb +61 -140
- data/peatio-coinpaymentnew-0.0.5.gem +0 -0
- data/peatio-coinpaymentnew-0.0.6.gem +0 -0
- data/peatio-coinpaymentnew-0.0.7.gem +0 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fba2656c87b177ed9f41a2297a04f343bdaa29c9
|
4
|
+
data.tar.gz: 942adceca45cf5d1aadd0d31e957b32a3c88c73b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
@@ -27,60 +27,21 @@ module Peatio
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def create_address!(options = {})
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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[
|
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[
|
140
|
-
|
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'] == '
|
160
|
-
|
161
|
-
|
162
|
-
else
|
163
|
-
|
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'] == '
|
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
|
-
|
177
|
-
|
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
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
state
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
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
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
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
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
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
|
-
|
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
|
-
|
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.
|
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-
|
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:
|