peatio-thought 2.6.5 → 2.6.7

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: c2ac431dc42834213be104d8228405d166d6fbaed44de43a7c85d12e62e8cda7
4
- data.tar.gz: d4dd5773e827047facbe616dcf4bf4002a2b5952301774a28dcc388590f27ec4
3
+ metadata.gz: 497ca16ccc4eda7ac0fb035c68ef543a378364f6b142f2f85dccb57803e1ea88
4
+ data.tar.gz: a1d194a397cee8e577e9665f17b4a8dae3238e0cecbb39925a3d1857524a4e55
5
5
  SHA512:
6
- metadata.gz: c24e9ee608e84c587d631f013ac747a752dc7814df856ff2b5f0838f9ca7878284f20b5113208beb3ff9daa063245409c4ccb209521dbcf3d5e960819c510318
7
- data.tar.gz: 4d2f142b8cc002ca013c17194095ad80c1108e14e797edf76de3e46bad3de64bf9ef47a9acefabba558c0290d78ef93d290cdb8678ae80a740420b31f30a28ca
6
+ metadata.gz: 4b3ff921351521a5dcbf80e4892d6d2a66879be411a7d940f0ff60443f7a0f8cff7bc17e2f4f4d3c33996d1f85c78d412ea9a4c143259a55f7070be2c85a7603
7
+ data.tar.gz: 91dc0dd40f9e4d24be962e0cff36a6a716d6b0005fdc1edb0b2df8626faa38fce4094fce9874876c56ccef998a18a37d3220346cb33c7aed2724f3989241e965
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- peatio-thought (2.6.5)
4
+ peatio-thought (2.6.7)
5
5
  activesupport (~> 5.2.3)
6
6
  better-faraday (~> 1.0.5)
7
7
  faraday (~> 0.17)
@@ -1,4 +1,3 @@
1
- # frozen_string_literal: true
2
1
 
3
2
  module Peatio
4
3
  module Thought
@@ -20,7 +19,7 @@ module Peatio
20
19
  def fetch_block!(block_number)
21
20
  block_hash = client.json_rpc(:getblockhash, [block_number])
22
21
 
23
- block_txs = client.json_rpc(:getblock, [block_hash, 2])
22
+ client.json_rpc(:getblock, [block_hash, 2])
24
23
  .fetch("tx").each_with_object([]) do |tx, txs_array|
25
24
  txs = build_transaction(tx).map do |ntx|
26
25
  Peatio::Transaction.new(ntx.merge(block_number: block_number))
@@ -58,17 +57,24 @@ private
58
57
  tx_hash.fetch("vout").select do |entry|
59
58
  entry.fetch("value").to_d.positive? && entry["scriptPubKey"].has_key?("addresses")
60
59
  end
61
- .each_with_object([]) do |entry, formatted_txs|
60
+
61
+ def build_transaction(tx_hash)
62
+ tx_hash.fetch('vout')
63
+ .select do |entry|
64
+ entry.fetch('value').to_d > 0 &&
65
+ entry['scriptPubKey'].has_key?('addresses')
66
+ end
67
+ .each_with_object([]) do |entry, formatted_txs|
62
68
  no_currency_tx =
63
69
  { hash: tx_hash['txid'], txout: entry['n'],
64
70
  to_address: entry['scriptPubKey']['addresses'][0],
65
71
  amount: entry.fetch('value').to_d,
66
72
  status: 'success' }
67
73
 
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
74
+ # Build transaction for each currency belonging to blockchain.
75
+ settings_fetch(:currencies).pluck(:id).each do |currency_id|
76
+ formatted_txs << no_currency_tx.merge(currency_id: currency_id)
77
+ end
72
78
  end
73
79
  end
74
80
 
@@ -82,4 +88,4 @@ private
82
88
  end
83
89
  end
84
90
  end
85
-
91
+ end
@@ -8,49 +8,54 @@ module Peatio
8
8
  module Thought
9
9
  class Client
10
10
  Error = Class.new(StandardError)
11
-
12
- class ConnectionError < Error; end
11
+ ConnectionError = Class.new(Error)
13
12
 
14
13
  class ResponseError < Error
15
14
  def initialize(code, msg)
16
- super "#{msg} (#{code})"
15
+ @code = code
16
+ @msg = msg
17
+ end
18
+
19
+ def message
20
+ "#{@msg} (#{@code})"
21
+ end
17
22
  end
18
- end
23
+
19
24
 
20
25
  extend Memoist
21
26
 
22
- def initialize(endpoint, idle_timeout: 5)
23
- @json_rpc_endpoint = URI.parse(endpoint)
24
- @idle_timeout = idle_timeout
25
- end
27
+ def initialize(endpoint)
28
+ @json_rpc_endpoint = URI.parse(endpoint)
29
+ end
26
30
 
27
- def json_rpc(method, params = [])
28
- response = connection.post \
29
- '/',
30
- {jsonrpc: '1.0', method: method, params: params}.to_json,
31
- {'Accept' => 'application/json',
32
- 'Content-Type' => 'application/json'}
33
- response.assert_success!
34
- response = JSON.parse(response.body)
35
- response['error'].tap { |error| raise ResponseError.new(error['code'], error['message']) if error }
36
- response.fetch('result')
37
- rescue Faraday::Error => e
38
- raise ConnectionError, e
39
- rescue StandardError => e
40
- raise Error, e
41
- end
31
+ def json_rpc(method, params = [])
32
+ response = connection.post \
33
+ '/',
34
+ { jsonrpc: '1.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
42
46
 
43
47
  private
44
48
 
45
- def connection
46
- @connection ||= Faraday.new(@json_rpc_endpoint) do |f|
47
- f.adapter :net_http_persistent, pool_size: 5, idle_timeout: @idle_timeout
48
- end.tap do |connection|
49
- unless @json_rpc_endpoint.user.blank?
50
- connection.basic_auth(@json_rpc_endpoint.user, @json_rpc_endpoint.password)
49
+ def connection
50
+ @connection ||= Faraday.new(@json_rpc_endpoint) do |f|
51
+ f.adapter :net_http_persistent, pool_size: 5
52
+ end.tap do |connection|
53
+ unless @json_rpc_endpoint.user.blank?
54
+ connection.basic_auth(@json_rpc_endpoint.user,
55
+ @json_rpc_endpoint.password)
56
+ end
51
57
  end
52
58
  end
53
59
  end
54
60
  end
55
61
  end
56
- end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Peatio
4
4
  module Thought
5
- VERSION = "2.6.5"
5
+ VERSION = "2.6.7"
6
6
  end
7
7
  end
@@ -16,17 +16,17 @@ module Peatio
16
16
 
17
17
  @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
18
18
 
19
- @wallet = @settings.fetch(:wallet) {
19
+ @wallet = @settings.fetch(:wallet) do
20
20
  raise Peatio::Wallet::MissingSettingError, :wallet
21
- }.slice(:uri, :address)
21
+ end.slice(:uri, :address)
22
22
 
23
- @currency = @settings.fetch(:currency) {
23
+ @currency = @settings.fetch(:currency) do
24
24
  raise Peatio::Wallet::MissingSettingError, :currency
25
- }.slice(:id, :base_factor, :options)
25
+ end.slice(:id, :base_factor, :options)
26
26
  end
27
27
 
28
- def create_address!(_options={})
29
- {address: client.json_rpc(:getnewaddress)}
28
+ def create_address!(_options = {})
29
+ { address: client.json_rpc(:getnewaddress) }
30
30
  rescue Thought::Client::Error => e
31
31
  raise Peatio::Wallet::ClientError, e
32
32
  end
@@ -36,9 +36,9 @@ module Peatio
36
36
  [
37
37
  transaction.to_address,
38
38
  transaction.amount,
39
- "",
40
- "",
41
- options[:subtract_fee].to_s == "true" # subtract fee from transaction amount.
39
+ '',
40
+ '',
41
+ options[:subtract_fee].to_s == 'true' # subtract fee from transaction amount.
42
42
  ])
43
43
  transaction.hash = txid
44
44
  transaction
@@ -54,10 +54,11 @@ module Peatio
54
54
 
55
55
  private
56
56
 
57
- def client
58
- uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
59
- @client ||= Client.new(uri, idle_timeout: 1)
57
+ def client
58
+ uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
59
+ @client ||= Client.new(uri)
60
+ end
60
61
  end
61
62
  end
62
63
  end
63
- end
64
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peatio-thought
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.5
4
+ version: 2.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew@Thought