peatio-decredcoin 2.0.0 → 2.0.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 +4 -4
- data/.idea/.gitignore +8 -0
- data/.idea/decred-coin.iml +17 -0
- data/.idea/encodings.xml +4 -0
- data/.idea/inspectionProfiles/Project_Default.xml +6 -0
- data/.idea/misc.xml +4 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +151 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/decredcoin.gemspec +38 -0
- data/lib/peatio/decredcoin.rb +18 -0
- data/lib/peatio/decredcoin/blockchain.rb +84 -0
- data/lib/peatio/decredcoin/client.rb +62 -0
- data/lib/peatio/decredcoin/hooks.rb +42 -0
- data/lib/peatio/decredcoin/railtie.rb +13 -0
- data/lib/peatio/decredcoin/version.rb +5 -0
- data/lib/peatio/decredcoin/wallet.rb +63 -0
- metadata +22 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a6e7c138c5e6f375938b152cbb89df856f20be19821d7f3aa63b3eea91be2c5
|
4
|
+
data.tar.gz: 819b6b234844c242713aaf8472c6020d6325145f348c099ec0f083d42dc75ab8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c10f34b4c6762d333dbfbb77c0431702f528ef04cb20ed503eae049bdb61ec5483ffa418e93a31ea4740a3545bdd12c25f3e9eda0d5b75b03a2d1f294f4087e6
|
7
|
+
data.tar.gz: bd636a00b5ddd8b5f9fadb948d4cd97d37381d5197ac68fe6d6b1d33e5c774b04f480f27163331b4675729ed06b6c1902af71a0070cf03b89e4241ad69355cde
|
data/.idea/.gitignore
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
4
|
+
<shared />
|
5
|
+
</component>
|
6
|
+
<component name="NewModuleRootManager">
|
7
|
+
<content url="file://$MODULE_DIR$">
|
8
|
+
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
|
9
|
+
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
10
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
11
|
+
</content>
|
12
|
+
<orderEntry type="inheritedJdk" />
|
13
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.1.4, RVM: ruby-2.7.1 [global]) [gem]" level="application" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.1, RVM: ruby-2.7.1 [global]) [gem]" level="application" />
|
16
|
+
</component>
|
17
|
+
</module>
|
data/.idea/encodings.xml
ADDED
data/.idea/misc.xml
ADDED
data/.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/decred-coin.iml" filepath="$PROJECT_DIR$/.idea/decred-coin.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
data/.idea/vcs.xml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
peatio-decredcoin (2.0.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.4)
|
16
|
+
activesupport (= 5.2.4.4)
|
17
|
+
activesupport (5.2.4.4)
|
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.2)
|
25
|
+
amqp (1.8.0)
|
26
|
+
amq-protocol (>= 2.2.0)
|
27
|
+
eventmachine
|
28
|
+
better-faraday (1.0.8)
|
29
|
+
activesupport (>= 4.0, < 6.0)
|
30
|
+
faraday (~> 0.12)
|
31
|
+
bunny (2.17.0)
|
32
|
+
amq-protocol (~> 2.3, >= 2.3.1)
|
33
|
+
byebug (11.1.3)
|
34
|
+
clamp (1.3.2)
|
35
|
+
coderay (1.1.3)
|
36
|
+
concurrent-ruby (1.1.7)
|
37
|
+
connection_pool (2.2.3)
|
38
|
+
cookiejar (0.3.3)
|
39
|
+
crack (0.4.4)
|
40
|
+
daemons (1.3.1)
|
41
|
+
diff-lcs (1.4.4)
|
42
|
+
em-http-request (1.1.7)
|
43
|
+
addressable (>= 2.3.4)
|
44
|
+
cookiejar (!= 0.3.1)
|
45
|
+
em-socksify (>= 0.3)
|
46
|
+
eventmachine (>= 1.0.3)
|
47
|
+
http_parser.rb (>= 0.6.0)
|
48
|
+
em-socksify (0.3.2)
|
49
|
+
eventmachine (>= 1.0.0.beta.4)
|
50
|
+
em-synchrony (1.0.6)
|
51
|
+
eventmachine (>= 1.0.0.beta.1)
|
52
|
+
em-websocket (0.5.2)
|
53
|
+
eventmachine (>= 0.12.9)
|
54
|
+
http_parser.rb (~> 0.6.0)
|
55
|
+
eventmachine (1.2.7)
|
56
|
+
faraday (0.17.3)
|
57
|
+
multipart-post (>= 1.2, < 3)
|
58
|
+
faraday_middleware (0.13.1)
|
59
|
+
faraday (>= 0.7.4, < 1.0)
|
60
|
+
faye (1.4.0)
|
61
|
+
cookiejar (>= 0.3.0)
|
62
|
+
em-http-request (>= 1.1.6)
|
63
|
+
eventmachine (>= 0.12.0)
|
64
|
+
faye-websocket (>= 0.11.0)
|
65
|
+
multi_json (>= 1.0.0)
|
66
|
+
rack (>= 1.0.0)
|
67
|
+
websocket-driver (>= 0.5.1)
|
68
|
+
faye-websocket (0.11.0)
|
69
|
+
eventmachine (>= 0.12.0)
|
70
|
+
websocket-driver (>= 0.5.1)
|
71
|
+
hashdiff (1.0.1)
|
72
|
+
http_parser.rb (0.6.0)
|
73
|
+
i18n (1.8.5)
|
74
|
+
concurrent-ruby (~> 1.0)
|
75
|
+
jwt (2.2.2)
|
76
|
+
memoist (0.16.2)
|
77
|
+
method_source (1.0.0)
|
78
|
+
minitest (5.14.2)
|
79
|
+
mocha (1.11.2)
|
80
|
+
multi_json (1.15.0)
|
81
|
+
multipart-post (2.1.1)
|
82
|
+
mysql2 (0.5.3)
|
83
|
+
net-http-persistent (3.0.1)
|
84
|
+
connection_pool (~> 2.2)
|
85
|
+
peatio (2.6.2)
|
86
|
+
activemodel (> 5.2, <= 6.0.0)
|
87
|
+
amqp
|
88
|
+
bunny
|
89
|
+
clamp
|
90
|
+
em-synchrony (~> 1.0)
|
91
|
+
em-websocket
|
92
|
+
eventmachine
|
93
|
+
faraday_middleware (~> 0.13.1)
|
94
|
+
faye (~> 1.2)
|
95
|
+
jwt
|
96
|
+
mysql2
|
97
|
+
prometheus-client
|
98
|
+
thin
|
99
|
+
prometheus-client (2.1.0)
|
100
|
+
pry (0.13.1)
|
101
|
+
coderay (~> 1.1)
|
102
|
+
method_source (~> 1.0)
|
103
|
+
pry-byebug (3.9.0)
|
104
|
+
byebug (~> 11.0)
|
105
|
+
pry (~> 0.13.0)
|
106
|
+
public_suffix (4.0.6)
|
107
|
+
rack (2.2.3)
|
108
|
+
rake (13.0.1)
|
109
|
+
rspec (3.9.0)
|
110
|
+
rspec-core (~> 3.9.0)
|
111
|
+
rspec-expectations (~> 3.9.0)
|
112
|
+
rspec-mocks (~> 3.9.0)
|
113
|
+
rspec-core (3.9.3)
|
114
|
+
rspec-support (~> 3.9.3)
|
115
|
+
rspec-expectations (3.9.3)
|
116
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
117
|
+
rspec-support (~> 3.9.0)
|
118
|
+
rspec-mocks (3.9.1)
|
119
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
120
|
+
rspec-support (~> 3.9.0)
|
121
|
+
rspec-support (3.9.4)
|
122
|
+
thin (1.8.0)
|
123
|
+
daemons (~> 1.0, >= 1.0.9)
|
124
|
+
eventmachine (~> 1.0, >= 1.0.4)
|
125
|
+
rack (>= 1, < 3)
|
126
|
+
thread_safe (0.3.6)
|
127
|
+
tzinfo (1.2.8)
|
128
|
+
thread_safe (~> 0.1)
|
129
|
+
webmock (3.9.3)
|
130
|
+
addressable (>= 2.3.6)
|
131
|
+
crack (>= 0.3.2)
|
132
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
133
|
+
websocket-driver (0.7.3)
|
134
|
+
websocket-extensions (>= 0.1.0)
|
135
|
+
websocket-extensions (0.1.5)
|
136
|
+
|
137
|
+
PLATFORMS
|
138
|
+
ruby
|
139
|
+
|
140
|
+
DEPENDENCIES
|
141
|
+
bundler (~> 2.1.4)
|
142
|
+
mocha (~> 1.8)
|
143
|
+
peatio-decredcoin!
|
144
|
+
pry
|
145
|
+
pry-byebug
|
146
|
+
rake (~> 13.0)
|
147
|
+
rspec (~> 3.0)
|
148
|
+
webmock (~> 3.5)
|
149
|
+
|
150
|
+
BUNDLED WITH
|
151
|
+
2.1.4
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "peatio/decredcoin"
|
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
data/decredcoin.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "peatio/decredcoin/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "peatio-decredcoin"
|
7
|
+
spec.version = Peatio::Decredcoin::VERSION
|
8
|
+
spec.authors = ["Anuj Dhiman"]
|
9
|
+
spec.email = ["dhimananuj93@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Gem for extending Peatio plugable system with DecredCoin implementation.}
|
12
|
+
spec.description = %q{Decredcoin Peatio gem which implements Peatio::Blockchain::Abstract & Peatio::Wallet::Abstract.}
|
13
|
+
spec.homepage = "https://openware.com/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "activesupport", "~> 5.2.3"
|
25
|
+
spec.add_dependency "better-faraday", "~> 1.0.5"
|
26
|
+
spec.add_dependency "faraday", "~> 0.17"
|
27
|
+
spec.add_dependency "memoist", "~> 0.16.0"
|
28
|
+
spec.add_dependency "peatio", ">= 0.6.3"
|
29
|
+
spec.add_dependency 'net-http-persistent', '~> 3.0.1'
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 2.1.4"
|
32
|
+
spec.add_development_dependency "mocha", "~> 1.8"
|
33
|
+
spec.add_development_dependency "pry-byebug"
|
34
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_development_dependency "webmock", "~> 3.5"
|
37
|
+
spec.add_development_dependency "pry"
|
38
|
+
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 Decredcoin
|
7
|
+
require "bigdecimal"
|
8
|
+
require "bigdecimal/util"
|
9
|
+
|
10
|
+
require "peatio/decredcoin/blockchain"
|
11
|
+
require "peatio/decredcoin/client"
|
12
|
+
require "peatio/decredcoin/wallet"
|
13
|
+
|
14
|
+
require "peatio/decredcoin/hooks"
|
15
|
+
|
16
|
+
require "peatio/decredcoin/version"
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Peatio
|
2
|
+
module Decredcoin
|
3
|
+
# TODO: Processing of unconfirmed transactions from mempool isn't supported now.
|
4
|
+
class Blockchain < Peatio::Blockchain::Abstract
|
5
|
+
|
6
|
+
DEFAULT_FEATURES = {case_sensitive: true, cash_addr_format: false}.freeze
|
7
|
+
|
8
|
+
def initialize(custom_features = {})
|
9
|
+
@features = DEFAULT_FEATURES.merge(custom_features).slice(*SUPPORTED_FEATURES)
|
10
|
+
@settings = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure(settings = {})
|
14
|
+
# Clean client state during configure.
|
15
|
+
@client = nil
|
16
|
+
@settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
|
17
|
+
end
|
18
|
+
|
19
|
+
def fetch_block!(block_number)
|
20
|
+
block_hash = client.json_rpc(:getblockhash, [block_number])
|
21
|
+
|
22
|
+
client.json_rpc(:getblock, [block_hash, 2])
|
23
|
+
.fetch('tx').each_with_object([]) do |tx, txs_array|
|
24
|
+
txs = build_transaction(tx).map do |ntx|
|
25
|
+
Peatio::Transaction.new(ntx.merge(block_number: block_number))
|
26
|
+
end
|
27
|
+
txs_array.append(*txs)
|
28
|
+
end.yield_self { |txs_array| Peatio::Block.new(block_number, txs_array) }
|
29
|
+
rescue Client::Error => e
|
30
|
+
raise Peatio::Blockchain::ClientError, e
|
31
|
+
end
|
32
|
+
|
33
|
+
def latest_block_number
|
34
|
+
client.json_rpc(:getblockcount)
|
35
|
+
rescue Client::Error => e
|
36
|
+
raise Peatio::Blockchain::ClientError, e
|
37
|
+
end
|
38
|
+
|
39
|
+
def load_balance_of_address!(address, _currency_id)
|
40
|
+
address_with_balance = client.json_rpc(:listaddressgroupings)
|
41
|
+
.flatten(1)
|
42
|
+
.find { |addr| addr[0] == address }
|
43
|
+
|
44
|
+
if address_with_balance.blank?
|
45
|
+
raise Peatio::Blockchain::UnavailableAddressBalanceError, address
|
46
|
+
end
|
47
|
+
|
48
|
+
address_with_balance[1].to_d
|
49
|
+
rescue Client::Error => e
|
50
|
+
raise Peatio::Blockchain::ClientError, e
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def build_transaction(tx_hash)
|
56
|
+
tx_hash.fetch('vout')
|
57
|
+
.select do |entry|
|
58
|
+
entry.fetch('value').to_d > 0 &&
|
59
|
+
entry['scriptPubKey'].has_key?('addresses')
|
60
|
+
end
|
61
|
+
.each_with_object([]) do |entry, formatted_txs|
|
62
|
+
no_currency_tx =
|
63
|
+
{ hash: tx_hash['txid'], txout: entry['n'],
|
64
|
+
to_address: entry['scriptPubKey']['addresses'][0],
|
65
|
+
amount: entry.fetch('value').to_d,
|
66
|
+
status: 'success' }
|
67
|
+
|
68
|
+
# Build transaction for each currency belonging to blockchain.
|
69
|
+
settings_fetch(:currencies).pluck(:id).each do |currency_id|
|
70
|
+
formatted_txs << no_currency_tx.merge(currency_id: currency_id)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def client
|
76
|
+
@client ||= Client.new(settings_fetch(:server))
|
77
|
+
end
|
78
|
+
|
79
|
+
def settings_fetch(key)
|
80
|
+
@settings.fetch(key) { raise Peatio::Blockchain::MissingSettingError, key.to_s }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'memoist'
|
4
|
+
require 'faraday'
|
5
|
+
require 'better-faraday'
|
6
|
+
|
7
|
+
module Peatio
|
8
|
+
module Decredcoin
|
9
|
+
class Client
|
10
|
+
Error = Class.new(StandardError)
|
11
|
+
ConnectionError = Class.new(Error)
|
12
|
+
|
13
|
+
class ResponseError < Error
|
14
|
+
def initialize(code, msg)
|
15
|
+
@code = code
|
16
|
+
@msg = msg
|
17
|
+
end
|
18
|
+
|
19
|
+
def message
|
20
|
+
"#{@msg} (#{@code})"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
extend Memoist
|
25
|
+
|
26
|
+
def initialize(endpoint, is_secure = false)
|
27
|
+
@json_rpc_endpoint = URI.parse(endpoint)
|
28
|
+
@is_secure = is_secure
|
29
|
+
end
|
30
|
+
|
31
|
+
def json_rpc(method, params = [])
|
32
|
+
response = connection.post \
|
33
|
+
'/',
|
34
|
+
{ jsonrpc: '2.0', method: method, params: params }.to_json,
|
35
|
+
{ 'Accept' => 'application/json',
|
36
|
+
'Content-Type' => 'application/json' }
|
37
|
+
response.assert_2xx!
|
38
|
+
response = JSON.parse(response.body)
|
39
|
+
response['error'].tap do |e|
|
40
|
+
raise ResponseError.new(e['code'], e['message']) if e
|
41
|
+
end
|
42
|
+
response.fetch('result')
|
43
|
+
rescue Faraday::Error => e
|
44
|
+
raise ConnectionError, e
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def connection
|
50
|
+
@connection ||= Faraday.new(@json_rpc_endpoint) do |f|
|
51
|
+
f.adapter :net_http_persistent, pool_size: 5
|
52
|
+
f.ssl[:verify] = @is_secure
|
53
|
+
end.tap do |connection|
|
54
|
+
unless @json_rpc_endpoint.user.blank?
|
55
|
+
connection.basic_auth(@json_rpc_endpoint.user,
|
56
|
+
@json_rpc_endpoint.password)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Peatio
|
2
|
+
module Decredcoin
|
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
|
+
"Decredcoin blockchain version requirement was not suttisfied by Peatio::Blockchain.",
|
13
|
+
"Decredcoin 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
|
+
"Decredcoin wallet version requirement was not satisfied by Peatio::Wallet.",
|
22
|
+
"Decredcoin 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[:decredcoin] = Decredcoin::Blockchain
|
30
|
+
Peatio::Wallet.registry[:decredcoind] = Decredcoin::Wallet
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if defined?(Rails::Railtie)
|
35
|
+
require "peatio/decredcoin/railtie"
|
36
|
+
else
|
37
|
+
check_compatibility
|
38
|
+
register
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Peatio
|
2
|
+
module Decredcoin
|
3
|
+
class Wallet < Peatio::Wallet::Abstract
|
4
|
+
|
5
|
+
DEFAULT_FEATURES = { skip_deposit_collection: false }.freeze
|
6
|
+
|
7
|
+
def initialize(custom_features = {})
|
8
|
+
@features = DEFAULT_FEATURES.merge(custom_features).slice(*SUPPORTED_FEATURES)
|
9
|
+
@settings = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure(settings = {})
|
13
|
+
# Clean client state during configure.
|
14
|
+
@client = nil
|
15
|
+
|
16
|
+
@settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
|
17
|
+
|
18
|
+
@wallet = @settings.fetch(:wallet) do
|
19
|
+
raise Peatio::Wallet::MissingSettingError, :wallet
|
20
|
+
end.slice(:uri, :address)
|
21
|
+
|
22
|
+
@currency = @settings.fetch(:currency) do
|
23
|
+
raise Peatio::Wallet::MissingSettingError, :currency
|
24
|
+
end.slice(:id, :base_factor, :options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_address!(_options = {})
|
28
|
+
{ address: client.json_rpc(:getnewaddress) }
|
29
|
+
rescue Decredcoin::Client::Error => e
|
30
|
+
raise Peatio::Wallet::ClientError, e
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_transaction!(transaction, options = {})
|
34
|
+
txid = client.json_rpc(:sendtoaddress,
|
35
|
+
[
|
36
|
+
transaction.to_address,
|
37
|
+
transaction.amount,
|
38
|
+
'',
|
39
|
+
'',
|
40
|
+
options[:subtract_fee].to_s == 'true' # subtract fee from transaction amount.
|
41
|
+
])
|
42
|
+
transaction.hash = txid
|
43
|
+
transaction
|
44
|
+
rescue Decredcoin::Client::Error => e
|
45
|
+
raise Peatio::Wallet::ClientError, e
|
46
|
+
end
|
47
|
+
|
48
|
+
def load_balance!
|
49
|
+
client.json_rpc(:getbalance).to_d
|
50
|
+
|
51
|
+
rescue Decredcoin::Client::Error => e
|
52
|
+
raise Peatio::Wallet::ClientError, e
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def client
|
58
|
+
uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
|
59
|
+
@client ||= Client.new(uri)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peatio-decredcoin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anuj Dhiman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -199,7 +199,26 @@ email:
|
|
199
199
|
executables: []
|
200
200
|
extensions: []
|
201
201
|
extra_rdoc_files: []
|
202
|
-
files:
|
202
|
+
files:
|
203
|
+
- ".idea/.gitignore"
|
204
|
+
- ".idea/decred-coin.iml"
|
205
|
+
- ".idea/encodings.xml"
|
206
|
+
- ".idea/inspectionProfiles/Project_Default.xml"
|
207
|
+
- ".idea/misc.xml"
|
208
|
+
- ".idea/modules.xml"
|
209
|
+
- ".idea/vcs.xml"
|
210
|
+
- Gemfile
|
211
|
+
- Gemfile.lock
|
212
|
+
- bin/console
|
213
|
+
- bin/setup
|
214
|
+
- decredcoin.gemspec
|
215
|
+
- lib/peatio/decredcoin.rb
|
216
|
+
- lib/peatio/decredcoin/blockchain.rb
|
217
|
+
- lib/peatio/decredcoin/client.rb
|
218
|
+
- lib/peatio/decredcoin/hooks.rb
|
219
|
+
- lib/peatio/decredcoin/railtie.rb
|
220
|
+
- lib/peatio/decredcoin/version.rb
|
221
|
+
- lib/peatio/decredcoin/wallet.rb
|
203
222
|
homepage: https://openware.com/
|
204
223
|
licenses:
|
205
224
|
- MIT
|