peatio-goldcash 2.6.7 → 2.6.8
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/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/peatio/goldcash/blockchain.rb +72 -61
- data/lib/peatio/goldcash/client.rb +37 -45
- data/lib/peatio/goldcash/hooks.rb +3 -3
- data/lib/peatio/goldcash/version.rb +1 -1
- data/lib/peatio/goldcash/wallet.rb +55 -57
- data/peatio-goldcash.gemspec +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b49233782ebd62a00898f80b007c2f99ef10a04d2ee39c4a9a5a34efde9574b
|
4
|
+
data.tar.gz: dda5b4346240f310818627794a9d3b2b3211a029405aa352eb122c977cc86e12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30d0f806e2303a6ea6ed90682c218e75178d54ffdeab20bbf8b7dfd16a2d35af710135524df29c95b2e0e0b3355e8e85ca0a2bc51a81af669f0d466629badbc9
|
7
|
+
data.tar.gz: 86eac432bfac27e3345408031321c9f099d266dac65ba0b8f8b8fa55127ccbc25dac633d73c561e7258e5b00d10bfd0fd4be6193858a931e1b0787f6394ad891
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Peatio::Goldcash
|
2
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/
|
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
4
|
|
5
5
|
TODO: Delete this and the text above, and describe your gem
|
6
6
|
|
@@ -1,85 +1,96 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Peatio
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
DEFAULT_FEATURES = {case_sensitive: true, cash_addr_format: false}.freeze
|
8
|
-
|
9
|
-
def initialize(custom_features={})
|
10
|
-
@features = DEFAULT_FEATURES.merge(custom_features).slice(*SUPPORTED_FEATURES)
|
11
|
-
@settings = {}
|
12
|
-
end
|
4
|
+
module Goldcash
|
5
|
+
# TODO: Processing of unconfirmed transactions from mempool isn't supported now.
|
6
|
+
class Blockchain < Peatio::Blockchain::Abstract
|
13
7
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
def fetch_block!(block_number)
|
22
|
+
block_hash = client.json_rpc(:getblockhash, [block_number])
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
client.json_rpc(:getblock, [block_hash])
|
25
|
+
.fetch('tx').each_with_object([]) do |tx, txs_array|
|
25
26
|
txs = build_transaction(tx).map do |ntx|
|
26
27
|
Peatio::Transaction.new(ntx.merge(block_number: block_number))
|
27
28
|
end
|
28
29
|
txs_array.append(*txs)
|
29
|
-
end
|
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
|
30
34
|
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
35
40
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
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?
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
46
51
|
|
47
|
-
|
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 }
|
48
56
|
|
49
|
-
|
50
|
-
|
51
|
-
raise Peatio::Blockchain::ClientError, e
|
57
|
+
if address_with_balance.blank?
|
58
|
+
raise Peatio::Blockchain::UnavailableAddressBalanceError, address
|
52
59
|
end
|
53
60
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
entry.fetch("value").to_d.positive? && entry["scriptPubKey"].has_key?("addresses")
|
59
|
-
end
|
60
|
-
end
|
61
|
+
address_with_balance[1].to_d
|
62
|
+
rescue Goldcash::Client::Error => e
|
63
|
+
raise Peatio::Blockchain::ClientError, e
|
64
|
+
end
|
61
65
|
|
62
|
-
|
63
|
-
filter_vout(tx_hash).each_with_object([]) do |entry, formatted_txs|
|
64
|
-
no_currency_tx = {hash: tx_hash["txid"], txout: entry["n"],
|
65
|
-
to_address: entry["scriptPubKey"]["addresses"][0],
|
66
|
-
amount: entry.fetch("value").to_d,
|
67
|
-
status: "success"}
|
66
|
+
private
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
73
|
end
|
74
|
-
|
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
|
75
87
|
|
76
|
-
|
77
|
-
|
78
|
-
|
88
|
+
def client
|
89
|
+
@client ||= Goldcash::Client.new(settings_fetch(:server))
|
90
|
+
end
|
79
91
|
|
80
|
-
|
81
|
-
|
82
|
-
end
|
92
|
+
def settings_fetch(key)
|
93
|
+
@settings.fetch(key) { raise Peatio::Blockchain::MissingSettingError, key.to_s }
|
83
94
|
end
|
84
95
|
end
|
85
|
-
end
|
96
|
+
end
|
@@ -5,60 +5,52 @@ require "faraday"
|
|
5
5
|
require "better-faraday"
|
6
6
|
|
7
7
|
module Peatio
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
ConnectionError = Class.new(Error)
|
8
|
+
module Goldcash
|
9
|
+
class Client
|
10
|
+
Error = Class.new(StandardError)
|
12
11
|
|
13
|
-
|
14
|
-
def initialize(code, msg)
|
15
|
-
@code = code
|
16
|
-
@msg = msg
|
17
|
-
end
|
12
|
+
class ConnectionError < Error; end
|
18
13
|
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
class ResponseError < Error
|
15
|
+
def initialize(code, msg)
|
16
|
+
super "#{msg} (#{code})"
|
22
17
|
end
|
18
|
+
end
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
def initialize(endpoint)
|
27
|
-
@json_rpc_endpoint = URI.parse(endpoint)
|
28
|
-
end
|
29
|
-
|
30
|
-
def json_rpc(method, params=[])
|
31
|
-
response = post(method, params)
|
32
|
-
|
33
|
-
response.assert_2xx!
|
34
|
-
response = JSON.parse(response.body)
|
35
|
-
|
36
|
-
response["error"].tap do |e|
|
37
|
-
raise ResponseError.new(e["code"], e["message"]) if e
|
38
|
-
end
|
20
|
+
extend Memoist
|
39
21
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
44
27
|
|
45
|
-
|
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
|
46
43
|
|
47
|
-
|
48
|
-
connection.post("/", {jsonrpc: "1.0", method: method, params: params}.to_json,
|
49
|
-
"Accept" => "application/json", "Content-Type" => "application/json")
|
50
|
-
end
|
44
|
+
private
|
51
45
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
@json_rpc_endpoint.password)
|
59
|
-
end
|
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)
|
60
52
|
end
|
61
53
|
end
|
62
54
|
end
|
63
55
|
end
|
64
|
-
end
|
56
|
+
end
|
@@ -28,13 +28,13 @@ module Peatio
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def register
|
31
|
-
Peatio::Blockchain.registry[:
|
32
|
-
Peatio::Wallet.registry[:
|
31
|
+
Peatio::Blockchain.registry[:goldcash] = Goldcash::Blockchain
|
32
|
+
Peatio::Wallet.registry[:goldcashd] = Goldcash::Wallet
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
if defined?(Rails::Railtie)
|
37
|
-
require "peatio/
|
37
|
+
require "peatio/goldcash/railtie"
|
38
38
|
else
|
39
39
|
check_compatibility
|
40
40
|
register
|
@@ -1,63 +1,61 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Peatio
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
@client ||= Client.new(uri)
|
60
|
-
end
|
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)
|
61
59
|
end
|
62
60
|
end
|
63
61
|
end
|
data/peatio-goldcash.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
|
13
13
|
spec.summary = "Peatio Blockchain Plugin"
|
14
14
|
spec.description = "Peatio Blockchain Plugin for Rubykube"
|
15
|
-
spec.homepage = "https://
|
15
|
+
spec.homepage = "https://github.com/alcoxbiz/"
|
16
16
|
spec.license = "Proprietary"
|
17
17
|
|
18
18
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.metadata["homepage_uri"] = spec.homepage
|
23
23
|
spec.metadata["source_code_uri"] = "https://github.com/alcoxbiz/peatio-goldcash"
|
24
|
-
spec.metadata["changelog_uri"] = "https://github.com/alcoxbiz/peatio-goldcash/
|
24
|
+
spec.metadata["changelog_uri"] = "https://github.com/alcoxbiz/peatio-goldcash/commits/master"
|
25
25
|
else
|
26
26
|
raise "RubyGems 2.0 or newer is required to protect against " \
|
27
27
|
"public gem pushes."
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peatio-goldcash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.6.
|
4
|
+
version: 2.6.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- D.H.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -246,13 +246,13 @@ files:
|
|
246
246
|
- lib/peatio/goldcash/version.rb
|
247
247
|
- lib/peatio/goldcash/wallet.rb
|
248
248
|
- peatio-goldcash.gemspec
|
249
|
-
homepage: https://
|
249
|
+
homepage: https://github.com/alcoxbiz/
|
250
250
|
licenses:
|
251
251
|
- Proprietary
|
252
252
|
metadata:
|
253
|
-
homepage_uri: https://
|
253
|
+
homepage_uri: https://github.com/alcoxbiz/
|
254
254
|
source_code_uri: https://github.com/alcoxbiz/peatio-goldcash
|
255
|
-
changelog_uri: https://github.com/alcoxbiz/peatio-goldcash/
|
255
|
+
changelog_uri: https://github.com/alcoxbiz/peatio-goldcash/commits/master
|
256
256
|
post_install_message:
|
257
257
|
rdoc_options: []
|
258
258
|
require_paths:
|