peatio-coinpaymentnew 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- 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 +54 -128
- 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 +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89cb0e3405cea75e5abcd3aa418743b6779b0673
|
4
|
+
data.tar.gz: 50491be28e5d7f2b96f038696175a23d2df3862d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61a1d5a62f4698313b97f6182042403bf398c937bbe15a2d2ff32d73cc622597e945fc5d9636e53a0a3ea235fe04648bf0576fdb8124e4014fe66a5c6b38edbd
|
7
|
+
data.tar.gz: 2df07c66ee90855ecdf4b91585fbc124a0f20ece5faa50b99af4408c2c1e3a3a9e62d3ecebe1e326a48132ec9edacae625d278ddfca36793458f58f445d13c48
|
@@ -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
|
@@ -30,56 +30,20 @@ module Peatio
|
|
30
30
|
currency = erc20_currency_id
|
31
31
|
options.deep_symbolize_keys!
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
33
|
+
args = { cmd: 'get_deposit_address', currency: currency.upcase }.merge!(options)
|
34
|
+
response = client.rest_api(args)
|
35
|
+
{ address: response['address'] }
|
45
36
|
rescue Coinpayment::Client::Error => e
|
46
37
|
raise Peatio::Wallet::ClientError, e
|
47
38
|
end
|
48
39
|
|
49
40
|
def create_transaction!(transaction, options = {})
|
50
41
|
currency_options = @currency.fetch(:options).slice(:gas_limit, :gas_price, :erc20_contract_address)
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
42
|
+
amount = convert_to_base_unit(transaction.amount)
|
43
|
+
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) }
|
44
|
+
response = client.rest_api(args)
|
45
|
+
transaction.hash = normalize_txid(response['txn_id'])
|
46
|
+
transactio
|
83
47
|
rescue Coinpayment::Client::Error => e
|
84
48
|
raise Peatio::Wallet::ClientError, e
|
85
49
|
end
|
@@ -88,13 +52,7 @@ module Peatio
|
|
88
52
|
def build_raw_transaction(transaction)
|
89
53
|
args = { cmd: "rates" }
|
90
54
|
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)
|
55
|
+
response[currency_id.upcase]
|
98
56
|
end
|
99
57
|
|
100
58
|
# def create_eth_transaction(transaction, options = {})
|
@@ -136,13 +94,7 @@ module Peatio
|
|
136
94
|
def load_balance!
|
137
95
|
args = { cmd: "balances" }
|
138
96
|
response = client.rest_api(args)
|
139
|
-
response[
|
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
|
97
|
+
response[currency_id.upcase]['balancef']
|
146
98
|
rescue Coinpayment::Client::Error => e
|
147
99
|
raise Peatio::Wallet::ClientError, e
|
148
100
|
end
|
@@ -155,27 +107,24 @@ module Peatio
|
|
155
107
|
# end
|
156
108
|
|
157
109
|
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
|
110
|
+
# currency = @wallet.fetch(:testnet).present? ? 't' + @currency.fetch(:id) : @currency.fetch(:id)
|
111
|
+
# if request.params['ipn_type'] == 'deposit'
|
112
|
+
# return unless currency == request.params['coin'] &&
|
113
|
+
# @wallet.fetch(:wallet_id) == request.params['wallet']
|
114
|
+
# else
|
115
|
+
# return unless @wallet.fetch(:wallet_id) == request.params['walletId']
|
116
|
+
# end
|
165
117
|
|
166
|
-
if request.params['ipn_type'] == '
|
118
|
+
if request.params['ipn_type'] == 'deposit'
|
167
119
|
transactions = fetch_transfer!(request.params['txn_id'])
|
168
120
|
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
121
|
end
|
173
122
|
end
|
174
123
|
|
175
|
-
def register_webhooks!(url)
|
176
|
-
|
177
|
-
|
178
|
-
end
|
124
|
+
# def register_webhooks!(url)
|
125
|
+
# transfer_webhook(url)
|
126
|
+
# address_confirmation_webhook(url)
|
127
|
+
# end
|
179
128
|
|
180
129
|
# def fetch_address_id(address)
|
181
130
|
# currency = erc20_currency_id
|
@@ -188,64 +137,43 @@ module Peatio
|
|
188
137
|
def fetch_transfer!(id)
|
189
138
|
args = { cmd: "get_tx_info", txid: id }
|
190
139
|
response = client.rest_api(args)
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
state
|
202
|
-
|
203
|
-
|
204
|
-
|
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
|
140
|
+
state = define_transaction_state(response['status'])
|
141
|
+
transaction = Peatio::Transaction.new(
|
142
|
+
currency_id: @currency.fetch(:id),
|
143
|
+
amount: convert_from_base_unit(response['amountf']),
|
144
|
+
fee: 0,
|
145
|
+
fee_currency_id: response["coin"],
|
146
|
+
hash: normalize_txid(response['txid']),
|
147
|
+
to_address: response["payment_address"],
|
148
|
+
block_number: 0,
|
149
|
+
txout: 0,
|
150
|
+
status: state
|
151
|
+
)
|
152
|
+
|
153
|
+
transaction
|
226
154
|
rescue Coinpayment::Client::Error => e
|
227
155
|
raise Peatio::Wallet::ClientError, e
|
228
156
|
end
|
229
157
|
|
230
|
-
def transfer_webhook(url)
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
end
|
158
|
+
# def transfer_webhook(url)
|
159
|
+
# client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
|
160
|
+
# type: 'transfer',
|
161
|
+
# allToken: true,
|
162
|
+
# url: url,
|
163
|
+
# label: "webhook for #{url}",
|
164
|
+
# listenToFailureStates: false
|
165
|
+
# })
|
166
|
+
# end
|
239
167
|
|
240
|
-
def address_confirmation_webhook(url)
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
end
|
168
|
+
# def address_confirmation_webhook(url)
|
169
|
+
# client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
|
170
|
+
# type: 'address_confirmation',
|
171
|
+
# allToken: true,
|
172
|
+
# url: url,
|
173
|
+
# label: "webhook for #{url}",
|
174
|
+
# listenToFailureStates: false
|
175
|
+
# })
|
176
|
+
# end
|
249
177
|
|
250
178
|
def parse_entries(entries)
|
251
179
|
entries.map do |e|
|
@@ -258,8 +186,6 @@ module Peatio
|
|
258
186
|
access_token = @wallet.fetch(:access_token) { raise Peatio::Wallet::MissingSettingError, :access_token }
|
259
187
|
access_token2 = @wallet.fetch(:access_token2) { raise Peatio::Wallet::MissingSettingError, :access_token2 }
|
260
188
|
|
261
|
-
currency_code_prefix = @wallet.fetch(:testnet) ? 't' : ''
|
262
|
-
uri = uri.gsub(/\/+\z/, '') + '/' + currency_code_prefix
|
263
189
|
@client ||= Client.new(uri, access_token, access_token2)
|
264
190
|
end
|
265
191
|
|
Binary file
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harishankar Joshi
|
@@ -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:
|