peatio-coinpaymentnew 0.0.8 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/blockchains.yml +10 -0
- data/config/currencies.yml +18 -0
- data/config/initializers/coinpayments.rb +6 -0
- data/config/wallets.yml +44 -0
- data/lib/peatio/coinpaymentnew/blockchain.rb +85 -21
- data/lib/peatio/coinpaymentnew/client.rb +60 -37
- data/lib/peatio/coinpaymentnew/hooks.rb +42 -42
- data/lib/peatio/coinpaymentnew/railtie.rb +13 -13
- data/lib/peatio/coinpaymentnew/version.rb +1 -3
- data/lib/peatio/coinpaymentnew/wallet.rb +69 -279
- metadata +6 -8
- 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
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfdf451ac615568015f9af1f7d746b5661a0ef0c
|
4
|
+
data.tar.gz: 904fc5f91697bfa0974c256c1167a545c88968b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76cc5f7009690ebc82cad596506b2cfe9f3a505411faa9611ba192e1f4823f44b6784fde8095bae6784423c6a8b35155ac8fb63b49a742fd99d0620602768558
|
7
|
+
data.tar.gz: 1178a37d1192edaa4043d6186b48b89c499687c0e1d59a36d234fdd11df378be02304ec8c24fe07ab2cdd1190bc0bde4e9e3735bcb668bf1f6c76f42f959cdb3
|
@@ -0,0 +1,10 @@
|
|
1
|
+
- key: ltc-testnet
|
2
|
+
name: Coinpayment Testnet
|
3
|
+
client: coinpayment # API client name.
|
4
|
+
server: http://user:password@127.0.0.1:18332 # Public Coinpayment node endpoint.
|
5
|
+
height: 1087160 # Initial block number from which sync will be started.
|
6
|
+
min_confirmations: 6 # Minimal confirmations needed for withdraw and deposit confirmation.
|
7
|
+
explorer:
|
8
|
+
address: https://chain.so/address/LTCTEST/#{address}
|
9
|
+
transaction: https://chain.so/tx/LTCTEST/#{txid}
|
10
|
+
status: active
|
@@ -0,0 +1,18 @@
|
|
1
|
+
- id: ltc
|
2
|
+
name: Coinpayment
|
3
|
+
blockchain_key: ltc-testnet
|
4
|
+
symbol: 'Ł'
|
5
|
+
type: coin
|
6
|
+
precision: 8
|
7
|
+
base_factor: 100_000_000
|
8
|
+
enabled: true
|
9
|
+
# Deposits with less amount are skipped during blockchain synchronization.
|
10
|
+
# We advise to set value 10 times bigger than the network fee to prevent losses.
|
11
|
+
min_deposit_amount: 0.0004488
|
12
|
+
min_collection_amount: 0.0004488
|
13
|
+
withdraw_limit_24h: 0.5
|
14
|
+
withdraw_limit_72h: 1.2
|
15
|
+
deposit_fee: 0
|
16
|
+
withdraw_fee: 0
|
17
|
+
position: 5
|
18
|
+
options: {}
|
@@ -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
|
data/config/wallets.yml
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
- name: Coinpayment Deposit Wallet
|
2
|
+
blockchain_key: ltc-testnet
|
3
|
+
currency_id: ltc
|
4
|
+
# Address where deposits will be collected to.
|
5
|
+
address: 'Qc2BM7gp8mKgJPPxLAadLAHteNQwhFwwuf' # IMPORTANT: Always wrap this value in quotes!
|
6
|
+
kind: deposit # Wallet kind (deposit, hot, warm, cold or fee).
|
7
|
+
nsig: 1 # Number of signatures required for performing withdraw.
|
8
|
+
max_balance: 0.0
|
9
|
+
status: active
|
10
|
+
gateway: coinpaymentd # Gateway client name.
|
11
|
+
settings:
|
12
|
+
#
|
13
|
+
# Coinpaymentd gateway client settings.
|
14
|
+
uri: http://user:password@127.0.0.1:19332
|
15
|
+
|
16
|
+
- name: Coinpayment Hot Wallet
|
17
|
+
blockchain_key: ltc-testnet
|
18
|
+
currency_id: ltc
|
19
|
+
# Address where deposits will be collected to.
|
20
|
+
address: 'Qc2BM7gp8mKgJPPxLAadLAHteNQwhFwwuf' # IMPORTANT: Always wrap this value in quotes!
|
21
|
+
kind: hot # Wallet kind (deposit, hot, warm, cold or fee).
|
22
|
+
nsig: 1 # Number of signatures required for performing withdraw.
|
23
|
+
max_balance: 5.0
|
24
|
+
status: active
|
25
|
+
gateway: coinpaymentd # Gateway client name.
|
26
|
+
settings:
|
27
|
+
#
|
28
|
+
# Coinpaymentd gateway client settings.
|
29
|
+
uri: http://user:password@127.0.0.1:19332
|
30
|
+
|
31
|
+
- name: Coinpayment Warm Wallet
|
32
|
+
blockchain_key: ltc-testnet
|
33
|
+
currency_id: ltc
|
34
|
+
# Address where deposits will be collected to.
|
35
|
+
address: 'Qc2BM7gp8mKgJPPxLAadLAHteNQwhFwwuf' # IMPORTANT: Always wrap this value in quotes!
|
36
|
+
kind: warm # Wallet kind (deposit, hot, warm, cold or fee).
|
37
|
+
nsig: 1 # Number of signatures required for performing withdraw.
|
38
|
+
max_balance: 50.0
|
39
|
+
status: active
|
40
|
+
gateway: coinpaymentd # Gateway client name.
|
41
|
+
settings:
|
42
|
+
#
|
43
|
+
# Coinpaymentd gateway client settings.
|
44
|
+
uri: http://user:password@127.0.0.1:19332
|
@@ -1,21 +1,85 @@
|
|
1
|
-
|
2
|
-
module Peatio
|
3
|
-
module Coinpaymentnew
|
4
|
-
# TODO: Processing of unconfirmed transactions from mempool isn't supported now.
|
5
|
-
class Blockchain < Peatio::Blockchain::Abstract
|
6
|
-
|
7
|
-
DEFAULT_FEATURES = {case_sensitive: true, cash_addr_format: false}.freeze
|
8
|
-
|
9
|
-
def initialize(custom_features = {})
|
10
|
-
@features = DEFAULT_FEATURES.merge(custom_features).slice(*SUPPORTED_FEATURES)
|
11
|
-
@settings = {}
|
12
|
-
end
|
13
|
-
|
14
|
-
def configure(settings = {})
|
15
|
-
# Clean client state during configure.
|
16
|
-
@client = nil
|
17
|
-
@settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
|
1
|
+
|
2
|
+
module Peatio
|
3
|
+
module Coinpaymentnew
|
4
|
+
# TODO: Processing of unconfirmed transactions from mempool isn't supported now.
|
5
|
+
class Blockchain < Peatio::Blockchain::Abstract
|
6
|
+
|
7
|
+
DEFAULT_FEATURES = {case_sensitive: true, cash_addr_format: false}.freeze
|
8
|
+
|
9
|
+
def initialize(custom_features = {})
|
10
|
+
@features = DEFAULT_FEATURES.merge(custom_features).slice(*SUPPORTED_FEATURES)
|
11
|
+
@settings = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def configure(settings = {})
|
15
|
+
# Clean client state during configure.
|
16
|
+
@client = nil
|
17
|
+
@settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
|
18
|
+
end
|
19
|
+
|
20
|
+
def fetch_block!(block_number)
|
21
|
+
block_hash = client.json_rpc(:getblockhash, [block_number])
|
22
|
+
|
23
|
+
client.json_rpc(:getblock, [block_hash, 2])
|
24
|
+
.fetch('tx').each_with_object([]) do |tx, txs_array|
|
25
|
+
txs = build_transaction(tx).map do |ntx|
|
26
|
+
Peatio::Transaction.new(ntx.merge(block_number: block_number))
|
27
|
+
end
|
28
|
+
txs_array.append(*txs)
|
29
|
+
end.yield_self { |txs_array| Peatio::Block.new(block_number, txs_array) }
|
30
|
+
rescue Client::Error => e
|
31
|
+
raise Peatio::Blockchain::ClientError, e
|
32
|
+
end
|
33
|
+
|
34
|
+
def latest_block_number
|
35
|
+
client.json_rpc(:getblockcount)
|
36
|
+
rescue Client::Error => e
|
37
|
+
raise Peatio::Blockchain::ClientError, e
|
38
|
+
end
|
39
|
+
|
40
|
+
def load_balance_of_address!(address, _currency_id)
|
41
|
+
address_with_balance = client.json_rpc(:listaddressgroupings)
|
42
|
+
.flatten(1)
|
43
|
+
.find { |addr| addr[0] == address }
|
44
|
+
|
45
|
+
if address_with_balance.blank?
|
46
|
+
raise Peatio::Blockchain::UnavailableAddressBalanceError, address
|
47
|
+
end
|
48
|
+
|
49
|
+
address_with_balance[1].to_d
|
50
|
+
rescue Client::Error => e
|
51
|
+
raise Peatio::Blockchain::ClientError, e
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def build_transaction(tx_hash)
|
57
|
+
tx_hash.fetch('vout')
|
58
|
+
.select do |entry|
|
59
|
+
entry.fetch('value').to_d > 0 &&
|
60
|
+
entry['scriptPubKey'].has_key?('addresses')
|
61
|
+
end
|
62
|
+
.each_with_object([]) do |entry, formatted_txs|
|
63
|
+
no_currency_tx =
|
64
|
+
{ hash: tx_hash['txid'], txout: entry['n'],
|
65
|
+
to_address: entry['scriptPubKey']['addresses'][0],
|
66
|
+
amount: entry.fetch('value').to_d,
|
67
|
+
status: 'success' }
|
68
|
+
|
69
|
+
# Build transaction for each currency belonging to blockchain.
|
70
|
+
settings_fetch(:currencies).pluck(:id).each do |currency_id|
|
71
|
+
formatted_txs << no_currency_tx.merge(currency_id: currency_id)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def client
|
77
|
+
@client ||= Client.new(settings_fetch(:server))
|
78
|
+
end
|
79
|
+
|
80
|
+
def settings_fetch(key)
|
81
|
+
@settings.fetch(key) { raise Peatio::Blockchain::MissingSettingError, key.to_s }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -1,37 +1,60 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'memoist'
|
4
|
+
require 'faraday'
|
5
|
+
require 'better-faraday'
|
6
|
+
|
7
|
+
module Peatio
|
8
|
+
module Coinpaymentnew
|
9
|
+
class Client
|
10
|
+
Error = Class.new(StandardError)
|
11
|
+
ConnectionError = Class.new(Error)
|
12
|
+
|
13
|
+
class ResponseError < Error
|
14
|
+
def initialize(code, msg)
|
15
|
+
@code = code
|
16
|
+
@msg = msg
|
17
|
+
end
|
18
|
+
|
19
|
+
def message
|
20
|
+
"#{@msg} (#{@code})"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
extend Memoist
|
25
|
+
|
26
|
+
def initialize(endpoint)
|
27
|
+
@json_rpc_endpoint = URI.parse(endpoint)
|
28
|
+
end
|
29
|
+
|
30
|
+
def json_rpc(method, params = [])
|
31
|
+
response = connection.post \
|
32
|
+
'/',
|
33
|
+
{ jsonrpc: '1.0', method: method, params: params }.to_json,
|
34
|
+
{ 'Accept' => 'application/json',
|
35
|
+
'Content-Type' => 'application/json' }
|
36
|
+
response.assert_2xx!
|
37
|
+
response = JSON.parse(response.body)
|
38
|
+
response['error'].tap do |e|
|
39
|
+
raise ResponseError.new(e['code'], e['message']) if e
|
40
|
+
end
|
41
|
+
response.fetch('result')
|
42
|
+
rescue Faraday::Error => e
|
43
|
+
raise ConnectionError, e
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def connection
|
49
|
+
@connection ||= Faraday.new(@json_rpc_endpoint) do |f|
|
50
|
+
f.adapter :net_http_persistent, pool_size: 5
|
51
|
+
end.tap do |connection|
|
52
|
+
unless @json_rpc_endpoint.user.blank?
|
53
|
+
connection.basic_auth(@json_rpc_endpoint.user,
|
54
|
+
@json_rpc_endpoint.password)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -1,42 +1,42 @@
|
|
1
|
-
module Peatio
|
2
|
-
module Coinpaymentnew
|
3
|
-
module Hooks
|
4
|
-
BLOCKCHAIN_VERSION_REQUIREMENT = "~> 1.0.0"
|
5
|
-
WALLET_VERSION_REQUIREMENT = "~> 1.0.0"
|
6
|
-
|
7
|
-
class << self
|
8
|
-
def check_compatibility
|
9
|
-
unless Gem::Requirement.new(BLOCKCHAIN_VERSION_REQUIREMENT)
|
10
|
-
.satisfied_by?(Gem::Version.new(Peatio::Blockchain::VERSION))
|
11
|
-
[
|
12
|
-
"
|
13
|
-
"
|
14
|
-
"Peatio::Blockchain version is #{Peatio::Blockchain::VERSION}"
|
15
|
-
].join('\n').tap { |s| Kernel.abort s }
|
16
|
-
end
|
17
|
-
|
18
|
-
unless Gem::Requirement.new(WALLET_VERSION_REQUIREMENT)
|
19
|
-
.satisfied_by?(Gem::Version.new(Peatio::Wallet::VERSION))
|
20
|
-
[
|
21
|
-
"
|
22
|
-
"
|
23
|
-
"Peatio::Wallet version is #{Peatio::Wallet::VERSION}"
|
24
|
-
].join('\n').tap { |s| Kernel.abort s }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def register
|
29
|
-
Peatio::Blockchain.registry[:coinpaymentnew] = Coinpaymentnew::Blockchain
|
30
|
-
Peatio::Wallet.registry[:
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
if defined?(Rails::Railtie)
|
35
|
-
require "peatio/coinpaymentnew/railtie"
|
36
|
-
else
|
37
|
-
check_compatibility
|
38
|
-
register
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
1
|
+
module Peatio
|
2
|
+
module Coinpaymentnew
|
3
|
+
module Hooks
|
4
|
+
BLOCKCHAIN_VERSION_REQUIREMENT = "~> 1.0.0"
|
5
|
+
WALLET_VERSION_REQUIREMENT = "~> 1.0.0"
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def check_compatibility
|
9
|
+
unless Gem::Requirement.new(BLOCKCHAIN_VERSION_REQUIREMENT)
|
10
|
+
.satisfied_by?(Gem::Version.new(Peatio::Blockchain::VERSION))
|
11
|
+
[
|
12
|
+
"Coinpayment blockchain version requiremnt was not suttisfied by Peatio::Blockchain.",
|
13
|
+
"Coinpayment blockchain requires #{BLOCKCHAIN_VERSION_REQUIREMENT}.",
|
14
|
+
"Peatio::Blockchain version is #{Peatio::Blockchain::VERSION}"
|
15
|
+
].join('\n').tap { |s| Kernel.abort s }
|
16
|
+
end
|
17
|
+
|
18
|
+
unless Gem::Requirement.new(WALLET_VERSION_REQUIREMENT)
|
19
|
+
.satisfied_by?(Gem::Version.new(Peatio::Wallet::VERSION))
|
20
|
+
[
|
21
|
+
"Coinpayment wallet version requiremnt was not suttisfied by Peatio::Wallet.",
|
22
|
+
"Coinpayment wallet requires #{WALLET_VERSION_REQUIREMENT}.",
|
23
|
+
"Peatio::Wallet version is #{Peatio::Wallet::VERSION}"
|
24
|
+
].join('\n').tap { |s| Kernel.abort s }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def register
|
29
|
+
Peatio::Blockchain.registry[:coinpaymentnew] = Coinpaymentnew::Blockchain
|
30
|
+
Peatio::Wallet.registry[:coinpaymentnewd] = Coinpaymentnew::Wallet
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if defined?(Rails::Railtie)
|
35
|
+
require "peatio/coinpaymentnew/railtie"
|
36
|
+
else
|
37
|
+
check_compatibility
|
38
|
+
register
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
module Peatio
|
2
|
-
module Coinpaymentnew
|
3
|
-
class Railtie < Rails::Railtie
|
4
|
-
config.before_initialize do
|
5
|
-
Hooks.check_compatibility
|
6
|
-
end
|
7
|
-
|
8
|
-
config.after_initialize do
|
9
|
-
Hooks.register
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
1
|
+
module Peatio
|
2
|
+
module Coinpaymentnew
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
config.before_initialize do
|
5
|
+
Hooks.check_compatibility
|
6
|
+
end
|
7
|
+
|
8
|
+
config.after_initialize do
|
9
|
+
Hooks.register
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,279 +1,69 @@
|
|
1
|
-
module Peatio
|
2
|
-
module Coinpaymentnew
|
3
|
-
class Wallet < Peatio::Wallet::Abstract
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@
|
17
|
-
|
18
|
-
@settings.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
{ address:
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
transaction
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
# response = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
|
71
|
-
# address: transaction.to_address.to_s,
|
72
|
-
# amount: amount.to_s,
|
73
|
-
# walletPassphrase: coinpayment_wallet_passphrase,
|
74
|
-
# gas: options.fetch(:gas_limit).to_i,
|
75
|
-
# gasPrice: options.fetch(:gas_price).to_i,
|
76
|
-
# hop: hop
|
77
|
-
# }.compact)
|
78
|
-
|
79
|
-
# if response['feeString'].present?
|
80
|
-
# fee = convert_from_base_unit(response['feeString'])
|
81
|
-
# transaction.fee = fee
|
82
|
-
# end
|
83
|
-
|
84
|
-
# transaction.hash = normalize_txid(response['txid'])
|
85
|
-
# transaction.fee_currency_id = erc20_currency_id
|
86
|
-
# transaction.options = options
|
87
|
-
# transaction
|
88
|
-
# end
|
89
|
-
|
90
|
-
# def fee_estimate(amount, hop)
|
91
|
-
# client.rest_api(:get, "#{erc20_currency_id}/tx/fee", { amount: amount, hop: hop }.compact)
|
92
|
-
# end
|
93
|
-
|
94
|
-
def load_balance!
|
95
|
-
args = { cmd: "balances" }
|
96
|
-
response = client.rest_api(args)
|
97
|
-
response[currency_id.upcase]['balancef']
|
98
|
-
rescue Coinpayment::Client::Error => e
|
99
|
-
raise Peatio::Wallet::ClientError, e
|
100
|
-
end
|
101
|
-
|
102
|
-
# def load_erc20_balance!
|
103
|
-
# response = client.rest_api(:get, "#{erc20_currency_id}/wallet/#{wallet_id}?allTokens=true")
|
104
|
-
# convert_from_base_unit(response.dig('tokens', currency_id, 'balanceString'))
|
105
|
-
# rescue Coinpayment::Client::Error => e
|
106
|
-
# raise Peatio::Wallet::ClientError, e
|
107
|
-
# end
|
108
|
-
|
109
|
-
def trigger_webhook_event(request)
|
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
|
117
|
-
|
118
|
-
if request.params['ipn_type'] == 'deposit'
|
119
|
-
transactions = fetch_transfer!(request.params['txn_id'])
|
120
|
-
return transactions
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
# def register_webhooks!(url)
|
125
|
-
# transfer_webhook(url)
|
126
|
-
# address_confirmation_webhook(url)
|
127
|
-
# end
|
128
|
-
|
129
|
-
# def fetch_address_id(address)
|
130
|
-
# currency = erc20_currency_id
|
131
|
-
# client.rest_api(:get, "#{currency}/wallet/#{wallet_id}/address/#{address}")
|
132
|
-
# .fetch('id')
|
133
|
-
# rescue Coinpayment::Client::Error => e
|
134
|
-
# raise Peatio::Wallet::ClientError, e
|
135
|
-
# end
|
136
|
-
|
137
|
-
def fetch_transfer!(id)
|
138
|
-
args = { cmd: "get_tx_info", txid: id }
|
139
|
-
response = client.rest_api(args)
|
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
|
154
|
-
rescue Coinpayment::Client::Error => e
|
155
|
-
raise Peatio::Wallet::ClientError, e
|
156
|
-
end
|
157
|
-
|
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
|
167
|
-
|
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
|
177
|
-
|
178
|
-
def parse_entries(entries)
|
179
|
-
entries.map do |e|
|
180
|
-
e if e["valueString"].to_i.positive?
|
181
|
-
end.compact
|
182
|
-
end
|
183
|
-
|
184
|
-
def client
|
185
|
-
uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
|
186
|
-
access_token = @wallet.fetch(:access_token) { raise Peatio::Wallet::MissingSettingError, :access_token }
|
187
|
-
access_token2 = @wallet.fetch(:access_token2) { raise Peatio::Wallet::MissingSettingError, :access_token2 }
|
188
|
-
|
189
|
-
@client ||= Client.new(uri, access_token, access_token2)
|
190
|
-
end
|
191
|
-
|
192
|
-
def build_address(address, memo)
|
193
|
-
"#{address}?memoId=#{memo['value']}"
|
194
|
-
end
|
195
|
-
|
196
|
-
# All these functions will have to be done with the coin set to eth or teth
|
197
|
-
# since that is the actual coin type being used.
|
198
|
-
def erc20_currency_id
|
199
|
-
return 'eth' if @currency.fetch(:options).slice(:erc20_contract_address).present?
|
200
|
-
|
201
|
-
currency_id
|
202
|
-
end
|
203
|
-
|
204
|
-
def xlm_memo(address)
|
205
|
-
build_xlm_memo(address) if @currency.fetch(:id) == 'xlm'
|
206
|
-
end
|
207
|
-
|
208
|
-
def build_xlm_memo(address)
|
209
|
-
case address.split('?').last.split('=').first
|
210
|
-
when 'memoId'
|
211
|
-
memo_value_from(address, 'memoId')
|
212
|
-
when 'memoText'
|
213
|
-
memo_value_from(address, 'memoText')
|
214
|
-
when 'memoHash'
|
215
|
-
memo_value_from(address, 'memoHash')
|
216
|
-
when 'memoReturn'
|
217
|
-
memo_value_from(address, 'memoReturn')
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
def memo_value_from(address, type)
|
222
|
-
memo_value = address.partition(type + '=').last
|
223
|
-
return { type: XLM_MEMO_TYPES[type.to_sym], value: memo_value } if memo_value.present?
|
224
|
-
end
|
225
|
-
|
226
|
-
def currency_id
|
227
|
-
@currency.fetch(:id) { raise Peatio::Wallet::MissingSettingError, :id }
|
228
|
-
end
|
229
|
-
|
230
|
-
def coinpayment_wallet_passphrase
|
231
|
-
@wallet.fetch(:secret)
|
232
|
-
end
|
233
|
-
|
234
|
-
def wallet_id
|
235
|
-
@wallet.fetch(:wallet_id)
|
236
|
-
end
|
237
|
-
|
238
|
-
def normalize_address(address)
|
239
|
-
if @currency.fetch(:id) == 'xlm'
|
240
|
-
address.split('?').first
|
241
|
-
else
|
242
|
-
address
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
def normalize_txid(txid)
|
247
|
-
txid.downcase
|
248
|
-
end
|
249
|
-
|
250
|
-
def convert_from_base_unit(value)
|
251
|
-
value.to_d / @currency.fetch(:base_factor)
|
252
|
-
end
|
253
|
-
|
254
|
-
def convert_to_base_unit(value)
|
255
|
-
x = value.to_d * @currency.fetch(:base_factor)
|
256
|
-
unless (x % 1).zero?
|
257
|
-
raise Peatio::WalletClient::Error,
|
258
|
-
"Failed to convert value to base (smallest) unit because it exceeds the maximum precision: " \
|
259
|
-
"#{value.to_d} - #{x.to_d} must be equal to zero."
|
260
|
-
end
|
261
|
-
x.to_i
|
262
|
-
end
|
263
|
-
|
264
|
-
def time_difference_in_minutes(updated_at)
|
265
|
-
(Time.now - updated_at)/60
|
266
|
-
end
|
267
|
-
|
268
|
-
def define_transaction_state(state)
|
269
|
-
if state >= 100
|
270
|
-
"success"
|
271
|
-
elsif state >= 0 and state <= 99
|
272
|
-
'pending'
|
273
|
-
else
|
274
|
-
'failed'
|
275
|
-
end
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|
1
|
+
module Peatio
|
2
|
+
module Coinpaymentnew
|
3
|
+
class Wallet < Peatio::Wallet::Abstract
|
4
|
+
|
5
|
+
DEFAULT_FEATURES = { skip_deposit_collection: false }.freeze
|
6
|
+
|
7
|
+
def initialize(custom_features = {})
|
8
|
+
@features = DEFAULT_FEATURES.merge(custom_features).slice(*SUPPORTED_FEATURES)
|
9
|
+
@settings = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure(settings = {})
|
13
|
+
# Clean client state during configure.
|
14
|
+
@client = nil
|
15
|
+
|
16
|
+
@settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
|
17
|
+
|
18
|
+
@wallet = @settings.fetch(:wallet) do
|
19
|
+
raise Peatio::Wallet::MissingSettingError, :wallet
|
20
|
+
end.slice(:uri, :address)
|
21
|
+
|
22
|
+
@currency = @settings.fetch(:currency) do
|
23
|
+
raise Peatio::Wallet::MissingSettingError, :currency
|
24
|
+
end.slice(:id, :base_factor, :options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_address!(_options = {})
|
28
|
+
r = Coinpayments.get_callback_address('BTC', {ipn_url: "https://v2app.rokes.exchange/api/v2/peatio/public/webhooks/deposit"})
|
29
|
+
{ address: r[:address] }
|
30
|
+
rescue Coinpaymentnew::Client::Error => e
|
31
|
+
raise Peatio::Wallet::ClientError, e
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_transaction!(transaction, options = {})
|
35
|
+
res = Coinpayments.create_transaction(transaction.amount, "USD", currency_id, {buyer_email: "joshirockstar007@gmail.com", address: transaction.to_address, ipn_url: "https://v2app.rokes.exchange/api/v2/peatio/public/webhooks/deposit"})
|
36
|
+
# txid = client.json_rpc(:sendtoaddress,
|
37
|
+
# [
|
38
|
+
# transaction.to_address,
|
39
|
+
# transaction.amount,
|
40
|
+
# '',
|
41
|
+
# '',
|
42
|
+
# options[:subtract_fee].to_s == 'true' # subtract fee from transaction amount.
|
43
|
+
# ])
|
44
|
+
transaction.hash = res[:txn_id]
|
45
|
+
transaction
|
46
|
+
rescue Coinpaymentnew::Client::Error => e
|
47
|
+
raise Peatio::Wallet::ClientError, e
|
48
|
+
end
|
49
|
+
|
50
|
+
def load_balance!
|
51
|
+
client.json_rpc(:getbalance).to_d
|
52
|
+
|
53
|
+
rescue Coinpaymentnew::Client::Error => e
|
54
|
+
raise Peatio::Wallet::ClientError, e
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def client
|
60
|
+
uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
|
61
|
+
@client ||= Client.new(uri)
|
62
|
+
end
|
63
|
+
|
64
|
+
def currency_id
|
65
|
+
@currency.fetch(:id) { raise Peatio::Wallet::MissingSettingError, :id }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
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:
|
4
|
+
version: 1.0.2
|
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-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -205,6 +205,10 @@ files:
|
|
205
205
|
- Rakefile
|
206
206
|
- bin/console
|
207
207
|
- bin/setup
|
208
|
+
- config/blockchains.yml
|
209
|
+
- config/currencies.yml
|
210
|
+
- config/initializers/coinpayments.rb
|
211
|
+
- config/wallets.yml
|
208
212
|
- lib/peatio/coinpaymentnew.rb
|
209
213
|
- lib/peatio/coinpaymentnew/blockchain.rb
|
210
214
|
- lib/peatio/coinpaymentnew/client.rb
|
@@ -212,12 +216,6 @@ files:
|
|
212
216
|
- lib/peatio/coinpaymentnew/railtie.rb
|
213
217
|
- lib/peatio/coinpaymentnew/version.rb
|
214
218
|
- lib/peatio/coinpaymentnew/wallet.rb
|
215
|
-
- peatio-coinpaymentnew-0.0.2.gem
|
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
|
221
219
|
- peatio-coinpaymentnew.gemspec
|
222
220
|
homepage: https://openware.com/
|
223
221
|
licenses:
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|