peatio-umbru 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +110 -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 +44 -0
- data/docs/integration.md +29 -0
- data/docs/json-rpc.md +29 -0
- data/docs/testnet.md +7 -0
- data/lib/peatio/umbru.rb +18 -0
- data/lib/peatio/umbru/blockchain.rb +85 -0
- data/lib/peatio/umbru/client.rb +61 -0
- data/lib/peatio/umbru/hooks.rb +42 -0
- data/lib/peatio/umbru/railtie.rb +13 -0
- data/lib/peatio/umbru/version.rb +5 -0
- data/lib/peatio/umbru/wallet.rb +60 -0
- data/peatio-umbru.gemspec +38 -0
- metadata +28 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2fecf19bf4a0bdfa106cb8588563f554f59fc043056abc17e3d1cfbaf5d59f37
|
4
|
+
data.tar.gz: 1502ecddebea5b26747bff45b2e40ebde75640d381ef6c5ce0d87c8d88478f4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ba7e25af7edd09322442684c92eea5d9e8c9128244c787a809fdb8f905509edc9b0423bc201b89e4dca8530a4faada6caae8836c5792305ec365d40b4159940
|
7
|
+
data.tar.gz: 06070dd70ad4a8b162ee0bbf269ef14c8b46c5dca08dded7c5ba155530dd47731f81067fab5cb1d59c708d7bfbe634951c8242d66601e948552b89e90d03e3f6
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
peatio-umbru (0.2.1)
|
5
|
+
activesupport (~> 5.2.3)
|
6
|
+
better-faraday (~> 1.0.5)
|
7
|
+
faraday (~> 0.15.4)
|
8
|
+
memoist (~> 0.16.0)
|
9
|
+
peatio (~> 0.6.1)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
activemodel (5.2.3)
|
15
|
+
activesupport (= 5.2.3)
|
16
|
+
activesupport (5.2.3)
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
+
i18n (>= 0.7, < 2)
|
19
|
+
minitest (~> 5.1)
|
20
|
+
tzinfo (~> 1.1)
|
21
|
+
addressable (2.6.0)
|
22
|
+
public_suffix (>= 2.0.2, < 4.0)
|
23
|
+
amq-protocol (2.3.0)
|
24
|
+
amqp (1.8.0)
|
25
|
+
amq-protocol (>= 2.2.0)
|
26
|
+
eventmachine
|
27
|
+
better-faraday (1.0.5)
|
28
|
+
activesupport (>= 4.0, < 6.0)
|
29
|
+
faraday (~> 0.12)
|
30
|
+
bunny (2.14.2)
|
31
|
+
amq-protocol (~> 2.3, >= 2.3.0)
|
32
|
+
byebug (11.0.1)
|
33
|
+
clamp (1.3.0)
|
34
|
+
coderay (1.1.2)
|
35
|
+
concurrent-ruby (1.1.5)
|
36
|
+
crack (0.4.3)
|
37
|
+
safe_yaml (~> 1.0.0)
|
38
|
+
diff-lcs (1.3)
|
39
|
+
em-websocket (0.5.1)
|
40
|
+
eventmachine (>= 0.12.9)
|
41
|
+
http_parser.rb (~> 0.6.0)
|
42
|
+
eventmachine (1.2.7)
|
43
|
+
faraday (0.15.4)
|
44
|
+
multipart-post (>= 1.2, < 3)
|
45
|
+
hashdiff (0.3.9)
|
46
|
+
http_parser.rb (0.6.0)
|
47
|
+
i18n (1.6.0)
|
48
|
+
concurrent-ruby (~> 1.0)
|
49
|
+
jwt (2.2.1)
|
50
|
+
memoist (0.16.0)
|
51
|
+
metaclass (0.0.4)
|
52
|
+
method_source (0.9.2)
|
53
|
+
minitest (5.11.3)
|
54
|
+
mocha (1.8.0)
|
55
|
+
metaclass (~> 0.0.1)
|
56
|
+
multipart-post (2.1.1)
|
57
|
+
mysql2 (0.5.2)
|
58
|
+
peatio (0.6.1)
|
59
|
+
activemodel (~> 5.2.3)
|
60
|
+
amqp
|
61
|
+
bunny
|
62
|
+
clamp
|
63
|
+
em-websocket
|
64
|
+
eventmachine
|
65
|
+
jwt
|
66
|
+
mysql2
|
67
|
+
pry (0.12.2)
|
68
|
+
coderay (~> 1.1.0)
|
69
|
+
method_source (~> 0.9.0)
|
70
|
+
pry-byebug (3.7.0)
|
71
|
+
byebug (~> 11.0)
|
72
|
+
pry (~> 0.10)
|
73
|
+
public_suffix (3.0.3)
|
74
|
+
rake (10.5.0)
|
75
|
+
rspec (3.8.0)
|
76
|
+
rspec-core (~> 3.8.0)
|
77
|
+
rspec-expectations (~> 3.8.0)
|
78
|
+
rspec-mocks (~> 3.8.0)
|
79
|
+
rspec-core (3.8.0)
|
80
|
+
rspec-support (~> 3.8.0)
|
81
|
+
rspec-expectations (3.8.2)
|
82
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
83
|
+
rspec-support (~> 3.8.0)
|
84
|
+
rspec-mocks (3.8.0)
|
85
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
86
|
+
rspec-support (~> 3.8.0)
|
87
|
+
rspec-support (3.8.0)
|
88
|
+
safe_yaml (1.0.5)
|
89
|
+
thread_safe (0.3.6)
|
90
|
+
tzinfo (1.2.5)
|
91
|
+
thread_safe (~> 0.1)
|
92
|
+
webmock (3.5.1)
|
93
|
+
addressable (>= 2.3.6)
|
94
|
+
crack (>= 0.3.2)
|
95
|
+
hashdiff
|
96
|
+
|
97
|
+
PLATFORMS
|
98
|
+
ruby
|
99
|
+
|
100
|
+
DEPENDENCIES
|
101
|
+
bundler (~> 1.16)
|
102
|
+
mocha (~> 1.8)
|
103
|
+
peatio-umbru!
|
104
|
+
pry-byebug
|
105
|
+
rake (~> 10.0)
|
106
|
+
rspec (~> 3.0)
|
107
|
+
webmock (~> 3.5)
|
108
|
+
|
109
|
+
BUNDLED WITH
|
110
|
+
1.16.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Yaroslav Savchuk
|
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::Umbru
|
2
|
+
|
3
|
+
Peatio umbru plugin for Rubykube stack
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'peatio-umbru'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install peatio-umbru
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
For Peatio Umbru plugin integration you need to do the following steps:
|
24
|
+
|
25
|
+
### Image Build.
|
26
|
+
|
27
|
+
1. Add peatio-umbru gem into your Gemfile.plugin
|
28
|
+
```ruby
|
29
|
+
gem 'peatio-umbru', '~> 0.2.1'
|
30
|
+
```
|
31
|
+
|
32
|
+
2. Run `bundle install` for updating Gemfile.lock
|
33
|
+
|
34
|
+
3. Build custom Peatio [docker image with Umbru 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-umbru gem
|
39
|
+
|
40
|
+
### Peatio Configuration.
|
41
|
+
|
42
|
+
1. Create Umbru Blockchain [config example](../config/blockchains.yml).
|
43
|
+
* No additional steps are needed
|
44
|
+
|
45
|
+
2. Create Umbru Currency [config example](../config/currencies.yml).
|
46
|
+
* No additional steps are needed
|
47
|
+
|
48
|
+
3. Create Umbru 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-umbru.
|
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/umbru"
|
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: umbru-mainnet
|
2
|
+
name: Umbru Mainnet
|
3
|
+
client: umbru # API client name.
|
4
|
+
server: http://user:password@127.0.0.1:19707 # Public Umbru node endpoint.
|
5
|
+
height: 50000 # 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://explorer.umbru.org/address/#{address}
|
9
|
+
transaction: https://explorer.umbru.org/tx/#{txid}
|
10
|
+
status: active
|
@@ -0,0 +1,18 @@
|
|
1
|
+
- id: umbru
|
2
|
+
name: Umbru
|
3
|
+
blockchain_key: umbru-mainnet
|
4
|
+
symbol: 'C'
|
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: Umbru Deposit Wallet
|
2
|
+
blockchain_key: umbru-mainnet
|
3
|
+
currency_id: umbru
|
4
|
+
# Address where deposits will be collected to.
|
5
|
+
address: 'CWWkTPkNRdpTDSfPw7gxUt9cEaC5PSsP3Y' # 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: umbrud # Gateway client name.
|
11
|
+
settings:
|
12
|
+
#
|
13
|
+
# Umbrud gateway client settings.
|
14
|
+
uri: http://user:password@127.0.0.1:19707
|
15
|
+
|
16
|
+
- name: Umbru Hot Wallet
|
17
|
+
blockchain_key: umbru-mainnet
|
18
|
+
currency_id: umbru
|
19
|
+
# Address where deposits will be collected to.
|
20
|
+
address: 'CWWkTPkNRdpTDSfPw7gxUt9cEaC5PSsP3Y' # 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: umbrud # Gateway client name.
|
26
|
+
settings:
|
27
|
+
#
|
28
|
+
# Umbrud gateway client settings.
|
29
|
+
uri: http://user:password@127.0.0.1:19707
|
30
|
+
|
31
|
+
- name: Umbru Warm Wallet
|
32
|
+
blockchain_key: umbru-mainnet
|
33
|
+
currency_id: umbru
|
34
|
+
# Address where deposits will be collected to.
|
35
|
+
address: 'CWWkTPkNRdpTDSfPw7gxUt9cEaC5PSsP3Y' # 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: umbrud # Gateway client name.
|
41
|
+
settings:
|
42
|
+
#
|
43
|
+
# Umbrud gateway client settings.
|
44
|
+
uri: http://user:password@127.0.0.1:19707
|
data/docs/integration.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Integration.
|
2
|
+
|
3
|
+
For Peatio Umbru plugin integration you need to do the following steps:
|
4
|
+
|
5
|
+
## Image Build.
|
6
|
+
|
7
|
+
1. Add peatio-umbru gem into your Gemfile.plugin
|
8
|
+
```ruby
|
9
|
+
gem 'peatio-umbru', '~> 0.2.1'
|
10
|
+
```
|
11
|
+
|
12
|
+
2. Run `bundle install` for updating Gemfile.lock
|
13
|
+
|
14
|
+
3. Build custom Peatio [docker image with Umbru 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-umbru gem
|
19
|
+
|
20
|
+
## Peatio Configuration.
|
21
|
+
|
22
|
+
1. Create Umbru Blockchain [config example](../config/blockchains.yml).
|
23
|
+
* No additional steps are needed
|
24
|
+
|
25
|
+
2. Create Umbru Currency [config example](../config/currencies.yml).
|
26
|
+
* No additional steps are needed
|
27
|
+
|
28
|
+
3. Create Umbru 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:19707`
|
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:19707`
|
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:19707`
|
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:19707 `
|
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:19707 `
|
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:19707`
|
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:19707`
|
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:19707`
|
data/docs/testnet.md
ADDED
data/lib/peatio/umbru.rb
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 Umbru
|
7
|
+
require "bigdecimal"
|
8
|
+
require "bigdecimal/util"
|
9
|
+
|
10
|
+
require "peatio/umbru/blockchain"
|
11
|
+
require "peatio/umbru/client"
|
12
|
+
require "peatio/umbru/wallet"
|
13
|
+
|
14
|
+
require "peatio/umbru/hooks"
|
15
|
+
|
16
|
+
require "peatio/umbru/version"
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
|
2
|
+
module Peatio
|
3
|
+
module Umbru
|
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,61 @@
|
|
1
|
+
require 'memoist'
|
2
|
+
require 'faraday'
|
3
|
+
require 'better-faraday'
|
4
|
+
|
5
|
+
module Peatio
|
6
|
+
module Umbru
|
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
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Peatio
|
2
|
+
module Umbru
|
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
|
+
"Umbru blockchain version requiremnt was not suttisfied by Peatio::Blockchain.",
|
13
|
+
"Umbru 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
|
+
"Umbru wallet version requiremnt was not suttisfied by Peatio::Wallet.",
|
22
|
+
"Umbru 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[:umbru] = Umbru::Blockchain.new
|
30
|
+
Peatio::Wallet.registry[:umbrud] = Umbru::Wallet.new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if defined?(Rails::Railtie)
|
35
|
+
require "peatio/umbru/railtie"
|
36
|
+
else
|
37
|
+
check_compatibility
|
38
|
+
register
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Peatio
|
2
|
+
module Umbru
|
3
|
+
class Wallet < Peatio::Wallet::Abstract
|
4
|
+
|
5
|
+
def initialize(settings = {})
|
6
|
+
@settings = settings
|
7
|
+
end
|
8
|
+
|
9
|
+
def configure(settings = {})
|
10
|
+
# Clean client state during configure.
|
11
|
+
@client = nil
|
12
|
+
|
13
|
+
@settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
|
14
|
+
|
15
|
+
@wallet = @settings.fetch(:wallet) do
|
16
|
+
raise Peatio::Wallet::MissingSettingError, :wallet
|
17
|
+
end.slice(:uri, :address)
|
18
|
+
|
19
|
+
@currency = @settings.fetch(:currency) do
|
20
|
+
raise Peatio::Wallet::MissingSettingError, :currency
|
21
|
+
end.slice(:id, :base_factor, :options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_address!(_options = {})
|
25
|
+
{ address: client.json_rpc(:getnewaddress) }
|
26
|
+
rescue Umbru::Client::Error => e
|
27
|
+
raise Peatio::Wallet::ClientError, e
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_transaction!(transaction, options = {})
|
31
|
+
txid = client.json_rpc(:sendtoaddress,
|
32
|
+
[
|
33
|
+
transaction.to_address,
|
34
|
+
transaction.amount,
|
35
|
+
'',
|
36
|
+
'',
|
37
|
+
options[:subtract_fee].to_s == 'true' # subtract fee from transaction amount.
|
38
|
+
])
|
39
|
+
transaction.hash = txid
|
40
|
+
transaction
|
41
|
+
rescue Umbru::Client::Error => e
|
42
|
+
raise Peatio::Wallet::ClientError, e
|
43
|
+
end
|
44
|
+
|
45
|
+
def load_balance!
|
46
|
+
client.json_rpc(:getbalance).to_d
|
47
|
+
|
48
|
+
rescue Umbru::Client::Error => e
|
49
|
+
raise Peatio::Wallet::ClientError, e
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def client
|
55
|
+
uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
|
56
|
+
@client ||= Client.new(uri)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "peatio/umbru/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "peatio-umbru"
|
8
|
+
spec.version = Peatio::Umbru::VERSION
|
9
|
+
spec.authors = ["Hawkz_"]
|
10
|
+
spec.email = ["team@umbru.io"]
|
11
|
+
|
12
|
+
spec.summary = %q{Gem for extending Peatio plugable system with Umbru implementation.}
|
13
|
+
spec.description = %q{Umbru Peatio gem which implements Peatio::Blockchain::Abstract & Peatio::Wallet::Abstract.}
|
14
|
+
spec.homepage = "https://umbru.io/"
|
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
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
33
|
+
spec.add_development_dependency "mocha", "~> 1.8"
|
34
|
+
spec.add_development_dependency "pry-byebug"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
37
|
+
spec.add_development_dependency "webmock", "~> 3.5"
|
38
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peatio-umbru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hawkz_
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -170,7 +170,31 @@ email:
|
|
170
170
|
executables: []
|
171
171
|
extensions: []
|
172
172
|
extra_rdoc_files: []
|
173
|
-
files:
|
173
|
+
files:
|
174
|
+
- ".gitignore"
|
175
|
+
- ".rspec"
|
176
|
+
- ".travis.yml"
|
177
|
+
- Gemfile
|
178
|
+
- Gemfile.lock
|
179
|
+
- LICENSE.txt
|
180
|
+
- README.md
|
181
|
+
- Rakefile
|
182
|
+
- bin/console
|
183
|
+
- bin/setup
|
184
|
+
- config/blockchains.yml
|
185
|
+
- config/currencies.yml
|
186
|
+
- config/wallets.yml
|
187
|
+
- docs/integration.md
|
188
|
+
- docs/json-rpc.md
|
189
|
+
- docs/testnet.md
|
190
|
+
- lib/peatio/umbru.rb
|
191
|
+
- lib/peatio/umbru/blockchain.rb
|
192
|
+
- lib/peatio/umbru/client.rb
|
193
|
+
- lib/peatio/umbru/hooks.rb
|
194
|
+
- lib/peatio/umbru/railtie.rb
|
195
|
+
- lib/peatio/umbru/version.rb
|
196
|
+
- lib/peatio/umbru/wallet.rb
|
197
|
+
- peatio-umbru.gemspec
|
174
198
|
homepage: https://umbru.io/
|
175
199
|
licenses:
|
176
200
|
- MIT
|
@@ -190,8 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
214
|
- !ruby/object:Gem::Version
|
191
215
|
version: '0'
|
192
216
|
requirements: []
|
193
|
-
|
194
|
-
rubygems_version: 2.5.2
|
217
|
+
rubygems_version: 3.0.3
|
195
218
|
signing_key:
|
196
219
|
specification_version: 4
|
197
220
|
summary: Gem for extending Peatio plugable system with Umbru implementation.
|