peatio-thought 2.6.3 → 2.6.5

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: 29d09e5977b9013ff270981b1546acfff59b7391d4a0c6bbfd5aa518fdbe66f5
4
- data.tar.gz: db4378b445083e2ba33ff4a7d232708b9327259059789988d37c8bfa2eaa2a2a
3
+ metadata.gz: c2ac431dc42834213be104d8228405d166d6fbaed44de43a7c85d12e62e8cda7
4
+ data.tar.gz: d4dd5773e827047facbe616dcf4bf4002a2b5952301774a28dcc388590f27ec4
5
5
  SHA512:
6
- metadata.gz: 561df470215fc6188a394b44be79e1a2d1c00123ba2f41513d089f27a946e8037c0b850af521bddf573f896f03e2312eb0efc987f426f1798fecfc7cc079642c
7
- data.tar.gz: 78d72b04b95607f25b29a1e97e2fe39e0afd4feae4520f60d1cbf56de83f70d4d121bec2dfe5d7bab1301f064b403127cb3af236e0b8c37c9ce536cf920cc70c
6
+ metadata.gz: c24e9ee608e84c587d631f013ac747a752dc7814df856ff2b5f0838f9ca7878284f20b5113208beb3ff9daa063245409c4ccb209521dbcf3d5e960819c510318
7
+ data.tar.gz: 4d2f142b8cc002ca013c17194095ad80c1108e14e797edf76de3e46bad3de64bf9ef47a9acefabba558c0290d78ef93d290cdb8678ae80a740420b31f30a28ca
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- peatio-thought (2.6.3)
4
+ peatio-thought (2.6.5)
5
5
  activesupport (~> 5.2.3)
6
6
  better-faraday (~> 1.0.5)
7
7
  faraday (~> 0.17)
@@ -26,12 +26,11 @@ module Peatio
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)
32
- rescue Client::Error => e
33
- raise Peatio::Blockchain::ClientError, e
34
- end
35
34
 
36
35
  def latest_block_number
37
36
  client.json_rpc(:getblockcount)
@@ -44,32 +43,32 @@ module Peatio
44
43
  .flatten(1)
45
44
  .find {|addr| addr[0] == address }
46
45
 
47
- raise Peatio::Blockchain::UnavailableAddressBalanceError, address if address_with_balance.blank?
48
-
49
- address_with_balance[1].to_d
50
- rescue Client::Error => e
51
- raise Peatio::Blockchain::ClientError, e
46
+ if address_with_balance.blank?
47
+ raise Peatio::Blockchain::UnavailableAddressBalanceError, address
52
48
  end
53
49
 
54
- private
50
+ address_with_balance[1].to_d
51
+ rescue Client::Error => e
52
+ raise Peatio::Blockchain::ClientError, e
53
+ end
54
+
55
+ private
55
56
 
56
57
  def filter_vout(tx_hash)
57
58
  tx_hash.fetch("vout").select do |entry|
58
59
  entry.fetch("value").to_d.positive? && entry["scriptPubKey"].has_key?("addresses")
59
60
  end
60
- end
61
-
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"}
68
-
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
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
73
72
  end
74
73
  end
75
74
 
@@ -77,9 +76,10 @@ module Peatio
77
76
  @client ||= Client.new(settings_fetch(:server))
78
77
  end
79
78
 
80
- def settings_fetch(key)
81
- @settings.fetch(key) { raise Peatio::Blockchain::MissingSettingError, key.to_s }
82
- end
79
+ def settings_fetch(key)
80
+ @settings.fetch(key) { raise Peatio::Blockchain::MissingSettingError, key.to_s }
83
81
  end
84
82
  end
83
+ end
85
84
  end
85
+
@@ -8,57 +8,49 @@ module Peatio
8
8
  module Thought
9
9
  class Client
10
10
  Error = Class.new(StandardError)
11
- ConnectionError = Class.new(Error)
11
+
12
+ class ConnectionError < Error; end
12
13
 
13
14
  class ResponseError < Error
14
15
  def initialize(code, msg)
15
- @code = code
16
- @msg = msg
17
- end
18
-
19
- def message
20
- "#{@msg} (#{@code})"
21
- end
16
+ super "#{msg} (#{code})"
22
17
  end
18
+ end
23
19
 
24
20
  extend Memoist
25
21
 
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
39
-
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
+ @idle_timeout = idle_timeout
25
+ end
44
26
 
45
- private
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
46
42
 
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
43
+ private
51
44
 
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
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)
60
51
  end
61
52
  end
62
53
  end
63
54
  end
64
55
  end
56
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Peatio
4
4
  module Thought
5
- VERSION = "2.6.3"
5
+ VERSION = "2.6.5"
6
6
  end
7
7
  end
@@ -54,10 +54,10 @@ 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)
60
- end
57
+ def client
58
+ uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
59
+ @client ||= Client.new(uri, idle_timeout: 1)
61
60
  end
62
61
  end
63
62
  end
63
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peatio-thought
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.3
4
+ version: 2.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew@Thought
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-16 00:00:00.000000000 Z
11
+ date: 2020-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -270,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
270
  - !ruby/object:Gem::Version
271
271
  version: '0'
272
272
  requirements: []
273
- rubygems_version: 3.0.3
273
+ rubygems_version: 3.0.6
274
274
  signing_key:
275
275
  specification_version: 4
276
276
  summary: Peatio Thought Blockchain Plugin