module-render-xyz 0.1.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/Dockerfile +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +110 -0
- data/LICENSE.txt +21 -0
- data/README.md +100 -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 +20 -0
- data/config/wallets.yml +47 -0
- data/docs/integration.md +29 -0
- data/docs/json-rpc.md +29 -0
- data/docs/testnet.md +5 -0
- data/lib/peatio/infura/blockchain.rb +221 -0
- data/lib/peatio/infura/client.rb +77 -0
- data/lib/peatio/infura/hooks.rb +42 -0
- data/lib/peatio/infura/railtie.rb +13 -0
- data/lib/peatio/infura/version.rb +5 -0
- data/lib/peatio/infura/wallet.rb +223 -0
- data/lib/peatio/infura.rb +18 -0
- data/peatio-infura.gemspec +38 -0
- metadata +223 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0daad93f38be1007b120ebc3c7b2b1ca9ed89ba735ba2c71120c7ce059a0fd4e
|
4
|
+
data.tar.gz: a5607666e0a463bf6c8b788e66d11a0313493415fd5c99c35ba15e6816eff53a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 881ca231aad2f34d108ab1d583c036c1b4b4e072f045eea6c960b551828e91e9d9f04d9c506e157e42b083ba2e85586d2fb676b42c7623fabce06f65a5dc5ff5
|
7
|
+
data.tar.gz: 3278cb92864eb3f8af613907889c75765d5bd26c8b3e4c7bf974d55fb130e2c82e1e7572880709e6b9a7af16402b290de6825e08f82dab4c26c6fd116119ba06
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Dockerfile
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
module-render-xyz (0.1.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
|
+
module-render-xyz!
|
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,100 @@
|
|
1
|
+
# Peatio::Infura
|
2
|
+
|
3
|
+
Peatio infura plugin for Openware stack
|
4
|
+
|
5
|
+
## Create Gem
|
6
|
+
|
7
|
+
Clone this repository
|
8
|
+
|
9
|
+
git clone https://github.com/mycework/peatio-infura.git
|
10
|
+
|
11
|
+
Enter `peatio-infura` folder and build image
|
12
|
+
|
13
|
+
docker build -t sundanny26/ruby-infura .
|
14
|
+
|
15
|
+
Run container
|
16
|
+
|
17
|
+
docker run --name infura_container -d sundanny26/ruby-infura
|
18
|
+
|
19
|
+
Enter container
|
20
|
+
|
21
|
+
docker exec -it infura_container bash
|
22
|
+
|
23
|
+
Build GEM
|
24
|
+
|
25
|
+
gem build peatio-infura.gemspec
|
26
|
+
|
27
|
+
Push GEM
|
28
|
+
|
29
|
+
gem push peatio-infura-0.1.0.gem
|
30
|
+
|
31
|
+
|
32
|
+
*others*
|
33
|
+
Delete accidentaly added rubygem *if the gem contains password, you should reset all passwords*
|
34
|
+
|
35
|
+
gem yank -v 0.1.0 peatio-infura
|
36
|
+
|
37
|
+
|
38
|
+
## Installation
|
39
|
+
|
40
|
+
Add this line to your application's Gemfile:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
gem 'peatio-infura'
|
44
|
+
```
|
45
|
+
|
46
|
+
And then execute:
|
47
|
+
|
48
|
+
$ bundle
|
49
|
+
|
50
|
+
Or install it yourself as:
|
51
|
+
|
52
|
+
$ gem install peatio-infura
|
53
|
+
|
54
|
+
## Usage
|
55
|
+
|
56
|
+
For Peatio Infura plugin integration you need to do the following steps:
|
57
|
+
|
58
|
+
### Image Build.
|
59
|
+
|
60
|
+
1. Add peatio-infura gem into your Gemfile.plugin
|
61
|
+
```ruby
|
62
|
+
gem 'peatio-infura', '~> 0.2.0'
|
63
|
+
```
|
64
|
+
|
65
|
+
2. Run `bundle install` for updating Gemfile.lock
|
66
|
+
|
67
|
+
3. Build custom Peatio [docker image with Infura plugin](https://github.com/rubykube/peatio/blob/master/docs/plugins.md#build)
|
68
|
+
|
69
|
+
4. Push your image using `docker push`
|
70
|
+
|
71
|
+
5. Update your deployment to use image with peatio-infura gem
|
72
|
+
|
73
|
+
### Peatio Configuration.
|
74
|
+
|
75
|
+
1. Create Infura Blockchain [config example](../config/blockchains.yml).
|
76
|
+
* No additional steps are needed
|
77
|
+
|
78
|
+
2. Create Infura Currency [config example](../config/currencies.yml).
|
79
|
+
* No additional steps are needed
|
80
|
+
|
81
|
+
3. Create Infura Wallets [config example](../config/wallets.yml)(deposit and hot wallets are required).
|
82
|
+
* No additional steps are needed
|
83
|
+
|
84
|
+
|
85
|
+
## Development
|
86
|
+
|
87
|
+
Plugin development [example](https://github.com/rubykube/peatio/blob/master/docs/coins/development.md).
|
88
|
+
|
89
|
+
## Contributing
|
90
|
+
|
91
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rubykube/peatio-infura.
|
92
|
+
|
93
|
+
## License
|
94
|
+
|
95
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
96
|
+
|
97
|
+
## Consulting
|
98
|
+
|
99
|
+
You can contact Openware for finding certified vendors:
|
100
|
+
[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/infura"
|
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: eth-mainnet
|
2
|
+
name: Ethereum Mainnet
|
3
|
+
client: infura # API client name.
|
4
|
+
server: https://rinkeby.infura.io/v3/INFURA_KEY # Public Ethereum node endpoint. IMPORTANT: full syncmode.
|
5
|
+
height: 7500000 # 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://etherscan.io/address/#{address}
|
9
|
+
transaction: https://etherscan.io/tx/#{txid}
|
10
|
+
status: active
|
@@ -0,0 +1,20 @@
|
|
1
|
+
- id: eth
|
2
|
+
name: Ethereum
|
3
|
+
blockchain_key: eth-mainnet
|
4
|
+
symbol: 'Ξ'
|
5
|
+
type: coin
|
6
|
+
precision: 8
|
7
|
+
base_factor: 1_000_000_000_000_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.00021
|
12
|
+
min_collection_amount: 0.00021
|
13
|
+
withdraw_limit_24h: 2.0
|
14
|
+
withdraw_limit_72h: 5.0
|
15
|
+
deposit_fee: 0
|
16
|
+
withdraw_fee: 0
|
17
|
+
position: 5
|
18
|
+
options:
|
19
|
+
gas_limit: 21_000
|
20
|
+
gas_price: 1_000_000_000
|
data/config/wallets.yml
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
- name: Ethereum Deposit Wallet
|
2
|
+
blockchain_key: eth-mainnet
|
3
|
+
currency_id: eth
|
4
|
+
# Address where deposits will be collected to.
|
5
|
+
address: '0xd1bfc7daabbd6aa40a7a1a87464cc93882fa24cb' # 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: infurad # Gateway client name.
|
11
|
+
settings:
|
12
|
+
#
|
13
|
+
# infurad gateway client settings.
|
14
|
+
uri: https://rinkeby.infura.io/v3/INFURA_KEY
|
15
|
+
sign_uri: http://infura:8545
|
16
|
+
|
17
|
+
- name: Ethereum Hot Wallet
|
18
|
+
blockchain_key: eth-mainnet
|
19
|
+
currency_id: eth
|
20
|
+
# Address where deposits will be collected to.
|
21
|
+
address: '0xd1bfc7daabbd6aa40a7a1a87464cc93882fa2401' # IMPORTANT: Always wrap this value in quotes!
|
22
|
+
kind: hot # Wallet kind (deposit, hot, warm, cold or fee).
|
23
|
+
nsig: 1 # Number of signatures required for performing withdraw.
|
24
|
+
max_balance: 5.0
|
25
|
+
status: active
|
26
|
+
gateway: infurad # Gateway client name.
|
27
|
+
settings:
|
28
|
+
#
|
29
|
+
# infurad gateway client settings.
|
30
|
+
uri: https://rinkeby.infura.io/v3/INFURA_KEY
|
31
|
+
sign_uri: http://infura:8545
|
32
|
+
|
33
|
+
- name: Ethereum Warm Wallet
|
34
|
+
blockchain_key: eth-mainnet
|
35
|
+
currency_id: eth
|
36
|
+
# Address where deposits will be collected to.
|
37
|
+
address: '0xd1bfc7daabbd6aa40a7a1a87464cc93882fa24545' # IMPORTANT: Always wrap this value in quotes!
|
38
|
+
kind: warm # Wallet kind (deposit, hot, warm, cold or fee).
|
39
|
+
nsig: 1 # Number of signatures required for performing withdraw.
|
40
|
+
max_balance: 50.0
|
41
|
+
status: active
|
42
|
+
gateway: infurad # Gateway client name.
|
43
|
+
settings:
|
44
|
+
#
|
45
|
+
# infurad gateway client settings.
|
46
|
+
uri: https://rinkeby.infura.io/v3/INFURA_KEY
|
47
|
+
sign_uri: http://infura:8545
|
data/docs/integration.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Integration.
|
2
|
+
|
3
|
+
For Peatio Infura plugin integration you need to do the following steps:
|
4
|
+
|
5
|
+
## Image Build.
|
6
|
+
|
7
|
+
1. Add peatio-infura gem into your Gemfile.plugin
|
8
|
+
```ruby
|
9
|
+
gem 'peatio-infura', '~> 0.1.0'
|
10
|
+
```
|
11
|
+
|
12
|
+
2. Run `bundle install` for updating Gemfile.lock
|
13
|
+
|
14
|
+
3. Build custom Peatio [docker image with Infura 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-infura gem
|
19
|
+
|
20
|
+
## Peatio Configuration.
|
21
|
+
|
22
|
+
1. Create Infura Blockchain [config example](../config/blockchains.yml).
|
23
|
+
* No additional steps are needed
|
24
|
+
|
25
|
+
2. Create Infura Currency [config example](../config/currencies.yml).
|
26
|
+
* No additional steps are needed
|
27
|
+
|
28
|
+
3. Create Infura 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,221 @@
|
|
1
|
+
|
2
|
+
module Peatio
|
3
|
+
module Infura
|
4
|
+
class Blockchain < Peatio::Blockchain::Abstract
|
5
|
+
|
6
|
+
UndefinedCurrencyError = Class.new(StandardError)
|
7
|
+
|
8
|
+
TOKEN_EVENT_IDENTIFIER = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
|
9
|
+
SUCCESS = '0x1'
|
10
|
+
FAILED = '0x0'
|
11
|
+
|
12
|
+
DEFAULT_FEATURES = { case_sensitive: false, cash_addr_format: false }.freeze
|
13
|
+
|
14
|
+
def initialize(custom_features = {})
|
15
|
+
@features = DEFAULT_FEATURES.merge(custom_features).slice(*SUPPORTED_FEATURES)
|
16
|
+
@settings = {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def configure(settings = {})
|
20
|
+
# Clean client state during configure.
|
21
|
+
@client = nil
|
22
|
+
@erc20 = []; @eth = []
|
23
|
+
|
24
|
+
@settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
|
25
|
+
@settings[:currencies]&.each do |c|
|
26
|
+
if c.dig(:options, :erc20_contract_address).present?
|
27
|
+
@erc20 << c
|
28
|
+
else
|
29
|
+
@eth << c
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def fetch_block!(block_number)
|
35
|
+
block_json = client.json_rpc(:eth_getBlockByNumber, ["0x#{block_number.to_s(16)}", true])
|
36
|
+
|
37
|
+
if block_json.blank? || block_json['transactions'].blank?
|
38
|
+
return Peatio::Block.new(block_number, [])
|
39
|
+
end
|
40
|
+
block_json.fetch('transactions').each_with_object([]) do |tx, block_arr|
|
41
|
+
if tx.fetch('input').hex <= 0
|
42
|
+
next if invalid_eth_transaction?(tx)
|
43
|
+
else
|
44
|
+
next if @erc20.find { |c| c.dig(:options, :erc20_contract_address) == normalize_address(tx.fetch('to')) }.blank?
|
45
|
+
tx = client.json_rpc(:eth_getTransactionReceipt, [normalize_txid(tx.fetch('hash'))])
|
46
|
+
next if tx.nil? || tx.fetch('to').blank?
|
47
|
+
end
|
48
|
+
|
49
|
+
txs = build_transactions(tx).map do |ntx|
|
50
|
+
Peatio::Transaction.new(ntx)
|
51
|
+
end
|
52
|
+
|
53
|
+
block_arr.append(*txs)
|
54
|
+
end.yield_self { |block_arr| Peatio::Block.new(block_number, block_arr) }
|
55
|
+
rescue Infura::Client::Error => e
|
56
|
+
raise Peatio::Blockchain::ClientError, e
|
57
|
+
end
|
58
|
+
|
59
|
+
def latest_block_number
|
60
|
+
client.json_rpc(:eth_blockNumber).to_i(16)
|
61
|
+
rescue Infura::Client::Error => e
|
62
|
+
raise Peatio::Blockchain::ClientError, e
|
63
|
+
end
|
64
|
+
|
65
|
+
def load_balance_of_address!(address, currency_id)
|
66
|
+
currency = settings[:currencies].find { |c| c[:id] == currency_id.to_s }
|
67
|
+
raise UndefinedCurrencyError unless currency
|
68
|
+
|
69
|
+
if currency.dig(:options, :erc20_contract_address).present?
|
70
|
+
load_erc20_balance(address, currency)
|
71
|
+
else
|
72
|
+
client.json_rpc(:eth_getBalance, [normalize_address(address), 'latest'])
|
73
|
+
.hex
|
74
|
+
.to_d
|
75
|
+
.yield_self { |amount| convert_from_base_unit(amount, currency) }
|
76
|
+
end
|
77
|
+
rescue Infura::Client::Error => e
|
78
|
+
raise Peatio::Blockchain::ClientError, e
|
79
|
+
end
|
80
|
+
|
81
|
+
def fetch_transaction(transaction)
|
82
|
+
currency = settings[:currencies].find { |c| c.fetch(:id) == transaction.currency_id }
|
83
|
+
return if currency.blank?
|
84
|
+
txn_receipt = client.json_rpc(:eth_getTransactionReceipt, [transaction.hash])
|
85
|
+
if currency.in?(@eth)
|
86
|
+
txn_json = client.json_rpc(:eth_getTransactionByHash, [transaction.hash])
|
87
|
+
attributes = {
|
88
|
+
amount: convert_from_base_unit(txn_json.fetch('value').hex, currency),
|
89
|
+
to_address: normalize_address(txn_json['to']),
|
90
|
+
status: transaction_status(txn_receipt)
|
91
|
+
}
|
92
|
+
else
|
93
|
+
txn_json = txn_receipt.fetch('logs').find { |log| log['logIndex'].to_i(16) == transaction.txout }
|
94
|
+
attributes = {
|
95
|
+
amount: convert_from_base_unit(txn_json.fetch('data').hex, currency),
|
96
|
+
to_address: normalize_address('0x' + txn_json.fetch('topics').last[-40..-1]),
|
97
|
+
status: transaction_status(txn_receipt)
|
98
|
+
}
|
99
|
+
end
|
100
|
+
transaction.assign_attributes(attributes)
|
101
|
+
transaction
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def load_erc20_balance(address, currency)
|
107
|
+
data = abi_encode('balanceOf(address)', normalize_address(address))
|
108
|
+
client.json_rpc(:eth_call, [{ to: contract_address(currency), data: data }, 'latest'])
|
109
|
+
.hex
|
110
|
+
.to_d
|
111
|
+
.yield_self { |amount| convert_from_base_unit(amount, currency) }
|
112
|
+
end
|
113
|
+
|
114
|
+
def client
|
115
|
+
@client ||= Infura::Client.new(settings_fetch(:server))
|
116
|
+
end
|
117
|
+
|
118
|
+
def settings_fetch(key)
|
119
|
+
@settings.fetch(key) { raise Peatio::Blockchain::MissingSettingError, key.to_s }
|
120
|
+
end
|
121
|
+
|
122
|
+
def normalize_txid(txid)
|
123
|
+
txid.try(:downcase)
|
124
|
+
end
|
125
|
+
|
126
|
+
def normalize_address(address)
|
127
|
+
address.try(:downcase)
|
128
|
+
end
|
129
|
+
|
130
|
+
def build_transactions(tx_hash)
|
131
|
+
if tx_hash.has_key?('logs')
|
132
|
+
build_erc20_transactions(tx_hash)
|
133
|
+
else
|
134
|
+
build_eth_transactions(tx_hash)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def build_eth_transactions(block_txn)
|
139
|
+
@eth.map do |currency|
|
140
|
+
{ hash: normalize_txid(block_txn.fetch('hash')),
|
141
|
+
amount: convert_from_base_unit(block_txn.fetch('value').hex, currency),
|
142
|
+
to_address: normalize_address(block_txn['to']),
|
143
|
+
txout: block_txn.fetch('transactionIndex').to_i(16),
|
144
|
+
block_number: block_txn.fetch('blockNumber').to_i(16),
|
145
|
+
currency_id: currency.fetch(:id),
|
146
|
+
status: transaction_status(block_txn) }
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def build_erc20_transactions(txn_receipt)
|
151
|
+
# Build invalid transaction for failed withdrawals
|
152
|
+
if transaction_status(txn_receipt) == 'fail' && txn_receipt.fetch('logs').blank?
|
153
|
+
return build_invalid_erc20_transaction(txn_receipt)
|
154
|
+
end
|
155
|
+
|
156
|
+
txn_receipt.fetch('logs').each_with_object([]) do |log, formatted_txs|
|
157
|
+
|
158
|
+
next if log.fetch('topics').blank? || log.fetch('topics')[0] != TOKEN_EVENT_IDENTIFIER
|
159
|
+
|
160
|
+
# Skip if ERC20 contract address doesn't match.
|
161
|
+
currencies = @erc20.select { |c| c.dig(:options, :erc20_contract_address) == log.fetch('address') }
|
162
|
+
next if currencies.blank?
|
163
|
+
|
164
|
+
destination_address = normalize_address('0x' + log.fetch('topics').last[-40..-1])
|
165
|
+
|
166
|
+
currencies.each do |currency|
|
167
|
+
formatted_txs << { hash: normalize_txid(txn_receipt.fetch('transactionHash')),
|
168
|
+
amount: convert_from_base_unit(log.fetch('data').hex, currency),
|
169
|
+
to_address: destination_address,
|
170
|
+
txout: log['logIndex'].to_i(16),
|
171
|
+
block_number: txn_receipt.fetch('blockNumber').to_i(16),
|
172
|
+
currency_id: currency.fetch(:id),
|
173
|
+
status: transaction_status(txn_receipt) }
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def build_invalid_erc20_transaction(txn_receipt)
|
179
|
+
currencies = @erc20.select { |c| c.dig(:options, :erc20_contract_address) == txn_receipt.fetch('to') }
|
180
|
+
return if currencies.blank?
|
181
|
+
|
182
|
+
currencies.each_with_object([]) do |currency, invalid_txs|
|
183
|
+
invalid_txs << { hash: normalize_txid(txn_receipt.fetch('transactionHash')),
|
184
|
+
block_number: txn_receipt.fetch('blockNumber').to_i(16),
|
185
|
+
currency_id: currency.fetch(:id),
|
186
|
+
status: transaction_status(txn_receipt) }
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def transaction_status(block_txn)
|
191
|
+
if block_txn.dig('status') == SUCCESS
|
192
|
+
'success'
|
193
|
+
elsif block_txn.dig('status') == FAILED
|
194
|
+
'failed'
|
195
|
+
else
|
196
|
+
'pending'
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def invalid_eth_transaction?(block_txn)
|
201
|
+
block_txn.fetch('to').blank? \
|
202
|
+
|| block_txn.fetch('value').hex.to_d <= 0 && block_txn.fetch('input').hex <= 0
|
203
|
+
end
|
204
|
+
|
205
|
+
def contract_address(currency)
|
206
|
+
normalize_address(currency.dig(:options, :erc20_contract_address))
|
207
|
+
end
|
208
|
+
|
209
|
+
def abi_encode(method, *args)
|
210
|
+
'0x' + args.each_with_object(Digest::SHA3.hexdigest(method, 256)[0...8]) do |arg, data|
|
211
|
+
data.concat(arg.gsub(/\A0x/, '').rjust(64, '0'))
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def convert_from_base_unit(value, currency)
|
216
|
+
value.to_d / currency.fetch(:base_factor).to_d
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'memoist'
|
2
|
+
require 'faraday'
|
3
|
+
require 'better-faraday'
|
4
|
+
|
5
|
+
module Peatio
|
6
|
+
module Infura
|
7
|
+
class Client
|
8
|
+
Error = Class.new(StandardError)
|
9
|
+
|
10
|
+
class ConnectionError < Error; end
|
11
|
+
|
12
|
+
class ResponseError < Error
|
13
|
+
def initialize(code, msg)
|
14
|
+
super "#{msg} (#{code})"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
extend Memoist
|
19
|
+
|
20
|
+
def initialize(endpoint, sign_uri, idle_timeout: 5)
|
21
|
+
@json_rpc_endpoint = URI.parse(endpoint)
|
22
|
+
@sign_rpc_endpoint = URI.parse(sign_uri)
|
23
|
+
@json_rpc_call_id = 0
|
24
|
+
@idle_timeout = idle_timeout
|
25
|
+
end
|
26
|
+
|
27
|
+
def json_rpc(method, params = [], conn_type=nil)
|
28
|
+
current_conn = connection
|
29
|
+
unless conn_type.nil?
|
30
|
+
current_conn = sign_connection
|
31
|
+
end
|
32
|
+
response = current_conn.post \
|
33
|
+
'/',
|
34
|
+
{jsonrpc: '2.0', id: rpc_call_id, method: method, params: params}.to_json,
|
35
|
+
{'Accept' => 'application/json',
|
36
|
+
'Content-Type' => 'application/json'}
|
37
|
+
response.assert_success!
|
38
|
+
response = JSON.parse(response.body)
|
39
|
+
response['error'].tap { |error| raise ResponseError.new(error['code'], error['message']) if error }
|
40
|
+
response.fetch('result')
|
41
|
+
rescue Faraday::Error => e
|
42
|
+
raise ConnectionError, e
|
43
|
+
rescue StandardError => e
|
44
|
+
raise Error, e
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def rpc_call_id
|
50
|
+
@json_rpc_call_id += 1
|
51
|
+
end
|
52
|
+
|
53
|
+
def sign_connection
|
54
|
+
@connection ||= Faraday.new(@sign_rpc_endpoint) do |f|
|
55
|
+
f.adapter :net_http_persistent, pool_size: 5, idle_timeout: @idle_timeout
|
56
|
+
end.tap do |connection|
|
57
|
+
unless @json_rpc_endpoint.user.blank?
|
58
|
+
connection.basic_auth(@json_rpc_endpoint.user, @json_rpc_endpoint.password)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def connection
|
64
|
+
@connection ||= Faraday.new(@json_rpc_endpoint) do |f|
|
65
|
+
f.adapter :net_http_persistent, pool_size: 5, idle_timeout: @idle_timeout
|
66
|
+
end.tap do |connection|
|
67
|
+
unless @json_rpc_endpoint.user.blank?
|
68
|
+
connection.basic_auth(@json_rpc_endpoint.user, @json_rpc_endpoint.password)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Peatio
|
2
|
+
module Infura
|
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
|
+
"Infura blockchain version requiremnt was not suttisfied by Peatio::Blockchain.",
|
13
|
+
"Infura 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
|
+
"Infura wallet version requiremnt was not suttisfied by Peatio::Wallet.",
|
22
|
+
"Infura 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[:infura] = Infura::Blockchain.new
|
30
|
+
Peatio::Wallet.registry[:infurad] = Infura::Wallet.new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if defined?(Rails::Railtie)
|
35
|
+
require "peatio/infura/railtie"
|
36
|
+
else
|
37
|
+
check_compatibility
|
38
|
+
register
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,223 @@
|
|
1
|
+
module Peatio
|
2
|
+
module Infura
|
3
|
+
class Wallet < Peatio::Wallet::Abstract
|
4
|
+
|
5
|
+
DEFAULT_ETH_FEE = { gas_limit: 21_000, gas_price: 1_000_000_000 }.freeze
|
6
|
+
|
7
|
+
DEFAULT_ERC20_FEE = { gas_limit: 90_000, gas_price: 1_000_000_000 }.freeze
|
8
|
+
|
9
|
+
def initialize(settings = {})
|
10
|
+
@settings = settings
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure(settings = {})
|
14
|
+
# Clean client state during configure.
|
15
|
+
@client = nil
|
16
|
+
|
17
|
+
@settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
|
18
|
+
|
19
|
+
@wallet = @settings.fetch(:wallet) do
|
20
|
+
raise Peatio::Wallet::MissingSettingError, :wallet
|
21
|
+
end.slice(:uri, :sign_uri, :address, :secret)
|
22
|
+
|
23
|
+
@currency = @settings.fetch(:currency) do
|
24
|
+
raise Peatio::Wallet::MissingSettingError, :currency
|
25
|
+
end.slice(:id, :base_factor, :options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_address!(options = {})
|
29
|
+
secret = options.fetch(:secret) { PasswordGenerator.generate(64) }
|
30
|
+
secret.yield_self do |password|
|
31
|
+
{ address: normalize_address(client.json_rpc(:personal_newAccount, [password], conn_type="sign")),
|
32
|
+
secret: password }
|
33
|
+
end
|
34
|
+
rescue Infura::Client::Error => e
|
35
|
+
raise Peatio::Wallet::ClientError, e
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_transaction!(transaction, options = {})
|
39
|
+
if @currency.dig(:options, :erc20_contract_address).present?
|
40
|
+
create_erc20_transaction!(transaction)
|
41
|
+
else
|
42
|
+
create_eth_transaction!(transaction, options)
|
43
|
+
end
|
44
|
+
rescue Infura::Client::Error => e
|
45
|
+
raise Peatio::Wallet::ClientError, e
|
46
|
+
end
|
47
|
+
|
48
|
+
def sign_transaction(data)
|
49
|
+
client.json_rpc(:eth_signTransaction, [ data ], conn_type="sign").tap do |response|
|
50
|
+
unless response
|
51
|
+
raise Infura::WalletClient::Error, \
|
52
|
+
"#{walletnormalize_address.name} withdrawal from #{normalize_address(issuer[:address])} to #{normalize_address(recipient[:address])} is not permitted."
|
53
|
+
end
|
54
|
+
end
|
55
|
+
rescue Infura::Client::Error => e
|
56
|
+
raise Peatio::Wallet::ClientError, e
|
57
|
+
end
|
58
|
+
|
59
|
+
def prepare_deposit_collection!(transaction, deposit_spread, deposit_currency)
|
60
|
+
# TODO: Add spec for this behaviour.
|
61
|
+
# Don't prepare for deposit_collection in case of eth deposit.
|
62
|
+
return [] if deposit_currency.dig(:options, :erc20_contract_address).blank?
|
63
|
+
|
64
|
+
options = DEFAULT_ERC20_FEE.merge(deposit_currency.fetch(:options).slice(:gas_limit, :gas_price))
|
65
|
+
|
66
|
+
# We collect fees depending on the number of spread deposit size
|
67
|
+
# Example: if deposit spreads on three wallets need to collect eth fee for 3 transactions
|
68
|
+
fees = convert_from_base_unit(options.fetch(:gas_limit).to_i * options.fetch(:gas_price).to_i)
|
69
|
+
transaction.amount = fees * deposit_spread.size
|
70
|
+
|
71
|
+
[create_eth_transaction!(transaction)]
|
72
|
+
rescue Infura::Client::Error => e
|
73
|
+
raise Peatio::Wallet::ClientError, e
|
74
|
+
end
|
75
|
+
|
76
|
+
def load_balance!
|
77
|
+
if @currency.dig(:options, :erc20_contract_address).present?
|
78
|
+
load_erc20_balance(@wallet.fetch(:address))
|
79
|
+
else
|
80
|
+
client.json_rpc(:eth_getBalance, [normalize_address(@wallet.fetch(:address)), 'latest'])
|
81
|
+
.hex
|
82
|
+
.to_d
|
83
|
+
.yield_self { |amount| convert_from_base_unit(amount) }
|
84
|
+
end
|
85
|
+
rescue Infura::Client::Error => e
|
86
|
+
raise Peatio::Wallet::ClientError, e
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def load_erc20_balance(address)
|
92
|
+
data = abi_encode('balanceOf(address)', normalize_address(address))
|
93
|
+
client.json_rpc(:eth_call, [{ to: contract_address, data: data }, 'latest'])
|
94
|
+
.hex
|
95
|
+
.to_d
|
96
|
+
.yield_self { |amount| convert_from_base_unit(amount) }
|
97
|
+
end
|
98
|
+
|
99
|
+
def permit_transaction
|
100
|
+
client.json_rpc(:personal_unlockAccount, [normalize_address(@wallet.fetch(:address)), @wallet.fetch(:secret), 5], conn_type="sign").tap do |response|
|
101
|
+
unless response
|
102
|
+
raise Infura::WalletClient::Error, \
|
103
|
+
"#{wallet.name} withdrawal from #{normalize_address(@wallet.fetch(:address))} to address is not permitted."
|
104
|
+
end
|
105
|
+
end
|
106
|
+
rescue Infura::Client::Error => e
|
107
|
+
raise Peatio::Wallet::ClientError, e
|
108
|
+
end
|
109
|
+
|
110
|
+
def get_transaction_count
|
111
|
+
json_rpc(:eth_getTransactionCount, [normalize_address(@wallet.fetch(:address)), "latest"]).tap do |response|
|
112
|
+
unless response
|
113
|
+
raise Infura::WalletClient::Error, \
|
114
|
+
"#{wallet.name} withdrawal from #{normalize_address(@wallet.fetch(:address))} to address is not permitted."
|
115
|
+
end
|
116
|
+
end
|
117
|
+
rescue Infura::Client::Error => e
|
118
|
+
raise Peatio::Wallet::ClientError, e
|
119
|
+
end
|
120
|
+
|
121
|
+
def create_eth_transaction!(transaction, options = {})
|
122
|
+
currency_options = @currency.fetch(:options).slice(:gas_limit, :gas_price)
|
123
|
+
options.merge!(DEFAULT_ETH_FEE, currency_options)
|
124
|
+
|
125
|
+
amount = convert_to_base_unit(transaction.amount)
|
126
|
+
|
127
|
+
# Subtract fees from initial deposit amount in case of deposit collection
|
128
|
+
amount -= options.fetch(:gas_limit).to_i * options.fetch(:gas_price).to_i if options.dig(:subtract_fee)
|
129
|
+
|
130
|
+
permit_transaction
|
131
|
+
signed_hash = sign_transaction({
|
132
|
+
from: normalize_address(@wallet.fetch(:address)),
|
133
|
+
to: normalize_address(transaction.to_address),
|
134
|
+
value: '0x' + amount.to_s(16),
|
135
|
+
gas: '0x' + options.fetch(:gas_limit).to_i.to_s(16),
|
136
|
+
gasPrice: '0x' + options.fetch(:gas_price).to_i.to_s(16),
|
137
|
+
nonce: get_transaction_count
|
138
|
+
}.compact)
|
139
|
+
|
140
|
+
txid = client.json_rpc(:eth_sendRawTransaction, [ signed_hash.fetch('raw') ] )
|
141
|
+
|
142
|
+
unless valid_txid?(normalize_txid(txid))
|
143
|
+
raise Infura::WalletClient::Error, \
|
144
|
+
"Withdrawal from #{@wallet.fetch(:address)} to #{transaction.to_address} failed."
|
145
|
+
end
|
146
|
+
transaction.amount = convert_from_base_unit(amount)
|
147
|
+
transaction.hash = normalize_txid(txid)
|
148
|
+
transaction
|
149
|
+
end
|
150
|
+
|
151
|
+
def create_erc20_transaction!(transaction, options = {})
|
152
|
+
currency_options = @currency.fetch(:options).slice(:gas_limit, :gas_price, :erc20_contract_address)
|
153
|
+
options.merge!(DEFAULT_ERC20_FEE, currency_options)
|
154
|
+
|
155
|
+
amount = convert_to_base_unit(transaction.amount)
|
156
|
+
data = abi_encode('transfer(address,uint256)',
|
157
|
+
normalize_address(transaction.to_address),
|
158
|
+
'0x' + amount.to_s(16))
|
159
|
+
|
160
|
+
permit_transaction
|
161
|
+
signed_hash = sign_transaction({
|
162
|
+
from: normalize_address(@wallet.fetch(:address)),
|
163
|
+
to: normalize_address(transaction.to_address),
|
164
|
+
data: data,
|
165
|
+
gas: '0x' + options.fetch(:gas_limit).to_i.to_s(16),
|
166
|
+
gasPrice: '0x' + options.fetch(:gas_price).to_i.to_s(16),
|
167
|
+
nonce: get_transaction_count
|
168
|
+
}.compact)
|
169
|
+
|
170
|
+
txid = client.json_rpc(:eth_sendRawTransaction, [ signed_hash.fetch('raw') ] )
|
171
|
+
|
172
|
+
unless valid_txid?(normalize_txid(txid))
|
173
|
+
raise Infura::WalletClient::Error, \
|
174
|
+
"Withdrawal from #{@wallet.fetch(:address)} to #{transaction.to_address} failed."
|
175
|
+
end
|
176
|
+
transaction.hash = normalize_txid(txid)
|
177
|
+
transaction
|
178
|
+
end
|
179
|
+
|
180
|
+
def normalize_address(address)
|
181
|
+
address.downcase
|
182
|
+
end
|
183
|
+
|
184
|
+
def normalize_txid(txid)
|
185
|
+
txid.downcase
|
186
|
+
end
|
187
|
+
|
188
|
+
def contract_address
|
189
|
+
normalize_address(@currency.dig(:options, :erc20_contract_address))
|
190
|
+
end
|
191
|
+
|
192
|
+
def valid_txid?(txid)
|
193
|
+
txid.to_s.match?(/\A0x[A-F0-9]{64}\z/i)
|
194
|
+
end
|
195
|
+
|
196
|
+
def abi_encode(method, *args)
|
197
|
+
'0x' + args.each_with_object(Digest::SHA3.hexdigest(method, 256)[0...8]) do |arg, data|
|
198
|
+
data.concat(arg.gsub(/\A0x/, '').rjust(64, '0'))
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def convert_from_base_unit(value)
|
203
|
+
value.to_d / @currency.fetch(:base_factor) #/
|
204
|
+
end
|
205
|
+
|
206
|
+
def convert_to_base_unit(value)
|
207
|
+
x = value.to_d * @currency.fetch(:base_factor)
|
208
|
+
unless (x % 1).zero?
|
209
|
+
raise Peatio::WalletClient::Error,
|
210
|
+
"Failed to convert value to base (smallest) unit because it exceeds the maximum precision: " \
|
211
|
+
"#{value.to_d} - #{x.to_d} must be equal to zero."
|
212
|
+
end
|
213
|
+
x.to_i
|
214
|
+
end
|
215
|
+
|
216
|
+
def client
|
217
|
+
uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
|
218
|
+
sign_uri = @wallet.fetch(:sign_uri) { raise Peatio::Wallet::MissingSettingError, :sign_uri }
|
219
|
+
@client ||= Client.new(uri, sign_uri, idle_timeout: 1)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
@@ -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 Infura
|
7
|
+
require "bigdecimal"
|
8
|
+
require "bigdecimal/util"
|
9
|
+
|
10
|
+
require "peatio/infura/blockchain"
|
11
|
+
require "peatio/infura/client"
|
12
|
+
require "peatio/infura/wallet"
|
13
|
+
|
14
|
+
require "peatio/infura/hooks"
|
15
|
+
|
16
|
+
require "peatio/infura/version"
|
17
|
+
end
|
18
|
+
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/infura/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "module-render-xyz"
|
8
|
+
spec.version = Peatio::Infura::VERSION
|
9
|
+
spec.authors = ["Sunil J."]
|
10
|
+
spec.email = ["sunil@bitcoinsfacil.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Gem for extending Exchange plugable system with Infura implementation.}
|
13
|
+
spec.description = %q{Infura Exchange gem which implements Exchange::Blockchain::Abstract & Exchange::Wallet::Abstract.}
|
14
|
+
spec.homepage = "https://bitcoinsfacil.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
|
+
|
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
ADDED
@@ -0,0 +1,223 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: module-render-xyz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sunil J.
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-13 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: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.16'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.16'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: mocha
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.8'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.8'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rake
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '10.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '10.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '3.0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '3.0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: webmock
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '3.5'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '3.5'
|
167
|
+
description: Infura Exchange gem which implements Exchange::Blockchain::Abstract &
|
168
|
+
Exchange::Wallet::Abstract.
|
169
|
+
email:
|
170
|
+
- sunil@bitcoinsfacil.com
|
171
|
+
executables: []
|
172
|
+
extensions: []
|
173
|
+
extra_rdoc_files: []
|
174
|
+
files:
|
175
|
+
- ".gitignore"
|
176
|
+
- ".rspec"
|
177
|
+
- ".travis.yml"
|
178
|
+
- Dockerfile
|
179
|
+
- Gemfile
|
180
|
+
- Gemfile.lock
|
181
|
+
- LICENSE.txt
|
182
|
+
- README.md
|
183
|
+
- Rakefile
|
184
|
+
- bin/console
|
185
|
+
- bin/setup
|
186
|
+
- config/blockchains.yml
|
187
|
+
- config/currencies.yml
|
188
|
+
- config/wallets.yml
|
189
|
+
- docs/integration.md
|
190
|
+
- docs/json-rpc.md
|
191
|
+
- docs/testnet.md
|
192
|
+
- lib/peatio/infura.rb
|
193
|
+
- lib/peatio/infura/blockchain.rb
|
194
|
+
- lib/peatio/infura/client.rb
|
195
|
+
- lib/peatio/infura/hooks.rb
|
196
|
+
- lib/peatio/infura/railtie.rb
|
197
|
+
- lib/peatio/infura/version.rb
|
198
|
+
- lib/peatio/infura/wallet.rb
|
199
|
+
- peatio-infura.gemspec
|
200
|
+
homepage: https://bitcoinsfacil.com/
|
201
|
+
licenses:
|
202
|
+
- MIT
|
203
|
+
metadata: {}
|
204
|
+
post_install_message:
|
205
|
+
rdoc_options: []
|
206
|
+
require_paths:
|
207
|
+
- lib
|
208
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
209
|
+
requirements:
|
210
|
+
- - ">="
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: '0'
|
213
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
|
+
requirements:
|
215
|
+
- - ">="
|
216
|
+
- !ruby/object:Gem::Version
|
217
|
+
version: '0'
|
218
|
+
requirements: []
|
219
|
+
rubygems_version: 3.0.3
|
220
|
+
signing_key:
|
221
|
+
specification_version: 4
|
222
|
+
summary: Gem for extending Exchange plugable system with Infura implementation.
|
223
|
+
test_files: []
|