peatio-bitcoincash 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.travis.yml +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +114 -0
- data/LICENSE.txt +21 -0
- data/README.md +67 -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 +47 -0
- data/docs/integration.md +29 -0
- data/docs/json-rpc.md +32 -0
- data/docs/testnet.md +6 -0
- data/lib/peatio/bitcoincash.rb +22 -0
- data/lib/peatio/bitcoincash/blockchain.rb +87 -0
- data/lib/peatio/bitcoincash/client.rb +62 -0
- data/lib/peatio/bitcoincash/concerns/cash_address_format.rb +7 -0
- data/lib/peatio/bitcoincash/hooks.rb +42 -0
- data/lib/peatio/bitcoincash/railtie.rb +13 -0
- data/lib/peatio/bitcoincash/version.rb +5 -0
- data/lib/peatio/bitcoincash/wallet.rb +61 -0
- data/peatio-bitcoincash.gemspec +39 -0
- metadata +237 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6882a856d028ce52c3838de798ca00c57ab7a41aa00d44dc70c94b9eaabdd2fc
|
4
|
+
data.tar.gz: 9eaf079c05d42a22cfc63ec2f6e71b685a1d90afdcb015145a4a1b5469b915d8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 92da7224e97f0e738bfafa688207ae189de407d6e7e6cbe55637fc1c9a10d5145cd9a747c31709ae5ac6723674a321819bd278535f74a9eba3b1f47813737655
|
7
|
+
data.tar.gz: acc76707127a4e7f408bdb83ceae060c9d1e4e4d5bd423d89d01a7807bf429c05728a2ee1aeb89eba093876000133e384323ed23bc67355a4f67d83a554e5418
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
peatio-bitcoincash (0.1.0)
|
5
|
+
activesupport (~> 5.2.3)
|
6
|
+
better-faraday (~> 1.0.5)
|
7
|
+
cash-addr (~> 0.2.0)
|
8
|
+
faraday (~> 0.15.4)
|
9
|
+
memoist (~> 0.16.0)
|
10
|
+
peatio (~> 0.6.1)
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: https://rubygems.org/
|
14
|
+
specs:
|
15
|
+
activemodel (5.2.3)
|
16
|
+
activesupport (= 5.2.3)
|
17
|
+
activesupport (5.2.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.6.0)
|
23
|
+
public_suffix (>= 2.0.2, < 4.0)
|
24
|
+
amq-protocol (2.3.0)
|
25
|
+
amqp (1.8.0)
|
26
|
+
amq-protocol (>= 2.2.0)
|
27
|
+
eventmachine
|
28
|
+
base58 (0.2.3)
|
29
|
+
better-faraday (1.0.5)
|
30
|
+
activesupport (>= 4.0, < 6.0)
|
31
|
+
faraday (~> 0.12)
|
32
|
+
bunny (2.14.2)
|
33
|
+
amq-protocol (~> 2.3, >= 2.3.0)
|
34
|
+
byebug (11.0.1)
|
35
|
+
cash-addr (0.2.0)
|
36
|
+
base58 (~> 0.2.2)
|
37
|
+
clamp (1.3.0)
|
38
|
+
coderay (1.1.2)
|
39
|
+
concurrent-ruby (1.1.5)
|
40
|
+
crack (0.4.3)
|
41
|
+
safe_yaml (~> 1.0.0)
|
42
|
+
diff-lcs (1.3)
|
43
|
+
em-websocket (0.5.1)
|
44
|
+
eventmachine (>= 0.12.9)
|
45
|
+
http_parser.rb (~> 0.6.0)
|
46
|
+
eventmachine (1.2.7)
|
47
|
+
faraday (0.15.4)
|
48
|
+
multipart-post (>= 1.2, < 3)
|
49
|
+
hashdiff (0.3.9)
|
50
|
+
http_parser.rb (0.6.0)
|
51
|
+
i18n (1.6.0)
|
52
|
+
concurrent-ruby (~> 1.0)
|
53
|
+
jwt (2.2.1)
|
54
|
+
memoist (0.16.0)
|
55
|
+
metaclass (0.0.4)
|
56
|
+
method_source (0.9.2)
|
57
|
+
minitest (5.11.3)
|
58
|
+
mocha (1.8.0)
|
59
|
+
metaclass (~> 0.0.1)
|
60
|
+
multipart-post (2.1.1)
|
61
|
+
mysql2 (0.5.2)
|
62
|
+
peatio (0.6.1)
|
63
|
+
activemodel (~> 5.2.3)
|
64
|
+
amqp
|
65
|
+
bunny
|
66
|
+
clamp
|
67
|
+
em-websocket
|
68
|
+
eventmachine
|
69
|
+
jwt
|
70
|
+
mysql2
|
71
|
+
pry (0.12.2)
|
72
|
+
coderay (~> 1.1.0)
|
73
|
+
method_source (~> 0.9.0)
|
74
|
+
pry-byebug (3.7.0)
|
75
|
+
byebug (~> 11.0)
|
76
|
+
pry (~> 0.10)
|
77
|
+
public_suffix (3.0.3)
|
78
|
+
rake (10.5.0)
|
79
|
+
rspec (3.8.0)
|
80
|
+
rspec-core (~> 3.8.0)
|
81
|
+
rspec-expectations (~> 3.8.0)
|
82
|
+
rspec-mocks (~> 3.8.0)
|
83
|
+
rspec-core (3.8.0)
|
84
|
+
rspec-support (~> 3.8.0)
|
85
|
+
rspec-expectations (3.8.3)
|
86
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
87
|
+
rspec-support (~> 3.8.0)
|
88
|
+
rspec-mocks (3.8.0)
|
89
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
90
|
+
rspec-support (~> 3.8.0)
|
91
|
+
rspec-support (3.8.0)
|
92
|
+
safe_yaml (1.0.5)
|
93
|
+
thread_safe (0.3.6)
|
94
|
+
tzinfo (1.2.5)
|
95
|
+
thread_safe (~> 0.1)
|
96
|
+
webmock (3.5.1)
|
97
|
+
addressable (>= 2.3.6)
|
98
|
+
crack (>= 0.3.2)
|
99
|
+
hashdiff
|
100
|
+
|
101
|
+
PLATFORMS
|
102
|
+
ruby
|
103
|
+
|
104
|
+
DEPENDENCIES
|
105
|
+
bundler (~> 1.17)
|
106
|
+
mocha (~> 1.8)
|
107
|
+
peatio-bitcoincash!
|
108
|
+
pry-byebug
|
109
|
+
rake (~> 10.0)
|
110
|
+
rspec (~> 3.0)
|
111
|
+
webmock (~> 3.5)
|
112
|
+
|
113
|
+
BUNDLED WITH
|
114
|
+
1.17.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Dinesh Chohda
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Peatio::Bitcoincash
|
2
|
+
|
3
|
+
Peatio bitcoincash plugin for Rubykube stack
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'peatio-bitcoincash'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install peatio-bitcoincash
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
For Peatio Bitcoincash plugin integration you need to do the following steps:
|
24
|
+
|
25
|
+
### Image Build.
|
26
|
+
|
27
|
+
1. Add peatio-bitcoincash gem into your Gemfile.plugin
|
28
|
+
```ruby
|
29
|
+
gem 'peatio-bitcoincash', '~> 0.1.0'
|
30
|
+
```
|
31
|
+
|
32
|
+
2. Run `bundle install` for updating Gemfile.lock
|
33
|
+
|
34
|
+
3. Build custom Peatio [docker image with Bitcoincash plugin](https://github.com/rubykube/peatio/blob/master/docs/plugins.md#build)
|
35
|
+
|
36
|
+
4. Push your image using `docker push`
|
37
|
+
|
38
|
+
5. Update your deployment to use image with peatio-bitcoincash gem
|
39
|
+
|
40
|
+
### Peatio Configuration.
|
41
|
+
|
42
|
+
1. Create Bitcoincash Blockchain [config example](config/blockchains.yml).
|
43
|
+
* No additional steps are needed
|
44
|
+
|
45
|
+
2. Create Bitcoincash Currency [config example](config/currencies.yml).
|
46
|
+
* No additional steps are needed
|
47
|
+
|
48
|
+
3. Create Bitcoincash Wallets [config example](config/wallets.yml)(deposit and hot wallets are required).
|
49
|
+
* No additional steps are needed
|
50
|
+
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
Plugin development [example](https://github.com/rubykube/peatio/blob/master/docs/coins/development.md).
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rubykube/peatio-bitcoincash.
|
59
|
+
|
60
|
+
## License
|
61
|
+
|
62
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
63
|
+
|
64
|
+
## Consulting
|
65
|
+
|
66
|
+
You can contact Openware for finding certified vendors:
|
67
|
+
[Openware.com](https://www.openware.com)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "peatio/bitcoincash"
|
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: bch-testnet
|
2
|
+
name: Bitcoincash Testnet
|
3
|
+
client: bitcoincash # API client name.
|
4
|
+
server: http://user:password@127.0.0.1:18332 # Public Bitcoincash 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://www.blocktrail.com/tBCC/address/#{address}
|
9
|
+
transaction: https://www.blocktrail.com/tBCC/tx/#{txid}
|
10
|
+
status: active
|
@@ -0,0 +1,18 @@
|
|
1
|
+
- id: bch
|
2
|
+
name: Bitcoin Cash
|
3
|
+
blockchain_key: bch-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.0000748
|
12
|
+
min_collection_amount: 0.0000748
|
13
|
+
withdraw_limit_24h: 0.1
|
14
|
+
withdraw_limit_72h: 0.2
|
15
|
+
deposit_fee: 0
|
16
|
+
withdraw_fee: 0
|
17
|
+
position: 4
|
18
|
+
options: {}
|
data/config/wallets.yml
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
- name: Bitcoincash Deposit Wallet
|
2
|
+
blockchain_key: bch-testnet
|
3
|
+
currency_id: bch
|
4
|
+
# Address where deposits will be collected to.
|
5
|
+
# IMPORTANT: Use Cash Address Format
|
6
|
+
address: 'bchtest:qqpkpjpsv5ngwjet9alaktdhklgcrlf9qg9l4ta2w5' # IMPORTANT: Always wrap this value in quotes!
|
7
|
+
kind: deposit # Wallet kind (deposit, hot, warm, cold or fee).
|
8
|
+
nsig: 1 # Number of signatures required for performing withdraw.
|
9
|
+
max_balance: 0.0
|
10
|
+
status: active
|
11
|
+
gateway: bitcoincashd # Gateway client name.
|
12
|
+
settings:
|
13
|
+
#
|
14
|
+
# Bitcoincashd gateway client settings.
|
15
|
+
uri: http://user:password@127.0.0.1:18332
|
16
|
+
|
17
|
+
- name: Bitcoincash Hot Wallet
|
18
|
+
blockchain_key: bch-testnet
|
19
|
+
currency_id: bch
|
20
|
+
# Address where deposits will be collected to.
|
21
|
+
# IMPORTANT: Use Cash Address Format
|
22
|
+
address: 'bchtest:qqpkpjpsv5ngwjet9alaktdhklgcrlf9qg9l4ta2w5' # IMPORTANT: Always wrap this value in quotes!
|
23
|
+
kind: hot # Wallet kind (deposit, hot, warm, cold or fee).
|
24
|
+
nsig: 1 # Number of signatures required for performing withdraw.
|
25
|
+
max_balance: 5.0
|
26
|
+
status: active
|
27
|
+
gateway: bitcoincashd # Gateway client name.
|
28
|
+
settings:
|
29
|
+
#
|
30
|
+
# Bitcoincashd gateway client settings.
|
31
|
+
uri: http://user:password@127.0.0.1:18332
|
32
|
+
|
33
|
+
- name: Bitcoincash Warm Wallet
|
34
|
+
blockchain_key: bch-testnet
|
35
|
+
currency_id: bch
|
36
|
+
# Address where deposits will be collected to.
|
37
|
+
# IMPORTANT: Use Cash Address Format
|
38
|
+
address: 'bchtest:qqpkpjpsv5ngwjet9alaktdhklgcrlf9qg9l4ta2w5' # IMPORTANT: Always wrap this value in quotes!
|
39
|
+
kind: warm # Wallet kind (deposit, hot, warm, cold or fee).
|
40
|
+
nsig: 1 # Number of signatures required for performing withdraw.
|
41
|
+
max_balance: 50.0
|
42
|
+
status: active
|
43
|
+
gateway: bitcoincashd # Gateway client name.
|
44
|
+
settings:
|
45
|
+
#
|
46
|
+
# Bitcoincashd gateway client settings.
|
47
|
+
uri: http://user:password@127.0.0.1:18332
|
data/docs/integration.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Integration.
|
2
|
+
|
3
|
+
For Peatio Bitcoincash plugin integration you need to do the following steps:
|
4
|
+
|
5
|
+
## Image Build.
|
6
|
+
|
7
|
+
1. Add peatio-bitcoincash gem into your Gemfile.plugin
|
8
|
+
```ruby
|
9
|
+
gem 'peatio-bitcoincash', '~> 0.1.0'
|
10
|
+
```
|
11
|
+
|
12
|
+
2. Run `bundle install` for updating Gemfile.lock
|
13
|
+
|
14
|
+
3. Build custom Peatio [docker image with Bitcoincash 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-bitcoincash gem
|
19
|
+
|
20
|
+
## Peatio Configuration.
|
21
|
+
|
22
|
+
1. Create Bitcoincash Blockchain [config example](../config/blockchains.yml).
|
23
|
+
* No additional steps are needed
|
24
|
+
|
25
|
+
2. Create Bitcoincash Currency [config example](../config/currencies.yml).
|
26
|
+
* No additional steps are needed
|
27
|
+
|
28
|
+
3. Create Bitcoincash 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,32 @@
|
|
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:18332`
|
9
|
+
* getblock
|
10
|
+
|
11
|
+
`curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblock", "params": ["5a471d4fd13d8bc3351e4d3a618fa55993326014b925346d8e9272e271e97c4e", true] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:18332`
|
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:18332`
|
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:18332 `
|
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:18332 `
|
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:18332`
|
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:18332`
|
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:18332`
|
30
|
+
* getrawtransaction
|
31
|
+
|
32
|
+
`curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getrawtransaction", "params": ['2164bbfd689de16790aaf847d024459545dd938be6a4266f6e04f12d2bf471a2', true] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:18332 `
|
data/docs/testnet.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "active_support/core_ext/object/blank"
|
2
|
+
require "active_support/core_ext/enumerable"
|
3
|
+
require "active_support/core_ext/string/inquiry"
|
4
|
+
require "peatio"
|
5
|
+
|
6
|
+
module Peatio
|
7
|
+
module Bitcoincash
|
8
|
+
require "bigdecimal"
|
9
|
+
require "bigdecimal/util"
|
10
|
+
require "cash_addr"
|
11
|
+
|
12
|
+
require "peatio/bitcoincash/concerns/cash_address_format"
|
13
|
+
|
14
|
+
require "peatio/bitcoincash/blockchain"
|
15
|
+
require "peatio/bitcoincash/client"
|
16
|
+
require "peatio/bitcoincash/wallet"
|
17
|
+
|
18
|
+
require "peatio/bitcoincash/hooks"
|
19
|
+
|
20
|
+
require "peatio/bitcoincash/version"
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
|
2
|
+
module Peatio
|
3
|
+
module Bitcoincash
|
4
|
+
# TODO: Processing of unconfirmed transactions from mempool isn't supported now.
|
5
|
+
class Blockchain < Peatio::Blockchain::Abstract
|
6
|
+
include CashAddressFormat
|
7
|
+
|
8
|
+
DEFAULT_FEATURES = {case_sensitive: true, cash_addr_format: true}.freeze
|
9
|
+
|
10
|
+
def initialize(custom_features = {})
|
11
|
+
@features = DEFAULT_FEATURES.merge(custom_features).slice(*SUPPORTED_FEATURES)
|
12
|
+
@settings = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure(settings = {})
|
16
|
+
# Clean client state during configure.
|
17
|
+
@client = nil
|
18
|
+
|
19
|
+
@settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
|
20
|
+
end
|
21
|
+
|
22
|
+
def fetch_block!(block_number)
|
23
|
+
block_hash = client.json_rpc(:getblockhash, [block_number])
|
24
|
+
|
25
|
+
client.json_rpc(:getblock, [block_hash, true])
|
26
|
+
.fetch('tx').each_with_object([]) do |tx, txs_array|
|
27
|
+
txs = build_transaction(client.json_rpc(:getrawtransaction, [tx, true])).map do |ntx|
|
28
|
+
Peatio::Transaction.new(ntx.merge(block_number: block_number))
|
29
|
+
end
|
30
|
+
txs_array.append(*txs)
|
31
|
+
end.yield_self { |txs_array| Peatio::Block.new(block_number, txs_array) }
|
32
|
+
rescue Client::Error => e
|
33
|
+
raise Peatio::Blockchain::ClientError, e
|
34
|
+
end
|
35
|
+
|
36
|
+
def latest_block_number
|
37
|
+
client.json_rpc(:getblockcount)
|
38
|
+
rescue Client::Error => e
|
39
|
+
raise Peatio::Blockchain::ClientError, e
|
40
|
+
end
|
41
|
+
|
42
|
+
def load_balance_of_address!(address, _currency_id)
|
43
|
+
address_with_balance = client.json_rpc(:listaddressgroupings)
|
44
|
+
.flatten(1)
|
45
|
+
.find { |addr| addr[0] == normalize_address(address) }
|
46
|
+
|
47
|
+
if address_with_balance.blank?
|
48
|
+
raise Peatio::Blockchain::UnavailableAddressBalanceError, normalize_address(address)
|
49
|
+
end
|
50
|
+
|
51
|
+
address_with_balance[1].to_d
|
52
|
+
rescue Client::Error => e
|
53
|
+
raise Peatio::Blockchain::ClientError, e
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def build_transaction(tx_hash)
|
59
|
+
tx_hash.fetch('vout')
|
60
|
+
.select do |entry|
|
61
|
+
entry.fetch('value').to_d > 0 &&
|
62
|
+
entry['scriptPubKey'].has_key?('addresses')
|
63
|
+
end
|
64
|
+
.each_with_object([]) do |entry, formatted_txs|
|
65
|
+
no_currency_tx =
|
66
|
+
{ hash: tx_hash['txid'], txout: entry['n'],
|
67
|
+
to_address: normalize_address(entry['scriptPubKey']['addresses'][0]),
|
68
|
+
amount: entry.fetch('value').to_d,
|
69
|
+
status: 'success' }
|
70
|
+
|
71
|
+
# Build transaction for each currency belonging to blockchain.
|
72
|
+
settings_fetch(:currencies).pluck(:id).each do |currency_id|
|
73
|
+
formatted_txs << no_currency_tx.merge(currency_id: currency_id)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def client
|
79
|
+
@client ||= Client.new(settings_fetch(:server))
|
80
|
+
end
|
81
|
+
|
82
|
+
def settings_fetch(key)
|
83
|
+
@settings.fetch(key) { raise Peatio::Blockchain::MissingSettingError, key.to_s }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'memoist'
|
2
|
+
require 'faraday'
|
3
|
+
require 'better-faraday'
|
4
|
+
|
5
|
+
module Peatio
|
6
|
+
module Bitcoincash
|
7
|
+
class Client
|
8
|
+
Error = Class.new(StandardError)
|
9
|
+
class ConnectionError < Error; end
|
10
|
+
|
11
|
+
class ResponseError < Error
|
12
|
+
def initialize(code, msg)
|
13
|
+
@code = code
|
14
|
+
@msg = msg
|
15
|
+
end
|
16
|
+
|
17
|
+
def message
|
18
|
+
"#{@msg} (#{@code})"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
extend Memoist
|
23
|
+
|
24
|
+
def initialize(endpoint)
|
25
|
+
@json_rpc_endpoint = URI.parse(endpoint)
|
26
|
+
end
|
27
|
+
|
28
|
+
def json_rpc(method, params = [])
|
29
|
+
response = connection.post \
|
30
|
+
'/',
|
31
|
+
{ jsonrpc: '1.0', method: method, params: params }.to_json,
|
32
|
+
{ 'Accept' => 'application/json',
|
33
|
+
'Content-Type' => 'application/json' }
|
34
|
+
response.assert_2xx!
|
35
|
+
response = JSON.parse(response.body)
|
36
|
+
response['error'].tap { |e| raise ResponseError.new(e['code'], e['message']) if e }
|
37
|
+
response.fetch('result')
|
38
|
+
rescue => e
|
39
|
+
if e.is_a?(Error)
|
40
|
+
raise e
|
41
|
+
elsif e.is_a?(Faraday::Error)
|
42
|
+
raise ConnectionError, e
|
43
|
+
else
|
44
|
+
raise Error, e
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def connection
|
51
|
+
Faraday.new(@json_rpc_endpoint).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
|
+
memoize :connection
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Peatio
|
2
|
+
module Bitcoincash
|
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
|
+
"Bitcoincash blockchain version requirement was not satisfied by Peatio::Blockchain.",
|
13
|
+
"Bitcoincash 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
|
+
"Bitcoincash wallet version requirement was not satisfied by Peatio::Wallet.",
|
22
|
+
"Bitcoincash 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[:bitcoincash] = Bitcoincash::Blockchain.new
|
30
|
+
Peatio::Wallet.registry[:bitcoincashd] = Bitcoincash::Wallet.new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if defined?(Rails::Railtie)
|
35
|
+
require "peatio/bitcoincash/railtie"
|
36
|
+
else
|
37
|
+
check_compatibility
|
38
|
+
register
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Peatio
|
2
|
+
module Bitcoincash
|
3
|
+
class Wallet < Peatio::Wallet::Abstract
|
4
|
+
include CashAddressFormat
|
5
|
+
|
6
|
+
def initialize(settings = {})
|
7
|
+
@settings = settings
|
8
|
+
end
|
9
|
+
|
10
|
+
def configure(settings = {})
|
11
|
+
# Clean client state during configure.
|
12
|
+
@client = nil
|
13
|
+
|
14
|
+
@settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
|
15
|
+
|
16
|
+
@wallet = @settings.fetch(:wallet) do
|
17
|
+
raise Peatio::Wallet::MissingSettingError, :wallet
|
18
|
+
end.slice(:uri, :address)
|
19
|
+
|
20
|
+
@currency = @settings.fetch(:currency) do
|
21
|
+
raise Peatio::Wallet::MissingSettingError, :currency
|
22
|
+
end.slice(:id, :base_factor, :options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_address!(_options = {})
|
26
|
+
{ address: client.json_rpc(:getnewaddress) }
|
27
|
+
rescue Bitcoincash::Client::Error => e
|
28
|
+
raise Peatio::Wallet::ClientError, e
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_transaction!(transaction, options = {})
|
32
|
+
txid = client.json_rpc(:sendtoaddress,
|
33
|
+
[
|
34
|
+
normalize_address(transaction.to_address),
|
35
|
+
transaction.amount,
|
36
|
+
'',
|
37
|
+
'',
|
38
|
+
options[:subtract_fee].to_s == 'true' # subtract fee from transaction amount.
|
39
|
+
])
|
40
|
+
transaction.hash = txid
|
41
|
+
transaction
|
42
|
+
rescue Bitcoincash::Client::Error => e
|
43
|
+
raise Peatio::Wallet::ClientError, e
|
44
|
+
end
|
45
|
+
|
46
|
+
def load_balance!
|
47
|
+
client.json_rpc(:getbalance).to_d
|
48
|
+
|
49
|
+
rescue Bitcoincash::Client::Error => e
|
50
|
+
raise Peatio::Wallet::ClientError, e
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def client
|
56
|
+
uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
|
57
|
+
@client ||= Client.new(uri)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
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/bitcoincash/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "peatio-bitcoincash"
|
8
|
+
spec.version = Peatio::Bitcoincash::VERSION
|
9
|
+
spec.authors = ["Dinesh Chohda"]
|
10
|
+
spec.email = ["dinesh.skyach@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Gem for extending Peatio plugable system with Bitcoincash implementation.}
|
13
|
+
spec.description = %q{Bitcoincash Peatio gem which implements Peatio::Blockchain::Abstract & Peatio::Wallet::Abstract.}
|
14
|
+
spec.homepage = "https://www.skyach.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.1"
|
31
|
+
spec.add_dependency "cash-addr", '~> 0.2.0'
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
34
|
+
spec.add_development_dependency "mocha", "~> 1.8"
|
35
|
+
spec.add_development_dependency "pry-byebug"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
38
|
+
spec.add_development_dependency "webmock", "~> 3.5"
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,237 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: peatio-bitcoincash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dinesh Chohda
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-31 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.1
|
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.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: cash-addr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.2.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.2.0
|
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.17'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.17'
|
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: '10.0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '10.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: Bitcoincash Peatio gem which implements Peatio::Blockchain::Abstract
|
182
|
+
& Peatio::Wallet::Abstract.
|
183
|
+
email:
|
184
|
+
- dinesh.skyach@gmail.com
|
185
|
+
executables: []
|
186
|
+
extensions: []
|
187
|
+
extra_rdoc_files: []
|
188
|
+
files:
|
189
|
+
- ".gitignore"
|
190
|
+
- ".rspec"
|
191
|
+
- ".travis.yml"
|
192
|
+
- Gemfile
|
193
|
+
- Gemfile.lock
|
194
|
+
- LICENSE.txt
|
195
|
+
- README.md
|
196
|
+
- Rakefile
|
197
|
+
- bin/console
|
198
|
+
- bin/setup
|
199
|
+
- config/blockchains.yml
|
200
|
+
- config/currencies.yml
|
201
|
+
- config/wallets.yml
|
202
|
+
- docs/integration.md
|
203
|
+
- docs/json-rpc.md
|
204
|
+
- docs/testnet.md
|
205
|
+
- lib/peatio/bitcoincash.rb
|
206
|
+
- lib/peatio/bitcoincash/blockchain.rb
|
207
|
+
- lib/peatio/bitcoincash/client.rb
|
208
|
+
- lib/peatio/bitcoincash/concerns/cash_address_format.rb
|
209
|
+
- lib/peatio/bitcoincash/hooks.rb
|
210
|
+
- lib/peatio/bitcoincash/railtie.rb
|
211
|
+
- lib/peatio/bitcoincash/version.rb
|
212
|
+
- lib/peatio/bitcoincash/wallet.rb
|
213
|
+
- peatio-bitcoincash.gemspec
|
214
|
+
homepage: https://www.skyach.com/
|
215
|
+
licenses:
|
216
|
+
- MIT
|
217
|
+
metadata: {}
|
218
|
+
post_install_message:
|
219
|
+
rdoc_options: []
|
220
|
+
require_paths:
|
221
|
+
- lib
|
222
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
223
|
+
requirements:
|
224
|
+
- - ">="
|
225
|
+
- !ruby/object:Gem::Version
|
226
|
+
version: '0'
|
227
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
228
|
+
requirements:
|
229
|
+
- - ">="
|
230
|
+
- !ruby/object:Gem::Version
|
231
|
+
version: '0'
|
232
|
+
requirements: []
|
233
|
+
rubygems_version: 3.0.3
|
234
|
+
signing_key:
|
235
|
+
specification_version: 4
|
236
|
+
summary: Gem for extending Peatio plugable system with Bitcoincash implementation.
|
237
|
+
test_files: []
|