peatio-counosx 2.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +152 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/blockchains.yml +10 -0
- data/config/currencies.yml +18 -0
- data/config/wallets.yml +44 -0
- data/docs/integration.md +29 -0
- data/docs/json-rpc.md +29 -0
- data/docs/testnet.md +3 -0
- data/lib/peatio/counosx.rb +18 -0
- data/lib/peatio/counosx/blockchain.rb +85 -0
- data/lib/peatio/counosx/client.rb +60 -0
- data/lib/peatio/counosx/hooks.rb +42 -0
- data/lib/peatio/counosx/railtie.rb +13 -0
- data/lib/peatio/counosx/version.rb +5 -0
- data/lib/peatio/counosx/wallet.rb +63 -0
- data/peatio-counosx.gemspec +39 -0
- metadata +233 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 54cf2401d0a22a0e13091aa9a7403ff935ccece72fcb221b09e7c346ff427bb1
|
4
|
+
data.tar.gz: aab8ee470543634b90d05fda08dc7303e49ad2eae17357fbc125d6cc9d09d0e2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ac8c304b41464328a2ac824cf1bd9e7973a9ffc04222a8e3a6f8e9aa5e22ddd69569f38067513f071bf3dddcb91a3e08a0051f026470493d090075acc24a5754
|
7
|
+
data.tar.gz: 593afeecca3827dbdf1f826029c10d55179cc1b4086c3e3dbc1535829984ff281ba19554c1bf3601e1dba2e6e71d3926b5a6f6aa7112d08a865aff2e3da6bbc1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
peatio-counosx (2.6.1)
|
5
|
+
activesupport (~> 5.2.3)
|
6
|
+
better-faraday (~> 1.0.5)
|
7
|
+
faraday (~> 0.15.4)
|
8
|
+
memoist (~> 0.16.0)
|
9
|
+
net-http-persistent (~> 3.0.1)
|
10
|
+
peatio (>= 0.6.3)
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: https://rubygems.org/
|
14
|
+
specs:
|
15
|
+
activemodel (5.2.4.3)
|
16
|
+
activesupport (= 5.2.4.3)
|
17
|
+
activesupport (5.2.4.3)
|
18
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
+
i18n (>= 0.7, < 2)
|
20
|
+
minitest (~> 5.1)
|
21
|
+
tzinfo (~> 1.1)
|
22
|
+
addressable (2.7.0)
|
23
|
+
public_suffix (>= 2.0.2, < 5.0)
|
24
|
+
amq-protocol (2.3.1)
|
25
|
+
amqp (1.8.0)
|
26
|
+
amq-protocol (>= 2.2.0)
|
27
|
+
eventmachine
|
28
|
+
better-faraday (1.0.8)
|
29
|
+
activesupport (>= 4.0, < 6.0)
|
30
|
+
faraday (~> 0.12)
|
31
|
+
bunny (2.15.0)
|
32
|
+
amq-protocol (~> 2.3, >= 2.3.1)
|
33
|
+
byebug (11.1.1)
|
34
|
+
clamp (1.3.1)
|
35
|
+
coderay (1.1.2)
|
36
|
+
concurrent-ruby (1.1.6)
|
37
|
+
connection_pool (2.2.3)
|
38
|
+
cookiejar (0.3.3)
|
39
|
+
crack (0.4.3)
|
40
|
+
safe_yaml (~> 1.0.0)
|
41
|
+
daemons (1.3.1)
|
42
|
+
diff-lcs (1.3)
|
43
|
+
em-http-request (1.1.6)
|
44
|
+
addressable (>= 2.3.4)
|
45
|
+
cookiejar (!= 0.3.1)
|
46
|
+
em-socksify (>= 0.3)
|
47
|
+
eventmachine (>= 1.0.3)
|
48
|
+
http_parser.rb (>= 0.6.0)
|
49
|
+
em-socksify (0.3.2)
|
50
|
+
eventmachine (>= 1.0.0.beta.4)
|
51
|
+
em-synchrony (1.0.6)
|
52
|
+
eventmachine (>= 1.0.0.beta.1)
|
53
|
+
em-websocket (0.5.1)
|
54
|
+
eventmachine (>= 0.12.9)
|
55
|
+
http_parser.rb (~> 0.6.0)
|
56
|
+
eventmachine (1.2.7)
|
57
|
+
faraday (0.15.4)
|
58
|
+
multipart-post (>= 1.2, < 3)
|
59
|
+
faraday_middleware (0.13.1)
|
60
|
+
faraday (>= 0.7.4, < 1.0)
|
61
|
+
faye (1.3.0)
|
62
|
+
cookiejar (>= 0.3.0)
|
63
|
+
em-http-request (>= 0.3.0)
|
64
|
+
eventmachine (>= 0.12.0)
|
65
|
+
faye-websocket (>= 0.9.1)
|
66
|
+
multi_json (>= 1.0.0)
|
67
|
+
rack (>= 1.0.0)
|
68
|
+
websocket-driver (>= 0.5.1)
|
69
|
+
faye-websocket (0.10.9)
|
70
|
+
eventmachine (>= 0.12.0)
|
71
|
+
websocket-driver (>= 0.5.1)
|
72
|
+
hashdiff (1.0.1)
|
73
|
+
http_parser.rb (0.6.0)
|
74
|
+
i18n (1.8.3)
|
75
|
+
concurrent-ruby (~> 1.0)
|
76
|
+
jwt (2.2.1)
|
77
|
+
memoist (0.16.2)
|
78
|
+
method_source (1.0.0)
|
79
|
+
minitest (5.14.1)
|
80
|
+
mocha (1.11.2)
|
81
|
+
multi_json (1.14.1)
|
82
|
+
multipart-post (2.1.1)
|
83
|
+
mysql2 (0.5.3)
|
84
|
+
net-http-persistent (3.0.1)
|
85
|
+
connection_pool (~> 2.2)
|
86
|
+
peatio (2.6.1)
|
87
|
+
activemodel (> 5.2, <= 6.0.0)
|
88
|
+
amqp
|
89
|
+
bunny
|
90
|
+
clamp
|
91
|
+
em-synchrony (~> 1.0)
|
92
|
+
em-websocket
|
93
|
+
eventmachine
|
94
|
+
faraday_middleware (~> 0.13.1)
|
95
|
+
faye (~> 1.2)
|
96
|
+
jwt
|
97
|
+
mysql2
|
98
|
+
prometheus-client
|
99
|
+
thin
|
100
|
+
prometheus-client (2.1.0)
|
101
|
+
pry (0.13.0)
|
102
|
+
coderay (~> 1.1)
|
103
|
+
method_source (~> 1.0)
|
104
|
+
pry-byebug (3.9.0)
|
105
|
+
byebug (~> 11.0)
|
106
|
+
pry (~> 0.13.0)
|
107
|
+
public_suffix (4.0.4)
|
108
|
+
rack (2.2.3)
|
109
|
+
rake (13.0.1)
|
110
|
+
rspec (3.9.0)
|
111
|
+
rspec-core (~> 3.9.0)
|
112
|
+
rspec-expectations (~> 3.9.0)
|
113
|
+
rspec-mocks (~> 3.9.0)
|
114
|
+
rspec-core (3.9.1)
|
115
|
+
rspec-support (~> 3.9.1)
|
116
|
+
rspec-expectations (3.9.1)
|
117
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
118
|
+
rspec-support (~> 3.9.0)
|
119
|
+
rspec-mocks (3.9.1)
|
120
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
121
|
+
rspec-support (~> 3.9.0)
|
122
|
+
rspec-support (3.9.2)
|
123
|
+
safe_yaml (1.0.5)
|
124
|
+
thin (1.7.2)
|
125
|
+
daemons (~> 1.0, >= 1.0.9)
|
126
|
+
eventmachine (~> 1.0, >= 1.0.4)
|
127
|
+
rack (>= 1, < 3)
|
128
|
+
thread_safe (0.3.6)
|
129
|
+
tzinfo (1.2.7)
|
130
|
+
thread_safe (~> 0.1)
|
131
|
+
webmock (3.8.3)
|
132
|
+
addressable (>= 2.3.6)
|
133
|
+
crack (>= 0.3.2)
|
134
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
135
|
+
websocket-driver (0.7.2)
|
136
|
+
websocket-extensions (>= 0.1.0)
|
137
|
+
websocket-extensions (0.1.5)
|
138
|
+
|
139
|
+
PLATFORMS
|
140
|
+
ruby
|
141
|
+
|
142
|
+
DEPENDENCIES
|
143
|
+
bundler (~> 1.16)
|
144
|
+
mocha (~> 1.8)
|
145
|
+
peatio-counosx!
|
146
|
+
pry-byebug
|
147
|
+
rake (~> 13.0)
|
148
|
+
rspec (~> 3.0)
|
149
|
+
webmock (~> 3.5)
|
150
|
+
|
151
|
+
BUNDLED WITH
|
152
|
+
1.17.3
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "peatio/counosx"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
- key: ltc-testnet
|
2
|
+
name: CounosX Testnet
|
3
|
+
client: counosx # API client name.
|
4
|
+
server: http://user:password@127.0.0.1:18332 # Public CounosX 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: CounosX
|
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: {}
|
data/config/wallets.yml
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
- name: CounosX 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: counosxd # Gateway client name.
|
11
|
+
settings:
|
12
|
+
#
|
13
|
+
# counosxd gateway client settings.
|
14
|
+
uri: http://user:password@127.0.0.1:19332
|
15
|
+
|
16
|
+
- name: CounosX 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: counosxd # Gateway client name.
|
26
|
+
settings:
|
27
|
+
#
|
28
|
+
# Counosxd gateway client settings.
|
29
|
+
uri: http://user:password@127.0.0.1:19332
|
30
|
+
|
31
|
+
- name: CounosX 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: counosxd # Gateway client name.
|
41
|
+
settings:
|
42
|
+
#
|
43
|
+
# Counosxd gateway client settings.
|
44
|
+
uri: http://user:password@127.0.0.1:19332
|
data/docs/integration.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Integration.
|
2
|
+
|
3
|
+
For Peatio CounosX plugin integration you need to do the following steps:
|
4
|
+
|
5
|
+
## Image Build.
|
6
|
+
|
7
|
+
1. Add peatio-counosx gem into your Gemfile.plugin
|
8
|
+
```ruby
|
9
|
+
gem 'peatio-counosx', '~> 0.1.0'
|
10
|
+
```
|
11
|
+
|
12
|
+
2. Run `bundle install` for updating Gemfile.lock
|
13
|
+
|
14
|
+
3. Build custom Peatio [docker image with CounosX plugin](https://github.com/rubykube/peatio/blob/master/docs/plugins.md#build)
|
15
|
+
|
16
|
+
4. Push your image using `docker push`
|
17
|
+
|
18
|
+
5. Update your deployment to use image with peatio-counosx gem
|
19
|
+
|
20
|
+
## Peatio Configuration.
|
21
|
+
|
22
|
+
1. Create CounosX Blockchain [config example](../config/blockchains.yml).
|
23
|
+
* No additional steps are needed
|
24
|
+
|
25
|
+
2. Create CounosX Currency [config example](../config/currencies.yml).
|
26
|
+
* No additional steps are needed
|
27
|
+
|
28
|
+
3. Create CounosX Wallets [config example](../config/wallets.yml)(deposit and hot wallets are required).
|
29
|
+
* No additional steps are needed
|
data/docs/json-rpc.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# JSON RPC
|
2
|
+
|
3
|
+
The next list of JSON RPC calls where used for plugin development.
|
4
|
+
For response examples see spec/resources:
|
5
|
+
|
6
|
+
* getbalance
|
7
|
+
|
8
|
+
`curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getbalance", "params": [] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:19332`
|
9
|
+
* getblock
|
10
|
+
|
11
|
+
`curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblock", "params": ["5a471d4fd13d8bc3351e4d3a618fa55993326014b925346d8e9272e271e97c4e", 2] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:19332`
|
12
|
+
* getblockcount
|
13
|
+
|
14
|
+
`curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockcount", "params": [] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:19332`
|
15
|
+
* getblockhash
|
16
|
+
|
17
|
+
`curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockhash", "params": [40500] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:19332 `
|
18
|
+
* getnewaddress
|
19
|
+
|
20
|
+
`curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getnewaddress", "params": [] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:19332 `
|
21
|
+
* listaddressgroupings
|
22
|
+
|
23
|
+
`curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "listaddressgroupings", "params": [] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:19332`
|
24
|
+
* sendtoaddress
|
25
|
+
|
26
|
+
`curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "sendtoaddress", "params": ["QRnrwkUBQ2E4ZJ3bj8jvn4Nwx4nJ2U7wXF", 0.11] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:19332`
|
27
|
+
* methodnotfound
|
28
|
+
|
29
|
+
`curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "methodnotfound", "params": [] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:19332`
|
data/docs/testnet.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "active_support/core_ext/object/blank"
|
2
|
+
require "active_support/core_ext/enumerable"
|
3
|
+
require "peatio"
|
4
|
+
|
5
|
+
module Peatio
|
6
|
+
module CounosX
|
7
|
+
require "bigdecimal"
|
8
|
+
require "bigdecimal/util"
|
9
|
+
|
10
|
+
require "peatio/counosx/blockchain"
|
11
|
+
require "peatio/counosx/client"
|
12
|
+
require "peatio/counosx/wallet"
|
13
|
+
|
14
|
+
require "peatio/counosx/hooks"
|
15
|
+
|
16
|
+
require "peatio/counosx/version"
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
|
2
|
+
module Peatio
|
3
|
+
module CounosX
|
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
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'memoist'
|
4
|
+
require 'faraday'
|
5
|
+
require 'better-faraday'
|
6
|
+
|
7
|
+
module Peatio
|
8
|
+
module CounosX
|
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
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Peatio
|
2
|
+
module CounosX
|
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
|
+
"CounosX blockchain version requiremnt was not suttisfied by Peatio::Blockchain.",
|
13
|
+
"CounosX 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
|
+
"CounosX wallet version requiremnt was not suttisfied by Peatio::Wallet.",
|
22
|
+
"CounosX 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[:counosx] = CounosX::Blockchain
|
30
|
+
Peatio::Wallet.registry[:counosxd] = CounosX::Wallet
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if defined?(Rails::Railtie)
|
35
|
+
require "peatio/counosx/railtie"
|
36
|
+
else
|
37
|
+
check_compatibility
|
38
|
+
register
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Peatio
|
2
|
+
module CounosX
|
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
|
+
{ address: client.json_rpc(:getnewaddress) }
|
29
|
+
rescue CounosX::Client::Error => e
|
30
|
+
raise Peatio::Wallet::ClientError, e
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_transaction!(transaction, options = {})
|
34
|
+
txid = client.json_rpc(:sendtoaddress,
|
35
|
+
[
|
36
|
+
transaction.to_address,
|
37
|
+
transaction.amount,
|
38
|
+
'',
|
39
|
+
'',
|
40
|
+
options[:subtract_fee].to_s == 'true' # subtract fee from transaction amount.
|
41
|
+
])
|
42
|
+
transaction.hash = txid
|
43
|
+
transaction
|
44
|
+
rescue CounosX::Client::Error => e
|
45
|
+
raise Peatio::Wallet::ClientError, e
|
46
|
+
end
|
47
|
+
|
48
|
+
def load_balance!
|
49
|
+
client.json_rpc(:getbalance).to_d
|
50
|
+
|
51
|
+
rescue CounosX::Client::Error => e
|
52
|
+
raise Peatio::Wallet::ClientError, e
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def client
|
58
|
+
uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
|
59
|
+
@client ||= Client.new(uri)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "peatio/counosx/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "peatio-counosx"
|
8
|
+
spec.version = Peatio::CounosX::VERSION
|
9
|
+
spec.authors = ["Yaroslav S."]
|
10
|
+
spec.email = ["ysavchuk@heliostech.fr"]
|
11
|
+
|
12
|
+
spec.summary = %q{Gem for extending Peatio plugable system with CounosX implementation.}
|
13
|
+
spec.description = %q{CounosX Peatio gem which implements Peatio::Blockchain::Abstract & Peatio::Wallet::Abstract.}
|
14
|
+
spec.homepage = "https://openware.com/"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "activesupport", "~> 5.2.3"
|
27
|
+
spec.add_dependency "better-faraday", "~> 1.0.5"
|
28
|
+
spec.add_dependency "faraday", "~> 0.15.4"
|
29
|
+
spec.add_dependency "memoist", "~> 0.16.0"
|
30
|
+
spec.add_dependency "peatio", ">= 0.6.3"
|
31
|
+
spec.add_dependency 'net-http-persistent', '~> 3.0.1'
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
34
|
+
spec.add_development_dependency "mocha", "~> 1.8"
|
35
|
+
spec.add_development_dependency "pry-byebug"
|
36
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
38
|
+
spec.add_development_dependency "webmock", "~> 3.5"
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,233 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: peatio-counosx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.6.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yaroslav S.
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.2.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: better-faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.15.4
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.15.4
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: memoist
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.16.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.16.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: peatio
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.6.3
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.6.3
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: net-http-persistent
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.0.1
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.0.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.16'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.16'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: mocha
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.8'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.8'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry-byebug
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rake
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '13.0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '13.0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rspec
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '3.0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '3.0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: webmock
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '3.5'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '3.5'
|
181
|
+
description: CounosX Peatio gem which implements Peatio::Blockchain::Abstract & Peatio::Wallet::Abstract.
|
182
|
+
email:
|
183
|
+
- ysavchuk@heliostech.fr
|
184
|
+
executables: []
|
185
|
+
extensions: []
|
186
|
+
extra_rdoc_files: []
|
187
|
+
files:
|
188
|
+
- ".gitignore"
|
189
|
+
- ".rspec"
|
190
|
+
- ".travis.yml"
|
191
|
+
- Gemfile
|
192
|
+
- Gemfile.lock
|
193
|
+
- Rakefile
|
194
|
+
- bin/console
|
195
|
+
- bin/setup
|
196
|
+
- config/blockchains.yml
|
197
|
+
- config/currencies.yml
|
198
|
+
- config/wallets.yml
|
199
|
+
- docs/integration.md
|
200
|
+
- docs/json-rpc.md
|
201
|
+
- docs/testnet.md
|
202
|
+
- lib/peatio/counosx.rb
|
203
|
+
- lib/peatio/counosx/blockchain.rb
|
204
|
+
- lib/peatio/counosx/client.rb
|
205
|
+
- lib/peatio/counosx/hooks.rb
|
206
|
+
- lib/peatio/counosx/railtie.rb
|
207
|
+
- lib/peatio/counosx/version.rb
|
208
|
+
- lib/peatio/counosx/wallet.rb
|
209
|
+
- peatio-counosx.gemspec
|
210
|
+
homepage: https://openware.com/
|
211
|
+
licenses:
|
212
|
+
- MIT
|
213
|
+
metadata: {}
|
214
|
+
post_install_message:
|
215
|
+
rdoc_options: []
|
216
|
+
require_paths:
|
217
|
+
- lib
|
218
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
223
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
224
|
+
requirements:
|
225
|
+
- - ">="
|
226
|
+
- !ruby/object:Gem::Version
|
227
|
+
version: '0'
|
228
|
+
requirements: []
|
229
|
+
rubygems_version: 3.0.8
|
230
|
+
signing_key:
|
231
|
+
specification_version: 4
|
232
|
+
summary: Gem for extending Peatio plugable system with CounosX implementation.
|
233
|
+
test_files: []
|