peatio-coinpaymentnew 0.0.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +1 -1
- data/Gemfile.lock +14 -54
- data/config/initializers/coinpayments.rb +6 -0
- data/lib/peatio/coinpaymentnew/hooks.rb +1 -1
- data/lib/peatio/coinpaymentnew/version.rb +1 -1
- data/lib/peatio/coinpaymentnew/wallet.rb +152 -83
- data/lib/peatio/coinpaymentnew/walletApi.rb +41 -0
- data/lib/peatio/coinpaymentnew.rb +1 -1
- data/peatio-coinpaymentnew.gemspec +6 -8
- metadata +15 -36
- data/lib/peatio/coinpaymentnew/client.rb +0 -37
- data/peatio-coinpaymentnew-0.0.2.gem +0 -0
- data/peatio-coinpaymentnew-0.0.3.gem +0 -0
- data/peatio-coinpaymentnew-0.0.4.gem +0 -0
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 338317e409dd01b8c1da60ad97488200c0a5d4ff3f13d4cd15bb244e945cc4e0
|
4
|
+
data.tar.gz: ddf5d03db1d83449a02e9ca5f16a67fb08ca7df3647a105e1d9b7dab5585e6e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57cecc9b92c9aee512c78076e8c8648528a1e218f141b34f76495336b7047499530934ccfba0e262d87e8a9711b8ac75e6dab75695051c468911e4845908a194
|
7
|
+
data.tar.gz: 4f7ade2babf3da510839972fa65bd7b3f42d36d198503976551515ba39dddd2f0e22e7667e9fb6c2d390013e08a4fb87394e777fea984bf8a38bde944df09cc4
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
peatio-coinpaymentnew (0.0
|
4
|
+
peatio-coinpaymentnew (1.0.0)
|
5
5
|
activesupport (~> 5.2.3)
|
6
6
|
better-faraday (~> 1.0.5)
|
7
|
-
|
8
|
-
faraday (~> 0.17)
|
7
|
+
faraday (~> 0.15.4)
|
9
8
|
memoist (~> 0.16.0)
|
10
|
-
peatio (~>
|
9
|
+
peatio (~> 0.6.1)
|
11
10
|
|
12
11
|
GEM
|
13
12
|
remote: https://rubygems.org/
|
@@ -38,47 +37,22 @@ GEM
|
|
38
37
|
hashie
|
39
38
|
httparty
|
40
39
|
concurrent-ruby (1.1.9)
|
41
|
-
cookiejar (0.3.3)
|
42
40
|
crack (0.4.5)
|
43
41
|
rexml
|
44
|
-
daemons (1.4.1)
|
45
42
|
diff-lcs (1.4.4)
|
46
|
-
em-
|
47
|
-
addressable (>= 2.3.4)
|
48
|
-
cookiejar (!= 0.3.1)
|
49
|
-
em-socksify (>= 0.3)
|
50
|
-
eventmachine (>= 1.0.3)
|
51
|
-
http_parser.rb (>= 0.6.0)
|
52
|
-
em-socksify (0.3.2)
|
53
|
-
eventmachine (>= 1.0.0.beta.4)
|
54
|
-
em-synchrony (1.0.6)
|
55
|
-
eventmachine (>= 1.0.0.beta.1)
|
56
|
-
em-websocket (0.5.3)
|
43
|
+
em-websocket (0.5.2)
|
57
44
|
eventmachine (>= 0.12.9)
|
58
|
-
http_parser.rb (~> 0)
|
45
|
+
http_parser.rb (~> 0.6.0)
|
59
46
|
eventmachine (1.2.7-x64-mingw32)
|
60
|
-
faraday (0.
|
47
|
+
faraday (0.15.4)
|
61
48
|
multipart-post (>= 1.2, < 3)
|
62
|
-
faraday_middleware (0.13.1)
|
63
|
-
faraday (>= 0.7.4, < 1.0)
|
64
|
-
faye (1.4.0)
|
65
|
-
cookiejar (>= 0.3.0)
|
66
|
-
em-http-request (>= 1.1.6)
|
67
|
-
eventmachine (>= 0.12.0)
|
68
|
-
faye-websocket (>= 0.11.0)
|
69
|
-
multi_json (>= 1.0.0)
|
70
|
-
rack (>= 1.0.0)
|
71
|
-
websocket-driver (>= 0.5.1)
|
72
|
-
faye-websocket (0.11.1)
|
73
|
-
eventmachine (>= 0.12.0)
|
74
|
-
websocket-driver (>= 0.5.1)
|
75
49
|
hashdiff (1.0.1)
|
76
50
|
hashie (4.1.0)
|
77
|
-
http_parser.rb (0.
|
51
|
+
http_parser.rb (0.6.0)
|
78
52
|
httparty (0.20.0)
|
79
53
|
mime-types (~> 3.0)
|
80
54
|
multi_xml (>= 0.5.2)
|
81
|
-
i18n (1.8.
|
55
|
+
i18n (1.8.10)
|
82
56
|
concurrent-ruby (~> 1.0)
|
83
57
|
jwt (2.3.0)
|
84
58
|
memoist (0.16.2)
|
@@ -88,25 +62,18 @@ GEM
|
|
88
62
|
mime-types-data (3.2021.0901)
|
89
63
|
minitest (5.14.4)
|
90
64
|
mocha (1.13.0)
|
91
|
-
multi_json (1.15.0)
|
92
65
|
multi_xml (0.6.0)
|
93
66
|
multipart-post (2.1.1)
|
94
67
|
mysql2 (0.5.3-x64-mingw32)
|
95
|
-
peatio (
|
68
|
+
peatio (0.6.3)
|
96
69
|
activemodel (> 5.2, <= 6.0.0)
|
97
70
|
amqp
|
98
71
|
bunny
|
99
72
|
clamp
|
100
|
-
em-synchrony (~> 1.0)
|
101
73
|
em-websocket
|
102
74
|
eventmachine
|
103
|
-
faraday_middleware (~> 0.13.1)
|
104
|
-
faye (~> 1.2)
|
105
75
|
jwt
|
106
76
|
mysql2
|
107
|
-
prometheus-client
|
108
|
-
thin
|
109
|
-
prometheus-client (2.1.0)
|
110
77
|
pry (0.13.1)
|
111
78
|
coderay (~> 1.1)
|
112
79
|
method_source (~> 1.0)
|
@@ -114,8 +81,7 @@ GEM
|
|
114
81
|
byebug (~> 11.0)
|
115
82
|
pry (~> 0.13.0)
|
116
83
|
public_suffix (4.0.6)
|
117
|
-
|
118
|
-
rake (13.0.6)
|
84
|
+
rake (10.5.0)
|
119
85
|
rbtree (0.4.4)
|
120
86
|
rexml (3.2.5)
|
121
87
|
rspec (3.10.0)
|
@@ -131,14 +97,10 @@ GEM
|
|
131
97
|
diff-lcs (>= 1.2.0, < 2.0)
|
132
98
|
rspec-support (~> 3.10.0)
|
133
99
|
rspec-support (3.10.2)
|
134
|
-
set (1.0.
|
100
|
+
set (1.0.1)
|
135
101
|
sorted_set (1.0.3)
|
136
102
|
rbtree
|
137
103
|
set (~> 1.0)
|
138
|
-
thin (1.8.1)
|
139
|
-
daemons (~> 1.0, >= 1.0.9)
|
140
|
-
eventmachine (~> 1.0, >= 1.0.4)
|
141
|
-
rack (>= 1, < 3)
|
142
104
|
thread_safe (0.3.6)
|
143
105
|
tzinfo (1.2.9)
|
144
106
|
thread_safe (~> 0.1)
|
@@ -146,21 +108,19 @@ GEM
|
|
146
108
|
addressable (>= 2.8.0)
|
147
109
|
crack (>= 0.3.2)
|
148
110
|
hashdiff (>= 0.4.0, < 2.0.0)
|
149
|
-
websocket-driver (0.7.5)
|
150
|
-
websocket-extensions (>= 0.1.0)
|
151
|
-
websocket-extensions (0.1.5)
|
152
111
|
|
153
112
|
PLATFORMS
|
154
113
|
x64-mingw32
|
155
114
|
|
156
115
|
DEPENDENCIES
|
157
116
|
bundler (~> 1.16)
|
117
|
+
coinpayments
|
158
118
|
mocha (~> 1.8)
|
159
119
|
peatio-coinpaymentnew!
|
160
120
|
pry-byebug
|
161
|
-
rake (~>
|
121
|
+
rake (~> 10.0)
|
162
122
|
rspec (~> 3.0)
|
163
123
|
webmock (~> 3.5)
|
164
124
|
|
165
125
|
BUNDLED WITH
|
166
|
-
1.17.
|
126
|
+
1.17.2
|
@@ -0,0 +1,6 @@
|
|
1
|
+
Coinpayments.configure do |config|
|
2
|
+
config.merchant_id = '81584a734276162e589fb2a5c19d1114'
|
3
|
+
config.public_api_key = '1c68e7c5cd7f03d79325bc63e2985d3dc604847242a22d682673f531af4cadcb'
|
4
|
+
config.private_api_key = '13F4855BFDa330B43063F07961CA373CfF3bb141d8ccCdF83B5e92ac2ad0f78b'
|
5
|
+
config.secret_phrase = '@hari123'
|
6
|
+
end
|
@@ -27,7 +27,7 @@ module Peatio
|
|
27
27
|
|
28
28
|
def register
|
29
29
|
Peatio::Blockchain.registry[:coinpaymentnew] = Coinpaymentnew::Blockchain
|
30
|
-
Peatio::Wallet.registry[:
|
30
|
+
Peatio::Wallet.registry[:coinpaymentnewd] = Coinpaymentnew::Wallet
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -2,7 +2,7 @@ module Peatio
|
|
2
2
|
module Coinpaymentnew
|
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
|
+
# XLM_MEMO_TYPES = { 'memoId': 'id', 'memoText': 'text', 'memoHash': 'hash', 'memoReturn': 'return' }
|
6
6
|
|
7
7
|
DEFAULT_FEATURES = { skip_deposit_collection: false }.freeze
|
8
8
|
|
@@ -19,7 +19,7 @@ module Peatio
|
|
19
19
|
|
20
20
|
@wallet = @settings.fetch(:wallet) do
|
21
21
|
raise Peatio::Wallet::MissingSettingError, :wallet
|
22
|
-
end.slice(:uri, :address, :secret, :access_token, :
|
22
|
+
end.slice(:uri, :address, :secret, :access_token, :wallet_id, :testnet)
|
23
23
|
|
24
24
|
@currency = @settings.fetch(:currency) do
|
25
25
|
raise Peatio::Wallet::MissingSettingError, :currency
|
@@ -27,71 +27,115 @@ module Peatio
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def create_address!(options = {})
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
currency = erc20_currency_id
|
31
|
+
options.deep_symbolize_keys!
|
32
|
+
response = WalletApi.get_deposit_address(currency.upcase)
|
33
|
+
{ address: response[:address], secret: coinpayment_wallet_passphrase, details: { address_id: response[:address] }}
|
34
|
+
# if options.dig(:pa_details, :address_id).present? &&
|
35
|
+
# options.dig(:pa_details, :updated_at).present? &&
|
36
|
+
# time_difference_in_minutes(options.dig(:pa_details, :updated_at)) >= TIME_DIFFERENCE_IN_MINUTES
|
37
|
+
#
|
38
|
+
# response = client.rest_api(:get, "#{currency}/wallet/#{wallet_id}/address/#{options.dig(:pa_details, :address_id)}")
|
39
|
+
# { address: response['address'], secret: bitgo_wallet_passphrase }
|
40
|
+
# elsif options.dig(:pa_details, :address_id).blank?
|
41
|
+
# response = client.rest_api(:post, "#{currency}/wallet/#{wallet_id}/address")
|
42
|
+
# { address: response['address'], secret: bitgo_wallet_passphrase, details: { address_id: response['id'] }}
|
43
|
+
# end
|
33
44
|
rescue Coinpaymentnew::Client::Error => e
|
34
45
|
raise Peatio::Wallet::ClientError, e
|
35
46
|
end
|
36
47
|
|
37
48
|
def create_transaction!(transaction, options = {})
|
38
49
|
currency_options = @currency.fetch(:options).slice(:gas_limit, :gas_price, :erc20_contract_address)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
transaction
|
43
|
-
|
50
|
+
|
51
|
+
# if currency_options[:gas_limit].present? && currency_options[:gas_price].present?
|
52
|
+
# options.merge!(currency_options)
|
53
|
+
# create_eth_transaction(transaction, options)
|
54
|
+
# else
|
55
|
+
amount = convert_to_base_unit(transaction.amount)
|
56
|
+
|
57
|
+
# if options[:subtract_fee].to_s == 'true'
|
58
|
+
# fee = build_raw_transaction(transaction)
|
59
|
+
# baseFeeInfo = fee.dig('feeInfo','fee')
|
60
|
+
# fee = baseFeeInfo.present? ? baseFeeInfo : fee.dig('txInfo','Fee')
|
61
|
+
# amount -= fee.to_i
|
62
|
+
# end
|
63
|
+
response = WalletApi.createTransaction(transaction.amount.to_s, "USD",currency_id.upcase, transaction.to_address.to_s)
|
64
|
+
# response = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
|
65
|
+
# address: normalize_address(transaction.to_address.to_s),
|
66
|
+
# amount: amount.to_s,
|
67
|
+
# walletPassphrase: bitgo_wallet_passphrase,
|
68
|
+
# memo: xlm_memo(transaction.to_address.to_s)
|
69
|
+
# }.compact)
|
70
|
+
#
|
71
|
+
# if response['feeString'].present?
|
72
|
+
# fee = convert_from_base_unit(response['feeString'])
|
73
|
+
# transaction.fee = fee
|
74
|
+
# end
|
75
|
+
|
76
|
+
transaction.hash = normalize_txid(response[:txn_id])
|
77
|
+
transaction.fee_currency_id = erc20_currency_id
|
78
|
+
transaction
|
79
|
+
# end
|
44
80
|
rescue Coinpaymentnew::Client::Error => e
|
45
81
|
raise Peatio::Wallet::ClientError, e
|
46
82
|
end
|
47
83
|
|
48
|
-
|
49
|
-
def build_raw_transaction(transaction)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
84
|
+
#
|
85
|
+
# def build_raw_transaction(transaction)
|
86
|
+
# client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/tx/build", {
|
87
|
+
# recipients: [{
|
88
|
+
# address: transaction.to_address,
|
89
|
+
# amount: convert_to_base_unit(transaction.amount).to_s
|
90
|
+
# }]
|
91
|
+
# }.compact)
|
92
|
+
# end
|
54
93
|
|
55
94
|
# def create_eth_transaction(transaction, options = {})
|
56
95
|
# amount = convert_to_base_unit(transaction.amount)
|
57
96
|
# hop = true unless options.slice(:gas_price).present?
|
58
|
-
|
97
|
+
#
|
59
98
|
# fee_estimate = fee_estimate(amount.to_s, hop)
|
60
|
-
|
99
|
+
#
|
61
100
|
# if transaction.options.present? && transaction.options[:gas_price].present?
|
62
101
|
# options[:gas_price] = transaction.options[:gas_price]
|
63
102
|
# else
|
64
103
|
# options[:gas_price] = fee_estimate['minGasPrice'].to_i
|
65
104
|
# end
|
66
|
-
|
105
|
+
#
|
67
106
|
# response = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
|
68
107
|
# address: transaction.to_address.to_s,
|
69
108
|
# amount: amount.to_s,
|
70
|
-
# walletPassphrase:
|
109
|
+
# walletPassphrase: bitgo_wallet_passphrase,
|
71
110
|
# gas: options.fetch(:gas_limit).to_i,
|
72
111
|
# gasPrice: options.fetch(:gas_price).to_i,
|
73
112
|
# hop: hop
|
74
113
|
# }.compact)
|
75
|
-
|
114
|
+
#
|
76
115
|
# if response['feeString'].present?
|
77
116
|
# fee = convert_from_base_unit(response['feeString'])
|
78
117
|
# transaction.fee = fee
|
79
118
|
# end
|
80
|
-
|
119
|
+
#
|
81
120
|
# transaction.hash = normalize_txid(response['txid'])
|
82
121
|
# transaction.fee_currency_id = erc20_currency_id
|
83
122
|
# transaction.options = options
|
84
123
|
# transaction
|
85
124
|
# end
|
86
125
|
|
87
|
-
|
88
|
-
|
89
|
-
|
126
|
+
def fee_estimate(amount, hop)
|
127
|
+
client.rest_api(:get, "#{erc20_currency_id}/tx/fee", { amount: amount, hop: hop }.compact)
|
128
|
+
end
|
90
129
|
|
91
130
|
def load_balance!
|
92
|
-
|
93
|
-
|
94
|
-
|
131
|
+
# if @currency.fetch(:options).slice(:erc20_contract_address).present?
|
132
|
+
# load_erc20_balance!
|
133
|
+
# else
|
134
|
+
# response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}")
|
135
|
+
response = WalletApi.balance
|
136
|
+
response = response.fetch(currency_id)
|
137
|
+
convert_from_base_unit(response["balance"])
|
138
|
+
# end
|
95
139
|
rescue Coinpaymentnew::Client::Error => e
|
96
140
|
raise Peatio::Wallet::ClientError, e
|
97
141
|
end
|
@@ -99,78 +143,99 @@ module Peatio
|
|
99
143
|
# def load_erc20_balance!
|
100
144
|
# response = client.rest_api(:get, "#{erc20_currency_id}/wallet/#{wallet_id}?allTokens=true")
|
101
145
|
# convert_from_base_unit(response.dig('tokens', currency_id, 'balanceString'))
|
102
|
-
# rescue
|
146
|
+
# rescue Coinpaymentnew::Client::Error => e
|
103
147
|
# raise Peatio::Wallet::ClientError, e
|
104
148
|
# end
|
105
149
|
|
106
150
|
def trigger_webhook_event(request)
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
151
|
+
currency = @wallet.fetch(:testnet).present? ? 't' + @currency.fetch(:id) : @currency.fetch(:id)
|
152
|
+
if request.params['type'] == 'transfer'
|
153
|
+
return unless currency == request.params['coin'] &&
|
154
|
+
@wallet.fetch(:wallet_id) == request.params['wallet']
|
155
|
+
else
|
156
|
+
return unless @wallet.fetch(:wallet_id) == request.params['walletId']
|
157
|
+
end
|
114
158
|
|
115
|
-
if request.params['
|
116
|
-
transactions = fetch_transfer!(request.params['
|
159
|
+
if request.params['type'] == 'transfer'
|
160
|
+
transactions = fetch_transfer!(request.params['transfer'])
|
117
161
|
return transactions
|
162
|
+
elsif request.params['type'] == 'address_confirmation'
|
163
|
+
address_id = fetch_address_id(request.params['address'])
|
164
|
+
return { address_id: address_id, address: request.params['address'], currency_id: currency_id }
|
118
165
|
end
|
119
166
|
end
|
120
167
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
168
|
+
def register_webhooks!(url)
|
169
|
+
transfer_webhook(url)
|
170
|
+
address_confirmation_webhook(url)
|
171
|
+
end
|
125
172
|
|
126
173
|
# def fetch_address_id(address)
|
127
174
|
# currency = erc20_currency_id
|
128
175
|
# client.rest_api(:get, "#{currency}/wallet/#{wallet_id}/address/#{address}")
|
129
176
|
# .fetch('id')
|
130
|
-
# rescue
|
177
|
+
# rescue Coinpaymentnew::Client::Error => e
|
131
178
|
# raise Peatio::Wallet::ClientError, e
|
132
179
|
# end
|
133
180
|
|
134
181
|
def fetch_transfer!(id)
|
135
|
-
|
136
|
-
response
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
182
|
+
response = client.rest_api(:get, "#{currency_id}/wallet/#{wallet_id}/transfer/#{id}")
|
183
|
+
parse_entries(response['entries']).map do |entry|
|
184
|
+
to_address = if response.dig('coinSpecific', 'memo').present?
|
185
|
+
memo = response.dig('coinSpecific', 'memo')
|
186
|
+
memo_type = memo.kind_of?(Array) ? memo.first : memo
|
187
|
+
build_address(entry['address'], memo_type)
|
188
|
+
else
|
189
|
+
entry['address']
|
190
|
+
end
|
191
|
+
state = define_transaction_state(response['state'])
|
192
|
+
|
193
|
+
if response['outputs'].present?
|
194
|
+
output = response['outputs'].find { |out| out['address'] == to_address }
|
195
|
+
txout = output['index'] if output.present?
|
196
|
+
end
|
197
|
+
|
198
|
+
if response['feeString'].present?
|
199
|
+
fee = convert_from_base_unit(response['feeString']) / response['entries'].count
|
200
|
+
end
|
201
|
+
|
202
|
+
transaction = Peatio::Transaction.new(
|
203
|
+
currency_id: @currency.fetch(:id),
|
204
|
+
amount: convert_from_base_unit(entry['valueString']),
|
205
|
+
fee: fee,
|
206
|
+
fee_currency_id: erc20_currency_id,
|
207
|
+
hash: normalize_txid(response['txid']),
|
208
|
+
to_address: to_address,
|
209
|
+
block_number: response['height'],
|
210
|
+
txout: txout.to_i,
|
211
|
+
status: state
|
212
|
+
)
|
213
|
+
|
214
|
+
transaction if transaction.valid?
|
215
|
+
end.compact
|
151
216
|
rescue Coinpaymentnew::Client::Error => e
|
152
217
|
raise Peatio::Wallet::ClientError, e
|
153
218
|
end
|
154
219
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
220
|
+
def transfer_webhook(url)
|
221
|
+
client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
|
222
|
+
type: 'transfer',
|
223
|
+
allToken: true,
|
224
|
+
url: url,
|
225
|
+
label: "webhook for #{url}",
|
226
|
+
listenToFailureStates: false
|
227
|
+
})
|
228
|
+
end
|
164
229
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
230
|
+
def address_confirmation_webhook(url)
|
231
|
+
client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/webhooks", {
|
232
|
+
type: 'address_confirmation',
|
233
|
+
allToken: true,
|
234
|
+
url: url,
|
235
|
+
label: "webhook for #{url}",
|
236
|
+
listenToFailureStates: false
|
237
|
+
})
|
238
|
+
end
|
174
239
|
|
175
240
|
def parse_entries(entries)
|
176
241
|
entries.map do |e|
|
@@ -178,12 +243,15 @@ module Peatio
|
|
178
243
|
end.compact
|
179
244
|
end
|
180
245
|
|
246
|
+
private
|
247
|
+
|
181
248
|
def client
|
182
249
|
uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
|
183
250
|
access_token = @wallet.fetch(:access_token) { raise Peatio::Wallet::MissingSettingError, :access_token }
|
184
|
-
access_token2 = @wallet.fetch(:access_token2) { raise Peatio::Wallet::MissingSettingError, :access_token2 }
|
185
251
|
|
186
|
-
|
252
|
+
currency_code_prefix = @wallet.fetch(:testnet) ? 't' : ''
|
253
|
+
uri = uri.gsub(/\/+\z/, '') + '/' + currency_code_prefix
|
254
|
+
@client ||= Client.new(uri, access_token)
|
187
255
|
end
|
188
256
|
|
189
257
|
def build_address(address, memo)
|
@@ -263,11 +331,12 @@ module Peatio
|
|
263
331
|
end
|
264
332
|
|
265
333
|
def define_transaction_state(state)
|
266
|
-
|
267
|
-
|
268
|
-
elsif state >= 0 and state <= 99
|
334
|
+
case state
|
335
|
+
when 'unconfirmed'
|
269
336
|
'pending'
|
270
|
-
|
337
|
+
when 'confirmed'
|
338
|
+
'success'
|
339
|
+
when 'failed','rejected'
|
271
340
|
'failed'
|
272
341
|
end
|
273
342
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Peatio
|
4
|
+
module Coinpaymentnew
|
5
|
+
class WalletApi
|
6
|
+
public
|
7
|
+
def self.balance
|
8
|
+
Coinpayments.balances
|
9
|
+
end
|
10
|
+
def self.rate
|
11
|
+
Coinpayments.rates
|
12
|
+
end
|
13
|
+
def self.createTransaction(amount, currency1, currency2, address)
|
14
|
+
Coinpayments.create_transaction(amount, currency1, currency2, {address: address, buyer_email: "joshirockstar007@gmail.com"})
|
15
|
+
end
|
16
|
+
def self.createWithdrawal(amount, currency, address)
|
17
|
+
Coinpayments.create_withdrawal(amount, currency, address)
|
18
|
+
end
|
19
|
+
def self.cancelWithdrawal(id)
|
20
|
+
Coinpayments.cancel_withdrawal(id)
|
21
|
+
end
|
22
|
+
def self.getTxInfo(txid)
|
23
|
+
Coinpayments.get_tx_info(txid)
|
24
|
+
end
|
25
|
+
def self.getCallbackAddress(currency)
|
26
|
+
Coinpayments.get_callback_address(currency)
|
27
|
+
end
|
28
|
+
def self.get_deposit_address(currency, options = {})
|
29
|
+
args = { currency: currency }.merge!(options)
|
30
|
+
Coinpayments.api_call(args)
|
31
|
+
end
|
32
|
+
def self.getWithdrawalInfo(id)
|
33
|
+
Coinpayments.get_withdrawal_info(id)
|
34
|
+
end
|
35
|
+
def self.Sign(secretPhrase)
|
36
|
+
Coinpayments.sign(secretPhrase)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
@@ -2,6 +2,7 @@
|
|
2
2
|
require 'em/pure_ruby'
|
3
3
|
require "peatio"
|
4
4
|
require "coinpayments"
|
5
|
+
require_relative "../../config/initializers/coinpayments"
|
5
6
|
require_relative "coinpaymentnew/version"
|
6
7
|
|
7
8
|
module Peatio
|
@@ -12,7 +13,6 @@ module Peatio
|
|
12
13
|
require "bigdecimal/util"
|
13
14
|
|
14
15
|
require_relative "coinpaymentnew/blockchain"
|
15
|
-
require_relative "coinpaymentnew/client"
|
16
16
|
require_relative "coinpaymentnew/wallet"
|
17
17
|
|
18
18
|
require_relative "coinpaymentnew/hooks"
|
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["Harishankar Joshi"]
|
9
9
|
spec.email = ["joshirockstar007@gmail.com"]
|
10
10
|
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage = "
|
11
|
+
spec.summary = "Write a short summary, because RubyGems requires one."
|
12
|
+
spec.description = "Write a longer description or delete this line."
|
13
|
+
spec.homepage = "http://v2app.rokes.exchange/"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.required_ruby_version = ">= 2.4.0"
|
16
16
|
|
@@ -33,16 +33,14 @@ Gem::Specification.new do |spec|
|
|
33
33
|
# spec.add_dependency "example-gem", "~> 1.0"
|
34
34
|
spec.add_dependency "activesupport", "~> 5.2.3"
|
35
35
|
spec.add_dependency "better-faraday", "~> 1.0.5"
|
36
|
-
spec.add_dependency "faraday", "~> 0.
|
36
|
+
spec.add_dependency "faraday", "~> 0.15.4"
|
37
37
|
spec.add_dependency "memoist", "~> 0.16.0"
|
38
|
-
spec.add_dependency "peatio", "~>
|
39
|
-
spec.add_dependency "coinpayments", "~> 0.0.4" # Required.
|
40
|
-
|
38
|
+
spec.add_dependency "peatio", "~> 0.6.1" # Required.
|
41
39
|
#
|
42
40
|
spec.add_development_dependency "bundler", "~> 1.16"
|
43
41
|
spec.add_development_dependency "mocha", "~> 1.8"
|
44
42
|
spec.add_development_dependency "pry-byebug"
|
45
|
-
spec.add_development_dependency "rake", "~>
|
43
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
46
44
|
spec.add_development_dependency "rspec", "~> 3.0"
|
47
45
|
spec.add_development_dependency "webmock", "~> 3.5"
|
48
46
|
|
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: 1.0.0
|
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
|
+
date: 2021-10-31 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:
|
47
|
+
version: 0.15.4
|
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:
|
54
|
+
version: 0.15.4
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: memoist
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,28 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.6.1
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: coinpayments
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.0.4
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.0.4
|
82
|
+
version: 0.6.1
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: bundler
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,14 +128,14 @@ dependencies:
|
|
142
128
|
requirements:
|
143
129
|
- - "~>"
|
144
130
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
131
|
+
version: '10.0'
|
146
132
|
type: :development
|
147
133
|
prerelease: false
|
148
134
|
version_requirements: !ruby/object:Gem::Requirement
|
149
135
|
requirements:
|
150
136
|
- - "~>"
|
151
137
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
138
|
+
version: '10.0'
|
153
139
|
- !ruby/object:Gem::Dependency
|
154
140
|
name: rspec
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -178,8 +164,7 @@ dependencies:
|
|
178
164
|
- - "~>"
|
179
165
|
- !ruby/object:Gem::Version
|
180
166
|
version: '3.5'
|
181
|
-
description:
|
182
|
-
& Peatio::Wallet::Abstract.
|
167
|
+
description: Write a longer description or delete this line.
|
183
168
|
email:
|
184
169
|
- joshirockstar007@gmail.com
|
185
170
|
executables: []
|
@@ -205,26 +190,21 @@ files:
|
|
205
190
|
- Rakefile
|
206
191
|
- bin/console
|
207
192
|
- bin/setup
|
193
|
+
- config/initializers/coinpayments.rb
|
208
194
|
- lib/peatio/coinpaymentnew.rb
|
209
195
|
- lib/peatio/coinpaymentnew/blockchain.rb
|
210
|
-
- lib/peatio/coinpaymentnew/client.rb
|
211
196
|
- lib/peatio/coinpaymentnew/hooks.rb
|
212
197
|
- lib/peatio/coinpaymentnew/railtie.rb
|
213
198
|
- lib/peatio/coinpaymentnew/version.rb
|
214
199
|
- lib/peatio/coinpaymentnew/wallet.rb
|
215
|
-
- peatio
|
216
|
-
- peatio-coinpaymentnew-0.0.3.gem
|
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
|
200
|
+
- lib/peatio/coinpaymentnew/walletApi.rb
|
221
201
|
- peatio-coinpaymentnew.gemspec
|
222
|
-
homepage:
|
202
|
+
homepage: http://v2app.rokes.exchange/
|
223
203
|
licenses:
|
224
204
|
- MIT
|
225
205
|
metadata:
|
226
206
|
allowed_push_host: https://rubygems.org/
|
227
|
-
homepage_uri:
|
207
|
+
homepage_uri: http://v2app.rokes.exchange/
|
228
208
|
source_code_uri: http://v2app.rokes.exchange/
|
229
209
|
changelog_uri: http://v2app.rokes.exchange/
|
230
210
|
post_install_message:
|
@@ -242,9 +222,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
242
222
|
- !ruby/object:Gem::Version
|
243
223
|
version: '0'
|
244
224
|
requirements: []
|
245
|
-
|
246
|
-
rubygems_version: 2.6.6
|
225
|
+
rubygems_version: 3.0.3.1
|
247
226
|
signing_key:
|
248
227
|
specification_version: 4
|
249
|
-
summary:
|
228
|
+
summary: Write a short summary, because RubyGems requires one.
|
250
229
|
test_files: []
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Peatio
|
4
|
-
module Coinpaymentnew
|
5
|
-
class Client
|
6
|
-
Error = Class.new(StandardError)
|
7
|
-
ConnectionError = Class.new(Error)
|
8
|
-
|
9
|
-
class ResponseError < Error
|
10
|
-
def initialize(msg)
|
11
|
-
super "#{msg}"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize(endpoint, access_token, access_token2)
|
16
|
-
@endpoint = URI.parse(endpoint)
|
17
|
-
@access_token = access_token
|
18
|
-
@access_token2 = access_token2
|
19
|
-
end
|
20
|
-
def self.hmac(body)
|
21
|
-
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha512'), @access_token2, HTTParty::HashConversions.to_params(body))
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.required_params
|
25
|
-
{ version: 1, key: @access_token }
|
26
|
-
end
|
27
|
-
|
28
|
-
def rest_api(args)
|
29
|
-
body = required_params.merge!(args)
|
30
|
-
response = HTTParty.post(@endpoint.to_s, body: body, headers: {'hmac' => hmac(body)})
|
31
|
-
response['error'] == 'ok' ? Hashie::Mash.new(response['result']) : response['error']
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|