peatio-goldcoin 2.6.1 → 2.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a44b68aa25e27515c869b56433eba2a57eeb916871a9ce24c333efe45ab64a27
4
- data.tar.gz: 9defd08215cb9fb5b3012c1a79694da41842176071e07980d47b7e59a29d979d
3
+ metadata.gz: 41051340cc25563221456f9ce0f24177b1618d99588555d6efd453cceff5730d
4
+ data.tar.gz: 1c4ee8560e044564be986f552ad040d086fa17269d3525fccbbed62e6a8a4829
5
5
  SHA512:
6
- metadata.gz: 267070b8a93fbbffcd634829671d5d78fbb04d873d9d56f9c2c12d00a4ce17af156fe58455df22c3965213d4d0236d04eb033a513499f73ee2e674f105586753
7
- data.tar.gz: 0d09f1add62bcef8cccfa4716eca2f95a1e098ac546f2d5940cec74a544cbe928f9fb4bde00a1f30e544161ef1b2d53ef2a48a2bcf5737e802de46934409551e
6
+ metadata.gz: c0c9d80b9cf1e21cfc6d47e587f5ae1b06651af93e3c63e369e931011c37240d6d474651d2166380eeefb77e234de6fb87782bf07afce6d6e69780c92af57fed
7
+ data.tar.gz: 5a5897f96ebfe092ea59285867553e3ebd44e1ef1a6d10e054d41e7571600dd87a9605e6891e51aa5748ea33d534026ebd436f73dcecd268e609a936e5d657c0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- peatio-goldcoin (2.6.1)
4
+ peatio-goldcoin (2.6.2)
5
5
  activesupport (~> 5.2.3)
6
6
  better-faraday (~> 1.0.5)
7
7
  faraday (~> 0.17)
@@ -1,17 +1,17 @@
1
- # frozen_string_literal: true
2
1
 
3
2
  module Peatio
4
3
  module Goldcoin
5
4
  # TODO: Processing of unconfirmed transactions from mempool isn't supported now.
6
5
  class Blockchain < Peatio::Blockchain::Abstract
6
+
7
7
  DEFAULT_FEATURES = {case_sensitive: true, cash_addr_format: false}.freeze
8
8
 
9
- def initialize(custom_features={})
9
+ def initialize(custom_features = {})
10
10
  @features = DEFAULT_FEATURES.merge(custom_features).slice(*SUPPORTED_FEATURES)
11
11
  @settings = {}
12
12
  end
13
13
 
14
- def configure(settings={})
14
+ def configure(settings = {})
15
15
  # Clean client state during configure.
16
16
  @client = nil
17
17
  @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
@@ -20,15 +20,51 @@ module Peatio
20
20
  def fetch_block!(block_number)
21
21
  block_hash = client.json_rpc(:getblockhash, [block_number])
22
22
 
23
- block_txs = client.json_rpc(:getblock, [block_hash])
24
- .fetch("tx").each_with_object([]) do |tx, txs_array|
23
+ client.json_rpc(:getblock, [block_hash])
24
+ .fetch('tx').each_with_object([]) do |tx, txs_array|
25
25
  txs = build_transaction(tx).map do |ntx|
26
26
  Peatio::Transaction.new(ntx.merge(block_number: block_number))
27
27
  end
28
28
  txs_array.append(*txs)
29
- end
29
+ end.yield_self { |txs_array| Peatio::Block.new(block_number, txs_array) }
30
+ rescue Client::Error => e
31
+ raise Peatio::Blockchain::ClientError, e
32
+ end
30
33
 
31
- Peatio::Block.new(block_number, block_txs)
34
+ def latest_block_number
35
+ client.json_rpc(:getblockcount)
36
+ rescue Client::Error => e
37
+ raise Peatio::Blockchain::ClientError, e
38
+ end
39
+
40
+ module Peatio
41
+ module Goldcoin
42
+ # TODO: Processing of unconfirmed transactions from mempool isn't supported now.
43
+ class Blockchain < Peatio::Blockchain::Abstract
44
+
45
+ DEFAULT_FEATURES = {case_sensitive: true, cash_addr_format: false}.freeze
46
+
47
+ def initialize(custom_features = {})
48
+ @features = DEFAULT_FEATURES.merge(custom_features).slice(*SUPPORTED_FEATURES)
49
+ @settings = {}
50
+ end
51
+
52
+ def configure(settings = {})
53
+ # Clean client state during configure.
54
+ @client = nil
55
+ @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
56
+ end
57
+
58
+ def fetch_block!(block_number)
59
+ block_hash = client.json_rpc(:getblockhash, [block_number])
60
+
61
+ client.json_rpc(:getblock, [block_hash])
62
+ .fetch('tx').each_with_object([]) do |tx, txs_array|
63
+ txs = build_transaction(tx).map do |ntx|
64
+ Peatio::Transaction.new(ntx.merge(block_number: block_number))
65
+ end
66
+ txs_array.append(*txs)
67
+ end.yield_self { |txs_array| Peatio::Block.new(block_number, txs_array) }
32
68
  rescue Client::Error => e
33
69
  raise Peatio::Blockchain::ClientError, e
34
70
  end
@@ -41,10 +77,12 @@ module Peatio
41
77
 
42
78
  def load_balance_of_address!(address, _currency_id)
43
79
  address_with_balance = client.json_rpc(:listaddressgroupings)
44
- .flatten(1)
45
- .find {|addr| addr[0] == address }
80
+ .flatten(1)
81
+ .find { |addr| addr[0] == address }
46
82
 
47
- raise Peatio::Blockchain::UnavailableAddressBalanceError, address if address_with_balance.blank?
83
+ if address_with_balance.blank?
84
+ raise Peatio::Blockchain::UnavailableAddressBalanceError, address
85
+ end
48
86
 
49
87
  address_with_balance[1].to_d
50
88
  rescue Client::Error => e
@@ -53,18 +91,18 @@ module Peatio
53
91
 
54
92
  private
55
93
 
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
-
62
94
  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"}
95
+ tx_hash.fetch('vout')
96
+ .select do |entry|
97
+ entry.fetch('value').to_d > 0 &&
98
+ entry['scriptPubKey'].has_key?('addresses')
99
+ end
100
+ .each_with_object([]) do |entry, formatted_txs|
101
+ no_currency_tx =
102
+ { hash: tx_hash['txid'], txout: entry['n'],
103
+ to_address: entry['scriptPubKey']['addresses'][0],
104
+ amount: entry.fetch('value').to_d,
105
+ status: 'success' }
68
106
 
69
107
  # Build transaction for each currency belonging to blockchain.
70
108
  settings_fetch(:currencies).pluck(:id).each do |currency_id|
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "memoist"
4
- require "faraday"
5
- require "better-faraday"
3
+ require 'memoist'
4
+ require 'faraday'
5
+ require 'better-faraday'
6
6
 
7
7
  module Peatio
8
8
  module Goldcoin
@@ -27,23 +27,38 @@ module Peatio
27
27
  @json_rpc_endpoint = URI.parse(endpoint)
28
28
  end
29
29
 
30
- def json_rpc(method, params=[])
31
- response = post(method, params)
32
-
30
+ def json_rpc(method, params = [])
31
+ response = connection.post \
32
+ '/',
33
+ { jsonrpc: '1.0', method: method, params: params }.to_json,
34
+ { 'Accept' => 'application/json',
35
+ 'Content-Type' => 'application/json' }
33
36
  response.assert_2xx!
34
37
  response = JSON.parse(response.body)
35
-
36
- response["error"].tap do |e|
37
- raise ResponseError.new(e["code"], e["message"]) if e
38
+ response['error'].tap do |e|
39
+ raise ResponseError.new(e['code'], e['message']) if e
38
40
  end
39
-
40
- response.fetch("result")
41
+ response.fetch('result')
41
42
  rescue Faraday::Error => e
42
43
  raise ConnectionError, e
43
44
  end
44
45
 
45
46
  private
46
47
 
48
+ def connection
49
+ @connection ||= Faraday.new(@json_rpc_endpoint) do |f|
50
+ f.adapter :net_http_persistent, pool_size: 5
51
+ end.tap do |connection|
52
+ unless @json_rpc_endpoint.user.blank?
53
+ connection.basic_auth(@json_rpc_endpoint.user,
54
+ @json_rpc_endpoint.password)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+
47
62
  def post(method, params)
48
63
  connection.post("/", {jsonrpc: "1.0", method: method, params: params}.to_json,
49
64
  "Accept" => "application/json", "Content-Type" => "application/json")
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Peatio
4
4
  module Goldcoin
5
- VERSION = "2.6.1".freeze
5
+ VERSION = "2.6.2".freeze
6
6
  end
7
7
  end
@@ -1,8 +1,7 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Peatio
4
2
  module Goldcoin
5
3
  class Wallet < Peatio::Wallet::Abstract
4
+
6
5
  DEFAULT_FEATURES = { skip_deposit_collection: false }.freeze
7
6
 
8
7
  def initialize(custom_features = {})
@@ -10,35 +9,35 @@ module Peatio
10
9
  @settings = {}
11
10
  end
12
11
 
13
- def configure(settings={})
12
+ def configure(settings = {})
14
13
  # Clean client state during configure.
15
14
  @client = nil
16
15
 
17
16
  @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
18
17
 
19
- @wallet = @settings.fetch(:wallet) {
18
+ @wallet = @settings.fetch(:wallet) do
20
19
  raise Peatio::Wallet::MissingSettingError, :wallet
21
- }.slice(:uri, :address)
20
+ end.slice(:uri, :address)
22
21
 
23
- @currency = @settings.fetch(:currency) {
22
+ @currency = @settings.fetch(:currency) do
24
23
  raise Peatio::Wallet::MissingSettingError, :currency
25
- }.slice(:id, :base_factor, :options)
24
+ end.slice(:id, :base_factor, :options)
26
25
  end
27
26
 
28
- def create_address!(_options={})
29
- {address: client.json_rpc(:getnewaddress)}
27
+ def create_address!(_options = {})
28
+ { address: client.json_rpc(:getnewaddress) }
30
29
  rescue Goldcoin::Client::Error => e
31
30
  raise Peatio::Wallet::ClientError, e
32
31
  end
33
32
 
34
- def create_transaction!(transaction, options={})
33
+ def create_transaction!(transaction, options = {})
35
34
  txid = client.json_rpc(:sendtoaddress,
36
35
  [
37
36
  transaction.to_address,
38
37
  transaction.amount,
39
- "",
40
- "",
41
- options[:subtract_fee].to_s == "true" # subtract fee from transaction amount.
38
+ '',
39
+ '',
40
+ options[:subtract_fee].to_s == 'true' # subtract fee from transaction amount.
42
41
  ])
43
42
  transaction.hash = txid
44
43
  transaction
@@ -46,6 +45,25 @@ module Peatio
46
45
  raise Peatio::Wallet::ClientError, e
47
46
  end
48
47
 
48
+ def load_balance!
49
+ client.json_rpc(:getbalance).to_d
50
+
51
+ rescue Goldcoin::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
64
+
65
+ end
66
+
49
67
  def load_balance!
50
68
  client.json_rpc(:getbalance).to_d
51
69
  rescue Goldcoin::Client::Error => e
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peatio-goldcoin
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.1
4
+ version: 2.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - D.H.