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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9db4bc932d1550620cc776437a5f175a675a66be0fa34a1aaf6740b8676b22a6
4
- data.tar.gz: 42f2bc359bf19000c843381c059e5f5c70b0072ffe426b07f6b03ebd2265ec8b
3
+ metadata.gz: 2b49233782ebd62a00898f80b007c2f99ef10a04d2ee39c4a9a5a34efde9574b
4
+ data.tar.gz: dda5b4346240f310818627794a9d3b2b3211a029405aa352eb122c977cc86e12
5
5
  SHA512:
6
- metadata.gz: 8741622686943516252f10fcd6b11c49835865cc78f182b3fa80645b35fc9a39fbbe1b0b39c867bc7abb2292e0b3b700226a278cd03ff3eda7d66da1fa02a78f
7
- data.tar.gz: eea49aef9ff7c1acd8c02d48365fa7e2ea455b9545d6314b7ededc31fe8a3a7a7fe85e05f3293ea7efe1f6be1ece75ed7cc406a9abbe58b7c0da04158473dc22
6
+ metadata.gz: 30d0f806e2303a6ea6ed90682c218e75178d54ffdeab20bbf8b7dfd16a2d35af710135524df29c95b2e0e0b3355e8e85ca0a2bc51a81af669f0d466629badbc9
7
+ data.tar.gz: 86eac432bfac27e3345408031321c9f099d266dac65ba0b8f8b8fa55127ccbc25dac633d73c561e7258e5b00d10bfd0fd4be6193858a931e1b0787f6394ad891
data/Gemfile CHANGED
@@ -4,5 +4,5 @@ source "https://rubygems.org"
4
4
 
5
5
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6
6
 
7
- # Specify your gem's dependencies in peatio-goldcash.gemspec
7
+ # Specify your gem's dependencies in peatio-gold.gemspec
8
8
  gemspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- peatio-goldcash (2.6.7)
4
+ peatio-goldcash (2.6.8)
5
5
  activesupport (~> 5.2.3)
6
6
  better-faraday (~> 1.0.5)
7
7
  faraday (~> 0.17)
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/goldcash`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- module Goldcash
5
- # TODO: Processing of unconfirmed transactions from mempool isn't supported now.
6
- class Blockchain < Peatio::Blockchain::Abstract
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
- def configure(settings={})
15
- # Clean client state during configure.
16
- @client = nil
17
- @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
18
- end
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
- def fetch_block!(block_number)
21
- block_hash = client.json_rpc(:getblockhash, [block_number])
21
+ def fetch_block!(block_number)
22
+ block_hash = client.json_rpc(:getblockhash, [block_number])
22
23
 
23
- block_txs = client.json_rpc(:getblock, [block_hash])
24
- .fetch("tx").each_with_object([]) do |tx, txs_array|
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
- Peatio::Block.new(block_number, block_txs)
32
- rescue Client::Error => e
33
- raise Peatio::Blockchain::ClientError, e
34
- end
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
- def latest_block_number
37
- client.json_rpc(:getblockcount)
38
- rescue Client::Error => e
39
- raise Peatio::Blockchain::ClientError, e
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
- def load_balance_of_address!(address, _currency_id)
43
- address_with_balance = client.json_rpc(:listaddressgroupings)
44
- .flatten(1)
45
- .find {|addr| addr[0] == address }
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
- raise Peatio::Blockchain::UnavailableAddressBalanceError, address if address_with_balance.blank?
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
- address_with_balance[1].to_d
50
- rescue Client::Error => e
51
- raise Peatio::Blockchain::ClientError, e
57
+ if address_with_balance.blank?
58
+ raise Peatio::Blockchain::UnavailableAddressBalanceError, address
52
59
  end
53
60
 
54
- private
55
-
56
- def filter_vout(tx_hash)
57
- tx_hash.fetch("vout").select do |entry|
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
- def build_transaction(tx_hash)
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
- # Build transaction for each currency belonging to blockchain.
70
- settings_fetch(:currencies).pluck(:id).each do |currency_id|
71
- formatted_txs << no_currency_tx.merge(currency_id: currency_id)
72
- end
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
- 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
75
87
 
76
- def client
77
- @client ||= Client.new(settings_fetch(:server))
78
- end
88
+ def client
89
+ @client ||= Goldcash::Client.new(settings_fetch(:server))
90
+ end
79
91
 
80
- def settings_fetch(key)
81
- @settings.fetch(key) { raise Peatio::Blockchain::MissingSettingError, key.to_s }
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
- module Goldcash
9
- class Client
10
- Error = Class.new(StandardError)
11
- ConnectionError = Class.new(Error)
8
+ module Goldcash
9
+ class Client
10
+ Error = Class.new(StandardError)
12
11
 
13
- class ResponseError < Error
14
- def initialize(code, msg)
15
- @code = code
16
- @msg = msg
17
- end
12
+ class ConnectionError < Error; end
18
13
 
19
- def message
20
- "#{@msg} (#{@code})"
21
- end
14
+ class ResponseError < Error
15
+ def initialize(code, msg)
16
+ super "#{msg} (#{code})"
22
17
  end
18
+ end
23
19
 
24
- extend Memoist
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
- response.fetch("result")
41
- rescue Faraday::Error => e
42
- raise ConnectionError, e
43
- end
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
- private
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
- def post(method, params)
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
- def connection
53
- @connection ||= Faraday.new(@json_rpc_endpoint) do |f|
54
- f.adapter :net_http_persistent, pool_size: 5
55
- end.tap do |connection|
56
- unless @json_rpc_endpoint.user.blank?
57
- connection.basic_auth(@json_rpc_endpoint.user,
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[:goldcashcash] = Goldcash::Blockchain
32
- Peatio::Wallet.registry[:goldcashcashd] = Goldcash::Wallet
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/goldcashcash/railtie"
37
+ require "peatio/goldcash/railtie"
38
38
  else
39
39
  check_compatibility
40
40
  register
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Peatio
4
4
  module Goldcash
5
- VERSION = "2.6.7".freeze
5
+ VERSION = "2.6.8".freeze
6
6
  end
7
7
  end
@@ -1,63 +1,61 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Peatio
4
- module Goldcash
5
- class Wallet < Peatio::Wallet::Abstract
6
- DEFAULT_FEATURES = { skip_deposit_collection: 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
-
17
- @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
18
-
19
- @wallet = @settings.fetch(:wallet) {
20
- raise Peatio::Wallet::MissingSettingError, :wallet
21
- }.slice(:uri, :address)
22
-
23
- @currency = @settings.fetch(:currency) {
24
- raise Peatio::Wallet::MissingSettingError, :currency
25
- }.slice(:id, :base_factor, :options)
26
- end
27
-
28
- def create_address!(_options={})
29
- {address: client.json_rpc(:getnewaddress)}
30
- rescue Goldcash::Client::Error => e
31
- raise Peatio::Wallet::ClientError, e
32
- end
33
-
34
- def create_transaction!(transaction, options={})
35
- txid = client.json_rpc(:sendtoaddress,
36
- [
37
- transaction.to_address,
38
- transaction.amount,
39
- "",
40
- "",
41
- options[:subtract_fee].to_s == "true" # subtract fee from transaction amount.
42
- ])
43
- transaction.hash = txid
44
- transaction
45
- rescue Goldcash::Client::Error => e
46
- raise Peatio::Wallet::ClientError, e
47
- end
48
-
49
- def load_balance!
50
- client.json_rpc(:getbalance).to_d
51
- rescue Goldcash::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
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
@@ -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://www.alcox.biz"
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/blob/master/CHANGELOG.md"
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.7
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-03 00:00:00.000000000 Z
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://www.alcox.biz
249
+ homepage: https://github.com/alcoxbiz/
250
250
  licenses:
251
251
  - Proprietary
252
252
  metadata:
253
- homepage_uri: https://www.alcox.biz
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/blob/master/CHANGELOG.md
255
+ changelog_uri: https://github.com/alcoxbiz/peatio-goldcash/commits/master
256
256
  post_install_message:
257
257
  rdoc_options: []
258
258
  require_paths: