peatio-gold 2.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitattributes +2 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +184 -0
- data/LICENSE.txt +12 -0
- data/README.md +39 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/peatio/goldcash.rb +20 -0
- data/lib/peatio/goldcash/blockchain.rb +96 -0
- data/lib/peatio/goldcash/client.rb +56 -0
- data/lib/peatio/goldcash/hooks.rb +44 -0
- data/lib/peatio/goldcash/railtie.rb +15 -0
- data/lib/peatio/goldcash/version.rb +7 -0
- data/lib/peatio/goldcash/wallet.rb +61 -0
- data/peatio-gold.gemspec +55 -0
- metadata +275 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6b25f2ea835a26bafc21bf3b08e46737f488b8693aa104b84b283fd74ad58338
|
|
4
|
+
data.tar.gz: '082abdb1c944bfed49b2955ee143a0a77490e9b88ac9d72a391e8ff487069dec'
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 23b73a524917a23e6939b4d5cf58c66aaa76b39d2a6736995a5743dff72163ee5a681f618f01442734f16ddd8b7c2622e21791d082d5a9a77119206ad33d0b95
|
|
7
|
+
data.tar.gz: 6213f3d2e8aa9c087dcadb8732b493f5ff36256bffe69ef0d63e6ec99e047e6cdbc3b0e5a9a50a0c80fb79032ef06c9d606546de9d06ed17b6025d461c87e4cc
|
data/.gitattributes
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
peatio-gold (2.6.1)
|
|
5
|
+
activesupport (~> 5.2.3)
|
|
6
|
+
better-faraday (~> 1.0.5)
|
|
7
|
+
faraday (~> 0.17)
|
|
8
|
+
memoist (~> 0.16.0)
|
|
9
|
+
net-http-persistent (~> 3.0.1)
|
|
10
|
+
peatio (>= 0.6.3)
|
|
11
|
+
|
|
12
|
+
GEM
|
|
13
|
+
remote: https://rubygems.org/
|
|
14
|
+
specs:
|
|
15
|
+
activemodel (5.2.4.3)
|
|
16
|
+
activesupport (= 5.2.4.3)
|
|
17
|
+
activesupport (5.2.4.3)
|
|
18
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
19
|
+
i18n (>= 0.7, < 2)
|
|
20
|
+
minitest (~> 5.1)
|
|
21
|
+
tzinfo (~> 1.1)
|
|
22
|
+
addressable (2.7.0)
|
|
23
|
+
public_suffix (>= 2.0.2, < 5.0)
|
|
24
|
+
amq-protocol (2.3.1)
|
|
25
|
+
amqp (1.8.0)
|
|
26
|
+
amq-protocol (>= 2.2.0)
|
|
27
|
+
eventmachine
|
|
28
|
+
ast (2.4.0)
|
|
29
|
+
better-faraday (1.0.8)
|
|
30
|
+
activesupport (>= 4.0, < 6.0)
|
|
31
|
+
faraday (~> 0.12)
|
|
32
|
+
bunny (2.15.0)
|
|
33
|
+
amq-protocol (~> 2.3, >= 2.3.1)
|
|
34
|
+
byebug (11.1.1)
|
|
35
|
+
clamp (1.3.1)
|
|
36
|
+
coderay (1.1.2)
|
|
37
|
+
concurrent-ruby (1.1.6)
|
|
38
|
+
connection_pool (2.2.3)
|
|
39
|
+
cookiejar (0.3.3)
|
|
40
|
+
crack (0.4.3)
|
|
41
|
+
safe_yaml (~> 1.0.0)
|
|
42
|
+
daemons (1.3.1)
|
|
43
|
+
diff-lcs (1.3)
|
|
44
|
+
docile (1.3.2)
|
|
45
|
+
em-http-request (1.1.6)
|
|
46
|
+
addressable (>= 2.3.4)
|
|
47
|
+
cookiejar (!= 0.3.1)
|
|
48
|
+
em-socksify (>= 0.3)
|
|
49
|
+
eventmachine (>= 1.0.3)
|
|
50
|
+
http_parser.rb (>= 0.6.0)
|
|
51
|
+
em-socksify (0.3.2)
|
|
52
|
+
eventmachine (>= 1.0.0.beta.4)
|
|
53
|
+
em-synchrony (1.0.6)
|
|
54
|
+
eventmachine (>= 1.0.0.beta.1)
|
|
55
|
+
em-websocket (0.5.1)
|
|
56
|
+
eventmachine (>= 0.12.9)
|
|
57
|
+
http_parser.rb (~> 0.6.0)
|
|
58
|
+
eventmachine (1.2.7)
|
|
59
|
+
faraday (0.17.3)
|
|
60
|
+
multipart-post (>= 1.2, < 3)
|
|
61
|
+
faraday_middleware (0.13.1)
|
|
62
|
+
faraday (>= 0.7.4, < 1.0)
|
|
63
|
+
faye (1.3.0)
|
|
64
|
+
cookiejar (>= 0.3.0)
|
|
65
|
+
em-http-request (>= 0.3.0)
|
|
66
|
+
eventmachine (>= 0.12.0)
|
|
67
|
+
faye-websocket (>= 0.9.1)
|
|
68
|
+
multi_json (>= 1.0.0)
|
|
69
|
+
rack (>= 1.0.0)
|
|
70
|
+
websocket-driver (>= 0.5.1)
|
|
71
|
+
faye-websocket (0.10.9)
|
|
72
|
+
eventmachine (>= 0.12.0)
|
|
73
|
+
websocket-driver (>= 0.5.1)
|
|
74
|
+
hashdiff (1.0.1)
|
|
75
|
+
http_parser.rb (0.6.0)
|
|
76
|
+
i18n (1.8.3)
|
|
77
|
+
concurrent-ruby (~> 1.0)
|
|
78
|
+
io-console (0.5.6)
|
|
79
|
+
irb (1.2.3)
|
|
80
|
+
reline (>= 0.0.1)
|
|
81
|
+
jaro_winkler (1.5.4)
|
|
82
|
+
jwt (2.2.1)
|
|
83
|
+
memoist (0.16.2)
|
|
84
|
+
method_source (1.0.0)
|
|
85
|
+
minitest (5.14.1)
|
|
86
|
+
mocha (1.11.2)
|
|
87
|
+
multi_json (1.14.1)
|
|
88
|
+
multipart-post (2.1.1)
|
|
89
|
+
mysql2 (0.5.3)
|
|
90
|
+
net-http-persistent (3.0.1)
|
|
91
|
+
connection_pool (~> 2.2)
|
|
92
|
+
parallel (1.19.1)
|
|
93
|
+
parser (2.7.0.5)
|
|
94
|
+
ast (~> 2.4.0)
|
|
95
|
+
peatio (2.6.1)
|
|
96
|
+
activemodel (> 5.2, <= 6.0.0)
|
|
97
|
+
amqp
|
|
98
|
+
bunny
|
|
99
|
+
clamp
|
|
100
|
+
em-synchrony (~> 1.0)
|
|
101
|
+
em-websocket
|
|
102
|
+
eventmachine
|
|
103
|
+
faraday_middleware (~> 0.13.1)
|
|
104
|
+
faye (~> 1.2)
|
|
105
|
+
jwt
|
|
106
|
+
mysql2
|
|
107
|
+
prometheus-client
|
|
108
|
+
thin
|
|
109
|
+
prometheus-client (2.0.0)
|
|
110
|
+
pry (0.13.0)
|
|
111
|
+
coderay (~> 1.1)
|
|
112
|
+
method_source (~> 1.0)
|
|
113
|
+
pry-byebug (3.9.0)
|
|
114
|
+
byebug (~> 11.0)
|
|
115
|
+
pry (~> 0.13.0)
|
|
116
|
+
public_suffix (4.0.4)
|
|
117
|
+
rack (2.2.3)
|
|
118
|
+
rainbow (3.0.0)
|
|
119
|
+
rake (13.0.1)
|
|
120
|
+
reline (0.1.3)
|
|
121
|
+
io-console (~> 0.5)
|
|
122
|
+
rexml (3.2.4)
|
|
123
|
+
rspec (3.9.0)
|
|
124
|
+
rspec-core (~> 3.9.0)
|
|
125
|
+
rspec-expectations (~> 3.9.0)
|
|
126
|
+
rspec-mocks (~> 3.9.0)
|
|
127
|
+
rspec-core (3.9.1)
|
|
128
|
+
rspec-support (~> 3.9.1)
|
|
129
|
+
rspec-expectations (3.9.1)
|
|
130
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
131
|
+
rspec-support (~> 3.9.0)
|
|
132
|
+
rspec-mocks (3.9.1)
|
|
133
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
134
|
+
rspec-support (~> 3.9.0)
|
|
135
|
+
rspec-support (3.9.2)
|
|
136
|
+
rubocop (0.80.1)
|
|
137
|
+
jaro_winkler (~> 1.5.1)
|
|
138
|
+
parallel (~> 1.10)
|
|
139
|
+
parser (>= 2.7.0.1)
|
|
140
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
141
|
+
rexml
|
|
142
|
+
ruby-progressbar (~> 1.7)
|
|
143
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
|
144
|
+
rubocop-github (0.14.0)
|
|
145
|
+
rubocop (~> 0.59)
|
|
146
|
+
ruby-progressbar (1.10.1)
|
|
147
|
+
safe_yaml (1.0.5)
|
|
148
|
+
simplecov (0.18.5)
|
|
149
|
+
docile (~> 1.1)
|
|
150
|
+
simplecov-html (~> 0.11)
|
|
151
|
+
simplecov-html (0.12.2)
|
|
152
|
+
thin (1.7.2)
|
|
153
|
+
daemons (~> 1.0, >= 1.0.9)
|
|
154
|
+
eventmachine (~> 1.0, >= 1.0.4)
|
|
155
|
+
rack (>= 1, < 3)
|
|
156
|
+
thread_safe (0.3.6)
|
|
157
|
+
tzinfo (1.2.7)
|
|
158
|
+
thread_safe (~> 0.1)
|
|
159
|
+
unicode-display_width (1.6.1)
|
|
160
|
+
webmock (3.8.3)
|
|
161
|
+
addressable (>= 2.3.6)
|
|
162
|
+
crack (>= 0.3.2)
|
|
163
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
164
|
+
websocket-driver (0.7.2)
|
|
165
|
+
websocket-extensions (>= 0.1.0)
|
|
166
|
+
websocket-extensions (0.1.5)
|
|
167
|
+
|
|
168
|
+
PLATFORMS
|
|
169
|
+
ruby
|
|
170
|
+
|
|
171
|
+
DEPENDENCIES
|
|
172
|
+
bundler (~> 1.17)
|
|
173
|
+
irb
|
|
174
|
+
mocha (~> 1.8)
|
|
175
|
+
peatio-gold!
|
|
176
|
+
pry-byebug
|
|
177
|
+
rake (~> 13.0)
|
|
178
|
+
rspec (~> 3.0)
|
|
179
|
+
rubocop-github
|
|
180
|
+
simplecov
|
|
181
|
+
webmock (~> 3.5)
|
|
182
|
+
|
|
183
|
+
BUNDLED WITH
|
|
184
|
+
1.17.3
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Copyright (C) Alcox.biz - All Rights Reserved
|
|
2
|
+
|
|
3
|
+
NOTICE: All information contained herein is, and remains
|
|
4
|
+
the property of Alcox.biz and its suppliers, if any.
|
|
5
|
+
The intellectual and technical concepts contained herein are proprietary to Alcox.biz
|
|
6
|
+
and its suppliers and may be covered by U.S. and Foreign Patents,
|
|
7
|
+
patents in process, and are protected by trade secret or copyright law.
|
|
8
|
+
Dissemination of this information or reproduction of this material
|
|
9
|
+
is strictly forbidden unless prior written permission is obtained
|
|
10
|
+
from Alcox.biz.
|
|
11
|
+
|
|
12
|
+
Proprietary and confidential
|
data/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Peatio::Goldcash
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/peatio/gold`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'peatio-goldcash'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install peatio-gold
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/alcoxbiz/peatio-gold.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "peatio/goldcash"
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
+
# require "pry"
|
|
12
|
+
# Pry.start
|
|
13
|
+
|
|
14
|
+
require "irb"
|
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_support/core_ext/object/blank"
|
|
4
|
+
require "active_support/core_ext/enumerable"
|
|
5
|
+
require "peatio"
|
|
6
|
+
|
|
7
|
+
module Peatio
|
|
8
|
+
module Goldcash
|
|
9
|
+
require "bigdecimal"
|
|
10
|
+
require "bigdecimal/util"
|
|
11
|
+
|
|
12
|
+
require "peatio/goldcash/blockchain"
|
|
13
|
+
require "peatio/goldcash/client"
|
|
14
|
+
require "peatio/goldcash/wallet"
|
|
15
|
+
|
|
16
|
+
require "peatio/goldcash/hooks"
|
|
17
|
+
|
|
18
|
+
require "peatio/goldcash/version"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Peatio
|
|
4
|
+
module Goldcash
|
|
5
|
+
# TODO: Processing of unconfirmed transactions from mempool isn't supported now.
|
|
6
|
+
class Blockchain < Peatio::Blockchain::Abstract
|
|
7
|
+
|
|
8
|
+
DEFAULT_FEATURES = {case_sensitive: true, cash_addr_format: false}.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
|
+
@settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def fetch_block!(block_number)
|
|
22
|
+
block_hash = client.json_rpc(:getblockhash, [block_number])
|
|
23
|
+
|
|
24
|
+
client.json_rpc(:getblock, [block_hash])
|
|
25
|
+
.fetch('tx').each_with_object([]) do |tx, txs_array|
|
|
26
|
+
txs = build_transaction(tx).map do |ntx|
|
|
27
|
+
Peatio::Transaction.new(ntx.merge(block_number: block_number))
|
|
28
|
+
end
|
|
29
|
+
txs_array.append(*txs)
|
|
30
|
+
end.yield_self { |txs_array| Peatio::Block.new(block_number, txs_array) }
|
|
31
|
+
rescue Goldcash::Client::Error => e
|
|
32
|
+
raise Peatio::Blockchain::ClientError, e
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def latest_block_number
|
|
36
|
+
client.json_rpc(:getblockcount)
|
|
37
|
+
rescue Goldcash::Client::Error => e
|
|
38
|
+
raise Peatio::Blockchain::ClientError, e
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def transaction_sources(transaction)
|
|
42
|
+
transaction_hash = client.json_rpc(:getrawtransaction, [transaction.hash, 1])
|
|
43
|
+
transaction_hash['vin'].each_with_object([]) do |vin, source_addresses|
|
|
44
|
+
next if vin['txid'].blank?
|
|
45
|
+
|
|
46
|
+
vin_transaction = client.json_rpc(:getrawtransaction, [vin['txid'], 1])
|
|
47
|
+
source = vin_transaction['vout'].find { |hash| hash['n'] == vin['vout'] }
|
|
48
|
+
source_addresses << source['scriptPubKey']['addresses'][0]
|
|
49
|
+
end.compact.uniq
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def load_balance_of_address!(address, _currency_id)
|
|
53
|
+
address_with_balance = client.json_rpc(:listaddressgroupings)
|
|
54
|
+
.flatten(1)
|
|
55
|
+
.find { |addr| addr[0] == address }
|
|
56
|
+
|
|
57
|
+
if address_with_balance.blank?
|
|
58
|
+
raise Peatio::Blockchain::UnavailableAddressBalanceError, address
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
address_with_balance[1].to_d
|
|
62
|
+
rescue Goldcash::Client::Error => e
|
|
63
|
+
raise Peatio::Blockchain::ClientError, e
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
def build_transaction(tx_hash)
|
|
69
|
+
tx_hash.fetch('vout')
|
|
70
|
+
.select do |entry|
|
|
71
|
+
entry.fetch('value').to_d > 0 &&
|
|
72
|
+
entry['scriptPubKey'].has_key?('addresses')
|
|
73
|
+
end
|
|
74
|
+
.each_with_object([]) do |entry, formatted_txs|
|
|
75
|
+
no_currency_tx =
|
|
76
|
+
{ hash: tx_hash['txid'], txout: entry['n'],
|
|
77
|
+
to_address: entry['scriptPubKey']['addresses'][0],
|
|
78
|
+
amount: entry.fetch('value').to_d,
|
|
79
|
+
status: 'success' }
|
|
80
|
+
|
|
81
|
+
# Build transaction for each currency belonging to blockchain.
|
|
82
|
+
settings_fetch(:currencies).pluck(:id).each do |currency_id|
|
|
83
|
+
formatted_txs << no_currency_tx.merge(currency_id: currency_id)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def client
|
|
89
|
+
@client ||= Goldcash::Client.new(settings_fetch(:server))
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def settings_fetch(key)
|
|
93
|
+
@settings.fetch(key) { raise Peatio::Blockchain::MissingSettingError, key.to_s }
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "memoist"
|
|
4
|
+
require "faraday"
|
|
5
|
+
require "better-faraday"
|
|
6
|
+
|
|
7
|
+
module Peatio
|
|
8
|
+
module Goldcash
|
|
9
|
+
class Client
|
|
10
|
+
Error = Class.new(StandardError)
|
|
11
|
+
|
|
12
|
+
class ConnectionError < Error; end
|
|
13
|
+
|
|
14
|
+
class ResponseError < Error
|
|
15
|
+
def initialize(code, msg)
|
|
16
|
+
super "#{msg} (#{code})"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
extend Memoist
|
|
21
|
+
|
|
22
|
+
def initialize(endpoint, idle_timeout: 5)
|
|
23
|
+
@json_rpc_endpoint = URI.parse(endpoint)
|
|
24
|
+
@path = @json_rpc_endpoint.path.empty? ? "/" : @json_rpc_endpoint.path
|
|
25
|
+
@idle_timeout = idle_timeout
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def json_rpc(method, params = [])
|
|
29
|
+
response = connection.post \
|
|
30
|
+
@path,
|
|
31
|
+
{jsonrpc: '1.0', method: method, params: params}.to_json,
|
|
32
|
+
{'Accept' => 'application/json',
|
|
33
|
+
'Content-Type' => 'application/json'}
|
|
34
|
+
response.assert_success!
|
|
35
|
+
response = JSON.parse(response.body)
|
|
36
|
+
response['error'].tap { |error| raise ResponseError.new(error['code'], error['message']) if error }
|
|
37
|
+
response.fetch('result')
|
|
38
|
+
rescue Faraday::Error => e
|
|
39
|
+
raise ConnectionError, e
|
|
40
|
+
rescue StandardError => e
|
|
41
|
+
raise Error, e
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def connection
|
|
47
|
+
@connection ||= Faraday.new(@json_rpc_endpoint) do |f|
|
|
48
|
+
f.adapter :net_http_persistent, pool_size: 5, idle_timeout: @idle_timeout
|
|
49
|
+
end.tap do |connection|
|
|
50
|
+
unless @json_rpc_endpoint.user.blank?
|
|
51
|
+
connection.basic_auth(@json_rpc_endpoint.user, @json_rpc_endpoint.password)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Peatio
|
|
4
|
+
module Goldcash
|
|
5
|
+
module Hooks
|
|
6
|
+
BLOCKCHAIN_VERSION_REQUIREMENT = "~> 1.0.0"
|
|
7
|
+
WALLET_VERSION_REQUIREMENT = "~> 1.0.0"
|
|
8
|
+
|
|
9
|
+
class << self
|
|
10
|
+
def check_compatibility
|
|
11
|
+
unless Gem::Requirement.new(BLOCKCHAIN_VERSION_REQUIREMENT)
|
|
12
|
+
.satisfied_by?(Gem::Version.new(Peatio::Blockchain::VERSION))
|
|
13
|
+
[
|
|
14
|
+
"Goldcash blockchain version requiremnt was not suttisfied by Peatio::Blockchain.",
|
|
15
|
+
"Goldcash blockchain requires #{BLOCKCHAIN_VERSION_REQUIREMENT}.",
|
|
16
|
+
"Peatio::Blockchain version is #{Peatio::Blockchain::VERSION}"
|
|
17
|
+
].join('\n').tap {|s| Kernel.abort s }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
unless Gem::Requirement.new(WALLET_VERSION_REQUIREMENT)
|
|
21
|
+
.satisfied_by?(Gem::Version.new(Peatio::Wallet::VERSION))
|
|
22
|
+
[
|
|
23
|
+
"Goldcash wallet version requiremnt was not suttisfied by Peatio::Wallet.",
|
|
24
|
+
"Goldcash wallet requires #{WALLET_VERSION_REQUIREMENT}.",
|
|
25
|
+
"Peatio::Wallet version is #{Peatio::Wallet::VERSION}"
|
|
26
|
+
].join('\n').tap {|s| Kernel.abort s }
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def register
|
|
31
|
+
Peatio::Blockchain.registry[:goldcashcash] = Goldcash::Blockchain
|
|
32
|
+
Peatio::Wallet.registry[:goldcashcashd] = Goldcash::Wallet
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
if defined?(Rails::Railtie)
|
|
37
|
+
require "peatio/goldcashcash/railtie"
|
|
38
|
+
else
|
|
39
|
+
check_compatibility
|
|
40
|
+
register
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Peatio
|
|
4
|
+
module Goldcash
|
|
5
|
+
class Wallet < Peatio::Wallet::Abstract
|
|
6
|
+
|
|
7
|
+
def initialize(settings = {})
|
|
8
|
+
@settings = settings
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def configure(settings = {})
|
|
12
|
+
# Clean client state during configure.
|
|
13
|
+
@client = nil
|
|
14
|
+
|
|
15
|
+
@settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
|
|
16
|
+
|
|
17
|
+
@wallet = @settings.fetch(:wallet) do
|
|
18
|
+
raise Peatio::Wallet::MissingSettingError, :wallet
|
|
19
|
+
end.slice(:uri, :address)
|
|
20
|
+
|
|
21
|
+
@currency = @settings.fetch(:currency) do
|
|
22
|
+
raise Peatio::Wallet::MissingSettingError, :currency
|
|
23
|
+
end.slice(:id, :base_factor, :options)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def create_address!(_options = {})
|
|
27
|
+
{ address: client.json_rpc(:getnewaddress) }
|
|
28
|
+
rescue Goldcash::Client::Error => e
|
|
29
|
+
raise Peatio::Wallet::ClientError, e
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def create_transaction!(transaction, options = {})
|
|
33
|
+
txid = client.json_rpc(:sendtoaddress,
|
|
34
|
+
[
|
|
35
|
+
transaction.to_address,
|
|
36
|
+
transaction.amount,
|
|
37
|
+
'',
|
|
38
|
+
'',
|
|
39
|
+
options[:subtract_fee].to_s == 'true' # subtract fee from transaction amount.
|
|
40
|
+
])
|
|
41
|
+
transaction.hash = txid
|
|
42
|
+
transaction
|
|
43
|
+
rescue Goldcash::Client::Error => e
|
|
44
|
+
raise Peatio::Wallet::ClientError, e
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def load_balance!
|
|
48
|
+
client.json_rpc(:getbalance).to_d
|
|
49
|
+
|
|
50
|
+
rescue Goldcash::Client::Error => e
|
|
51
|
+
raise Peatio::Wallet::ClientError, e
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def client
|
|
57
|
+
uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
|
|
58
|
+
@client ||= Client.new(uri, idle_timeout: 1)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
data/peatio-gold.gemspec
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require "peatio/goldcash/version"
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = "peatio-gold"
|
|
9
|
+
spec.version = Peatio::Goldcash::VERSION
|
|
10
|
+
spec.authors = ["D.H."]
|
|
11
|
+
spec.email = ["dh@alcox.biz"]
|
|
12
|
+
|
|
13
|
+
spec.summary = "Peatio Blockchain Plugin"
|
|
14
|
+
spec.description = "Peatio Blockchain Plugin for Rubykube"
|
|
15
|
+
spec.homepage = "https://www.alcox.biz"
|
|
16
|
+
spec.license = "Proprietary"
|
|
17
|
+
|
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
20
|
+
if spec.respond_to?(:metadata)
|
|
21
|
+
|
|
22
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
23
|
+
spec.metadata["source_code_uri"] = "https://github.com/alcoxbiz/peatio-gold"
|
|
24
|
+
spec.metadata["changelog_uri"] = "https://github.com/alcoxbiz/peatio-gold/blob/master/CHANGELOG.md"
|
|
25
|
+
else
|
|
26
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
|
27
|
+
"public gem pushes."
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
32
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
33
|
+
`git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
|
|
34
|
+
end
|
|
35
|
+
spec.bindir = "exe"
|
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
|
|
37
|
+
spec.require_paths = ["lib"]
|
|
38
|
+
|
|
39
|
+
spec.add_dependency "activesupport", "~> 5.2.3"
|
|
40
|
+
spec.add_dependency "better-faraday", "~> 1.0.5"
|
|
41
|
+
spec.add_dependency "faraday", "~> 0.17"
|
|
42
|
+
spec.add_dependency "memoist", "~> 0.16.0"
|
|
43
|
+
spec.add_dependency "peatio", ">= 0.6.3"
|
|
44
|
+
spec.add_dependency 'net-http-persistent', '~> 3.0.1'
|
|
45
|
+
|
|
46
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
|
47
|
+
spec.add_development_dependency "irb"
|
|
48
|
+
spec.add_development_dependency "mocha", "~> 1.8"
|
|
49
|
+
spec.add_development_dependency "pry-byebug"
|
|
50
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
|
51
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
52
|
+
spec.add_development_dependency "rubocop-github"
|
|
53
|
+
spec.add_development_dependency "simplecov"
|
|
54
|
+
spec.add_development_dependency "webmock", "~> 3.5"
|
|
55
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: peatio-gold
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 2.6.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- D.H.
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-09-06 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.17'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0.17'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: memoist
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.16.0
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 0.16.0
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: peatio
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: 0.6.3
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: 0.6.3
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: net-http-persistent
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: 3.0.1
|
|
90
|
+
type: :runtime
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: 3.0.1
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: bundler
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '1.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: irb
|
|
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: mocha
|
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - "~>"
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '1.8'
|
|
132
|
+
type: :development
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - "~>"
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '1.8'
|
|
139
|
+
- !ruby/object:Gem::Dependency
|
|
140
|
+
name: pry-byebug
|
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
|
142
|
+
requirements:
|
|
143
|
+
- - ">="
|
|
144
|
+
- !ruby/object:Gem::Version
|
|
145
|
+
version: '0'
|
|
146
|
+
type: :development
|
|
147
|
+
prerelease: false
|
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - ">="
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '0'
|
|
153
|
+
- !ruby/object:Gem::Dependency
|
|
154
|
+
name: rake
|
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - "~>"
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: '13.0'
|
|
160
|
+
type: :development
|
|
161
|
+
prerelease: false
|
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
163
|
+
requirements:
|
|
164
|
+
- - "~>"
|
|
165
|
+
- !ruby/object:Gem::Version
|
|
166
|
+
version: '13.0'
|
|
167
|
+
- !ruby/object:Gem::Dependency
|
|
168
|
+
name: rspec
|
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
|
170
|
+
requirements:
|
|
171
|
+
- - "~>"
|
|
172
|
+
- !ruby/object:Gem::Version
|
|
173
|
+
version: '3.0'
|
|
174
|
+
type: :development
|
|
175
|
+
prerelease: false
|
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
177
|
+
requirements:
|
|
178
|
+
- - "~>"
|
|
179
|
+
- !ruby/object:Gem::Version
|
|
180
|
+
version: '3.0'
|
|
181
|
+
- !ruby/object:Gem::Dependency
|
|
182
|
+
name: rubocop-github
|
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
|
184
|
+
requirements:
|
|
185
|
+
- - ">="
|
|
186
|
+
- !ruby/object:Gem::Version
|
|
187
|
+
version: '0'
|
|
188
|
+
type: :development
|
|
189
|
+
prerelease: false
|
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
191
|
+
requirements:
|
|
192
|
+
- - ">="
|
|
193
|
+
- !ruby/object:Gem::Version
|
|
194
|
+
version: '0'
|
|
195
|
+
- !ruby/object:Gem::Dependency
|
|
196
|
+
name: simplecov
|
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
|
198
|
+
requirements:
|
|
199
|
+
- - ">="
|
|
200
|
+
- !ruby/object:Gem::Version
|
|
201
|
+
version: '0'
|
|
202
|
+
type: :development
|
|
203
|
+
prerelease: false
|
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
205
|
+
requirements:
|
|
206
|
+
- - ">="
|
|
207
|
+
- !ruby/object:Gem::Version
|
|
208
|
+
version: '0'
|
|
209
|
+
- !ruby/object:Gem::Dependency
|
|
210
|
+
name: webmock
|
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
|
212
|
+
requirements:
|
|
213
|
+
- - "~>"
|
|
214
|
+
- !ruby/object:Gem::Version
|
|
215
|
+
version: '3.5'
|
|
216
|
+
type: :development
|
|
217
|
+
prerelease: false
|
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
219
|
+
requirements:
|
|
220
|
+
- - "~>"
|
|
221
|
+
- !ruby/object:Gem::Version
|
|
222
|
+
version: '3.5'
|
|
223
|
+
description: Peatio Blockchain Plugin for Rubykube
|
|
224
|
+
email:
|
|
225
|
+
- dh@alcox.biz
|
|
226
|
+
executables: []
|
|
227
|
+
extensions: []
|
|
228
|
+
extra_rdoc_files: []
|
|
229
|
+
files:
|
|
230
|
+
- ".gitattributes"
|
|
231
|
+
- ".gitignore"
|
|
232
|
+
- ".rspec"
|
|
233
|
+
- ".travis.yml"
|
|
234
|
+
- Gemfile
|
|
235
|
+
- Gemfile.lock
|
|
236
|
+
- LICENSE.txt
|
|
237
|
+
- README.md
|
|
238
|
+
- Rakefile
|
|
239
|
+
- bin/console
|
|
240
|
+
- bin/setup
|
|
241
|
+
- lib/peatio/goldcash.rb
|
|
242
|
+
- lib/peatio/goldcash/blockchain.rb
|
|
243
|
+
- lib/peatio/goldcash/client.rb
|
|
244
|
+
- lib/peatio/goldcash/hooks.rb
|
|
245
|
+
- lib/peatio/goldcash/railtie.rb
|
|
246
|
+
- lib/peatio/goldcash/version.rb
|
|
247
|
+
- lib/peatio/goldcash/wallet.rb
|
|
248
|
+
- peatio-gold.gemspec
|
|
249
|
+
homepage: https://www.alcox.biz
|
|
250
|
+
licenses:
|
|
251
|
+
- Proprietary
|
|
252
|
+
metadata:
|
|
253
|
+
homepage_uri: https://www.alcox.biz
|
|
254
|
+
source_code_uri: https://github.com/alcoxbiz/peatio-gold
|
|
255
|
+
changelog_uri: https://github.com/alcoxbiz/peatio-gold/blob/master/CHANGELOG.md
|
|
256
|
+
post_install_message:
|
|
257
|
+
rdoc_options: []
|
|
258
|
+
require_paths:
|
|
259
|
+
- lib
|
|
260
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
261
|
+
requirements:
|
|
262
|
+
- - ">="
|
|
263
|
+
- !ruby/object:Gem::Version
|
|
264
|
+
version: '0'
|
|
265
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
266
|
+
requirements:
|
|
267
|
+
- - ">="
|
|
268
|
+
- !ruby/object:Gem::Version
|
|
269
|
+
version: '0'
|
|
270
|
+
requirements: []
|
|
271
|
+
rubygems_version: 3.0.6
|
|
272
|
+
signing_key:
|
|
273
|
+
specification_version: 4
|
|
274
|
+
summary: Peatio Blockchain Plugin
|
|
275
|
+
test_files: []
|