peatio-coinpaymentnew 0.0.9 → 1.0.3

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: fba2656c87b177ed9f41a2297a04f343bdaa29c9
4
- data.tar.gz: 942adceca45cf5d1aadd0d31e957b32a3c88c73b
3
+ metadata.gz: 2acbf149c789e765dd318ad69120c2b7e41e7dcb
4
+ data.tar.gz: eea76d2cba2afed3a85f1dfef9aafe92648e7bd5
5
5
  SHA512:
6
- metadata.gz: 79d32c8700361d9a72cd31075b65aebc452b752e83917b7c92024cbe414f08da86638fe6768da27d2c067f05fe7075092d2704157ea3cb02d0ffd3120707fc15
7
- data.tar.gz: d8f5d1d4519a9b9434b0c9376b4cebef550c6e196510ee5c1bf2e5cceef0eba6cc1fafa1379e8c6dca17d44c2a1c7625a94f7ed96c37e6fc30fa46783e24e6f6
6
+ metadata.gz: 0b4d69b611e35929de926dd0532cf1e58edc1af1e93297aac2c95b031605ac02e1687c9b696a84ca396ece0ff062d320c644d360861e56ce1bbba3664b743e5e
7
+ data.tar.gz: 7086449212a179300795af5b9d9ede47651e2f9bb32f01de7b96f5adf3597d1e5b3afce843dea9e20abf5de6b84ce36967924774c681b6e2f46d1b43d00958ba
@@ -17,38 +17,49 @@
17
17
  <orderEntry type="library" scope="PROVIDED" name="amq-protocol (v2.3.2, ruby-2.6.8-p205) [gem]" level="application" />
18
18
  <orderEntry type="library" scope="PROVIDED" name="amqp (v1.8.0, ruby-2.6.8-p205) [gem]" level="application" />
19
19
  <orderEntry type="library" scope="PROVIDED" name="better-faraday (v1.0.8, ruby-2.6.8-p205) [gem]" level="application" />
20
- <orderEntry type="library" scope="PROVIDED" name="bundler (v1.17.2, ruby-2.6.8-p205) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.2.32, ruby-2.6.8-p205) [gem]" level="application" />
21
21
  <orderEntry type="library" scope="PROVIDED" name="bunny (v2.19.0, ruby-2.6.8-p205) [gem]" level="application" />
22
22
  <orderEntry type="library" scope="PROVIDED" name="byebug (v11.1.3, ruby-2.6.8-p205) [gem]" level="application" />
23
23
  <orderEntry type="library" scope="PROVIDED" name="clamp (v1.3.2, ruby-2.6.8-p205) [gem]" level="application" />
24
24
  <orderEntry type="library" scope="PROVIDED" name="coderay (v1.1.3, ruby-2.6.8-p205) [gem]" level="application" />
25
25
  <orderEntry type="library" scope="PROVIDED" name="coinpayments (v0.0.4, ruby-2.6.8-p205) [gem]" level="application" />
26
26
  <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.9, ruby-2.6.8-p205) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="cookiejar (v0.3.3, ruby-2.6.8-p205) [gem]" level="application" />
27
28
  <orderEntry type="library" scope="PROVIDED" name="crack (v0.4.5, ruby-2.6.8-p205) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="daemons (v1.4.1, ruby-2.6.8-p205) [gem]" level="application" />
28
30
  <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.4.4, ruby-2.6.8-p205) [gem]" level="application" />
29
- <orderEntry type="library" scope="PROVIDED" name="em-websocket (v0.5.2, ruby-2.6.8-p205) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="em-http-request (v1.1.7, ruby-2.6.8-p205) [gem]" level="application" />
32
+ <orderEntry type="library" scope="PROVIDED" name="em-socksify (v0.3.2, ruby-2.6.8-p205) [gem]" level="application" />
33
+ <orderEntry type="library" scope="PROVIDED" name="em-synchrony (v1.0.6, ruby-2.6.8-p205) [gem]" level="application" />
34
+ <orderEntry type="library" scope="PROVIDED" name="em-websocket (v0.5.3, ruby-2.6.8-p205) [gem]" level="application" />
30
35
  <orderEntry type="library" scope="PROVIDED" name="eventmachine (v1.2.7, ruby-2.6.8-p205) [gem]" level="application" />
31
- <orderEntry type="library" scope="PROVIDED" name="faraday (v0.15.4, ruby-2.6.8-p205) [gem]" level="application" />
36
+ <orderEntry type="library" scope="PROVIDED" name="faraday (v0.17.4, ruby-2.6.8-p205) [gem]" level="application" />
37
+ <orderEntry type="library" scope="PROVIDED" name="faraday_middleware (v0.13.1, ruby-2.6.8-p205) [gem]" level="application" />
38
+ <orderEntry type="library" scope="PROVIDED" name="faye (v1.4.0, ruby-2.6.8-p205) [gem]" level="application" />
39
+ <orderEntry type="library" scope="PROVIDED" name="faye-websocket (v0.11.1, ruby-2.6.8-p205) [gem]" level="application" />
32
40
  <orderEntry type="library" scope="PROVIDED" name="hashdiff (v1.0.1, ruby-2.6.8-p205) [gem]" level="application" />
33
- <orderEntry type="library" scope="PROVIDED" name="hashie (v4.1.0, ruby-2.6.8-p205) [gem]" level="application" />
34
- <orderEntry type="library" scope="PROVIDED" name="http_parser.rb (v0.6.0, ruby-2.6.8-p205) [gem]" level="application" />
41
+ <orderEntry type="library" scope="PROVIDED" name="hashie (v5.0.0, ruby-2.6.8-p205) [gem]" level="application" />
42
+ <orderEntry type="library" scope="PROVIDED" name="http_parser.rb (v0.8.0, ruby-2.6.8-p205) [gem]" level="application" />
35
43
  <orderEntry type="library" scope="PROVIDED" name="httparty (v0.20.0, ruby-2.6.8-p205) [gem]" level="application" />
36
- <orderEntry type="library" scope="PROVIDED" name="i18n (v1.8.10, ruby-2.6.8-p205) [gem]" level="application" />
44
+ <orderEntry type="library" scope="PROVIDED" name="i18n (v1.8.11, ruby-2.6.8-p205) [gem]" level="application" />
37
45
  <orderEntry type="library" scope="PROVIDED" name="jwt (v2.3.0, ruby-2.6.8-p205) [gem]" level="application" />
38
46
  <orderEntry type="library" scope="PROVIDED" name="memoist (v0.16.2, ruby-2.6.8-p205) [gem]" level="application" />
39
47
  <orderEntry type="library" scope="PROVIDED" name="method_source (v1.0.0, ruby-2.6.8-p205) [gem]" level="application" />
40
- <orderEntry type="library" scope="PROVIDED" name="mime-types (v3.3.1, ruby-2.6.8-p205) [gem]" level="application" />
41
- <orderEntry type="library" scope="PROVIDED" name="mime-types-data (v3.2021.0901, ruby-2.6.8-p205) [gem]" level="application" />
48
+ <orderEntry type="library" scope="PROVIDED" name="mime-types (v3.4.1, ruby-2.6.8-p205) [gem]" level="application" />
49
+ <orderEntry type="library" scope="PROVIDED" name="mime-types-data (v3.2021.1115, ruby-2.6.8-p205) [gem]" level="application" />
42
50
  <orderEntry type="library" scope="PROVIDED" name="minitest (v5.14.4, ruby-2.6.8-p205) [gem]" level="application" />
43
51
  <orderEntry type="library" scope="PROVIDED" name="mocha (v1.13.0, ruby-2.6.8-p205) [gem]" level="application" />
52
+ <orderEntry type="library" scope="PROVIDED" name="multi_json (v1.15.0, ruby-2.6.8-p205) [gem]" level="application" />
44
53
  <orderEntry type="library" scope="PROVIDED" name="multi_xml (v0.6.0, ruby-2.6.8-p205) [gem]" level="application" />
45
54
  <orderEntry type="library" scope="PROVIDED" name="multipart-post (v2.1.1, ruby-2.6.8-p205) [gem]" level="application" />
46
55
  <orderEntry type="library" scope="PROVIDED" name="mysql2 (v0.5.3, ruby-2.6.8-p205) [gem]" level="application" />
47
- <orderEntry type="library" scope="PROVIDED" name="peatio (v0.6.3, ruby-2.6.8-p205) [gem]" level="application" />
56
+ <orderEntry type="library" scope="PROVIDED" name="peatio (v2.6.5, ruby-2.6.8-p205) [gem]" level="application" />
57
+ <orderEntry type="library" scope="PROVIDED" name="prometheus-client (v2.1.0, ruby-2.6.8-p205) [gem]" level="application" />
48
58
  <orderEntry type="library" scope="PROVIDED" name="pry (v0.13.1, ruby-2.6.8-p205) [gem]" level="application" />
49
59
  <orderEntry type="library" scope="PROVIDED" name="pry-byebug (v3.9.0, ruby-2.6.8-p205) [gem]" level="application" />
50
60
  <orderEntry type="library" scope="PROVIDED" name="public_suffix (v4.0.6, ruby-2.6.8-p205) [gem]" level="application" />
51
- <orderEntry type="library" scope="PROVIDED" name="rake (v10.5.0, ruby-2.6.8-p205) [gem]" level="application" />
61
+ <orderEntry type="library" scope="PROVIDED" name="rack (v2.2.3, ruby-2.6.8-p205) [gem]" level="application" />
62
+ <orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, ruby-2.6.8-p205) [gem]" level="application" />
52
63
  <orderEntry type="library" scope="PROVIDED" name="rbtree (v0.4.4, ruby-2.6.8-p205) [gem]" level="application" />
53
64
  <orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, ruby-2.6.8-p205) [gem]" level="application" />
54
65
  <orderEntry type="library" scope="PROVIDED" name="rspec (v3.10.0, ruby-2.6.8-p205) [gem]" level="application" />
@@ -56,11 +67,14 @@
56
67
  <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.10.1, ruby-2.6.8-p205) [gem]" level="application" />
57
68
  <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.10.2, ruby-2.6.8-p205) [gem]" level="application" />
58
69
  <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.10.2, ruby-2.6.8-p205) [gem]" level="application" />
59
- <orderEntry type="library" scope="PROVIDED" name="set (v1.0.1, ruby-2.6.8-p205) [gem]" level="application" />
70
+ <orderEntry type="library" scope="PROVIDED" name="set (v1.0.2, ruby-2.6.8-p205) [gem]" level="application" />
60
71
  <orderEntry type="library" scope="PROVIDED" name="sorted_set (v1.0.3, ruby-2.6.8-p205) [gem]" level="application" />
72
+ <orderEntry type="library" scope="PROVIDED" name="thin (v1.8.1, ruby-2.6.8-p205) [gem]" level="application" />
61
73
  <orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.3.6, ruby-2.6.8-p205) [gem]" level="application" />
62
74
  <orderEntry type="library" scope="PROVIDED" name="tzinfo (v1.2.9, ruby-2.6.8-p205) [gem]" level="application" />
63
75
  <orderEntry type="library" scope="PROVIDED" name="webmock (v3.14.0, ruby-2.6.8-p205) [gem]" level="application" />
76
+ <orderEntry type="library" scope="PROVIDED" name="websocket-driver (v0.7.5, ruby-2.6.8-p205) [gem]" level="application" />
77
+ <orderEntry type="library" scope="PROVIDED" name="websocket-extensions (v0.1.5, ruby-2.6.8-p205) [gem]" level="application" />
64
78
  </component>
65
79
  <component name="RakeTasksCache">
66
80
  <option name="myRootTask">
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- peatio-coinpaymentnew (0.0.5)
4
+ peatio-coinpaymentnew (1.0.3)
5
5
  activesupport (~> 5.2.3)
6
6
  better-faraday (~> 1.0.5)
7
7
  coinpayments (~> 0.0.4)
@@ -73,7 +73,7 @@ GEM
73
73
  eventmachine (>= 0.12.0)
74
74
  websocket-driver (>= 0.5.1)
75
75
  hashdiff (1.0.1)
76
- hashie (4.1.0)
76
+ hashie (5.0.0)
77
77
  http_parser.rb (0.8.0)
78
78
  httparty (0.20.0)
79
79
  mime-types (~> 3.0)
@@ -83,9 +83,9 @@ GEM
83
83
  jwt (2.3.0)
84
84
  memoist (0.16.2)
85
85
  method_source (1.0.0)
86
- mime-types (3.3.1)
86
+ mime-types (3.4.1)
87
87
  mime-types-data (~> 3.2015)
88
- mime-types-data (3.2021.0901)
88
+ mime-types-data (3.2021.1115)
89
89
  minitest (5.14.4)
90
90
  mocha (1.13.0)
91
91
  multi_json (1.15.0)
@@ -154,7 +154,7 @@ PLATFORMS
154
154
  x64-mingw32
155
155
 
156
156
  DEPENDENCIES
157
- bundler (~> 1.16)
157
+ bundler (~> 2.2.32)
158
158
  mocha (~> 1.8)
159
159
  peatio-coinpaymentnew!
160
160
  pry-byebug
@@ -163,4 +163,4 @@ DEPENDENCIES
163
163
  webmock (~> 3.5)
164
164
 
165
165
  BUNDLED WITH
166
- 1.17.3
166
+ 2.2.32
@@ -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
@@ -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
- end
20
- end
21
- end
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
- 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
-
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
- "Coinpaymentnew blockchain version requirement was not satisfied by Peatio::Blockchain.",
13
- "Coinpaymentnew 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
- "Coinpaymentnew wallet version requirement was not satisfied by Peatio::Wallet.",
22
- "Coinpaymentnew 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[:coinpaymentnew] = 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
+ 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,7 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Peatio
4
2
  module Coinpaymentnew
5
- VERSION = "0.0.9"
3
+ VERSION = "1.0.3".freeze
6
4
  end
7
5
  end
@@ -1,276 +1,69 @@
1
- module Peatio
2
- module Coinpaymentnew
3
- class Wallet < Peatio::Wallet::Abstract
4
- TIME_DIFFERENCE_IN_MINUTES = 10
5
- XLM_MEMO_TYPES = { 'memoId': 'id', 'memoText': 'text', 'memoHash': 'hash', 'memoReturn': 'return' }
6
-
7
- DEFAULT_FEATURES = { skip_deposit_collection: 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
-
18
- @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
19
-
20
- @wallet = @settings.fetch(:wallet) do
21
- raise Peatio::Wallet::MissingSettingError, :wallet
22
- end.slice(:uri, :address, :secret, :access_token, :access_token2, :wallet_id, :testnet)
23
-
24
- @currency = @settings.fetch(:currency) do
25
- raise Peatio::Wallet::MissingSettingError, :currency
26
- end.slice(:id, :base_factor, :code, :options)
27
- end
28
-
29
- def create_address!(options = {})
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
34
- raise Peatio::Wallet::ClientError, e
35
- end
36
-
37
- def create_transaction!(transaction, options = {})
38
- currency_options = @currency.fetch(:options).slice(:gas_limit, :gas_price, :erc20_contract_address)
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
45
- raise Peatio::Wallet::ClientError, e
46
- end
47
-
48
-
49
- def build_raw_transaction(transaction)
50
- args = { cmd: "rates" }
51
- response = client.rest_api(args)
52
- response[currency_id.upcase]
53
- end
54
-
55
- # def create_eth_transaction(transaction, options = {})
56
- # amount = convert_to_base_unit(transaction.amount)
57
- # hop = true unless options.slice(:gas_price).present?
58
-
59
- # fee_estimate = fee_estimate(amount.to_s, hop)
60
-
61
- # if transaction.options.present? && transaction.options[:gas_price].present?
62
- # options[:gas_price] = transaction.options[:gas_price]
63
- # else
64
- # options[:gas_price] = fee_estimate['minGasPrice'].to_i
65
- # end
66
-
67
- # response = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
68
- # address: transaction.to_address.to_s,
69
- # amount: amount.to_s,
70
- # walletPassphrase: coinpayment_wallet_passphrase,
71
- # gas: options.fetch(:gas_limit).to_i,
72
- # gasPrice: options.fetch(:gas_price).to_i,
73
- # hop: hop
74
- # }.compact)
75
-
76
- # if response['feeString'].present?
77
- # fee = convert_from_base_unit(response['feeString'])
78
- # transaction.fee = fee
79
- # end
80
-
81
- # transaction.hash = normalize_txid(response['txid'])
82
- # transaction.fee_currency_id = erc20_currency_id
83
- # transaction.options = options
84
- # transaction
85
- # end
86
-
87
- # def fee_estimate(amount, hop)
88
- # client.rest_api(:get, "#{erc20_currency_id}/tx/fee", { amount: amount, hop: hop }.compact)
89
- # end
90
-
91
- def load_balance!
92
- args = { cmd: "balances" }
93
- response = client.rest_api(args)
94
- response[currency_id.upcase]['balancef']
95
- rescue Coinpaymentnew::Client::Error => e
96
- raise Peatio::Wallet::ClientError, e
97
- end
98
-
99
- # def load_erc20_balance!
100
- # response = client.rest_api(:get, "#{erc20_currency_id}/wallet/#{wallet_id}?allTokens=true")
101
- # convert_from_base_unit(response.dig('tokens', currency_id, 'balanceString'))
102
- # rescue Coinpayment::Client::Error => e
103
- # raise Peatio::Wallet::ClientError, e
104
- # end
105
-
106
- def trigger_webhook_event(request)
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
114
-
115
- if request.params['ipn_type'] == 'deposit'
116
- transactions = fetch_transfer!(request.params['txn_id'])
117
- return transactions
118
- end
119
- end
120
-
121
- # def register_webhooks!(url)
122
- # transfer_webhook(url)
123
- # address_confirmation_webhook(url)
124
- # end
125
-
126
- # def fetch_address_id(address)
127
- # currency = erc20_currency_id
128
- # client.rest_api(:get, "#{currency}/wallet/#{wallet_id}/address/#{address}")
129
- # .fetch('id')
130
- # rescue Coinpayment::Client::Error => e
131
- # raise Peatio::Wallet::ClientError, e
132
- # end
133
-
134
- def fetch_transfer!(id)
135
- args = { cmd: "get_tx_info", txid: id }
136
- response = client.rest_api(args)
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
152
- raise Peatio::Wallet::ClientError, e
153
- end
154
-
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
164
-
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
174
-
175
- def parse_entries(entries)
176
- entries.map do |e|
177
- e if e["valueString"].to_i.positive?
178
- end.compact
179
- end
180
-
181
- def client
182
- uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
183
- 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
-
186
- @client ||= Client.new(uri, access_token, access_token2)
187
- end
188
-
189
- def build_address(address, memo)
190
- "#{address}?memoId=#{memo['value']}"
191
- end
192
-
193
- # All these functions will have to be done with the coin set to eth or teth
194
- # since that is the actual coin type being used.
195
- def erc20_currency_id
196
- return 'eth' if @currency.fetch(:options).slice(:erc20_contract_address).present?
197
-
198
- currency_id
199
- end
200
-
201
- def xlm_memo(address)
202
- build_xlm_memo(address) if @currency.fetch(:id) == 'xlm'
203
- end
204
-
205
- def build_xlm_memo(address)
206
- case address.split('?').last.split('=').first
207
- when 'memoId'
208
- memo_value_from(address, 'memoId')
209
- when 'memoText'
210
- memo_value_from(address, 'memoText')
211
- when 'memoHash'
212
- memo_value_from(address, 'memoHash')
213
- when 'memoReturn'
214
- memo_value_from(address, 'memoReturn')
215
- end
216
- end
217
-
218
- def memo_value_from(address, type)
219
- memo_value = address.partition(type + '=').last
220
- return { type: XLM_MEMO_TYPES[type.to_sym], value: memo_value } if memo_value.present?
221
- end
222
-
223
- def currency_id
224
- @currency.fetch(:id) { raise Peatio::Wallet::MissingSettingError, :id }
225
- end
226
-
227
- def coinpayment_wallet_passphrase
228
- @wallet.fetch(:secret)
229
- end
230
-
231
- def wallet_id
232
- @wallet.fetch(:wallet_id)
233
- end
234
-
235
- def normalize_address(address)
236
- if @currency.fetch(:id) == 'xlm'
237
- address.split('?').first
238
- else
239
- address
240
- end
241
- end
242
-
243
- def normalize_txid(txid)
244
- txid.downcase
245
- end
246
-
247
- def convert_from_base_unit(value)
248
- value.to_d / @currency.fetch(:base_factor)
249
- end
250
-
251
- def convert_to_base_unit(value)
252
- x = value.to_d * @currency.fetch(:base_factor)
253
- unless (x % 1).zero?
254
- raise Peatio::WalletClient::Error,
255
- "Failed to convert value to base (smallest) unit because it exceeds the maximum precision: " \
256
- "#{value.to_d} - #{x.to_d} must be equal to zero."
257
- end
258
- x.to_i
259
- end
260
-
261
- def time_difference_in_minutes(updated_at)
262
- (Time.now - updated_at)/60
263
- end
264
-
265
- def define_transaction_state(state)
266
- if state >= 100
267
- "success"
268
- elsif state >= 0 and state <= 99
269
- 'pending'
270
- else
271
- 'failed'
272
- end
273
- end
274
- end
275
- end
276
- 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(currency_id.upcase, {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
@@ -11,6 +11,7 @@ module Peatio
11
11
  require "bigdecimal"
12
12
  require "bigdecimal/util"
13
13
 
14
+ require_relative "../../config/initializers/coinpayments"
14
15
  require_relative "coinpaymentnew/blockchain"
15
16
  require_relative "coinpaymentnew/client"
16
17
  require_relative "coinpaymentnew/wallet"
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.9
4
+ version: 1.0.3
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-28 00:00:00.000000000 Z
11
+ date: 2021-12-02 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