peatio-thought 2.6.7 → 2.6.7.1

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: 497ca16ccc4eda7ac0fb035c68ef543a378364f6b142f2f85dccb57803e1ea88
4
- data.tar.gz: a1d194a397cee8e577e9665f17b4a8dae3238e0cecbb39925a3d1857524a4e55
3
+ metadata.gz: 3863bcba08ebff661b9bcd89a85b17dc3af9ed90ea3dafe80ae8fa57edf97e4f
4
+ data.tar.gz: 0a7f7d64cdd64c8aae0b9dc296685305335b12f763f04af5c6fa248cdc3c7ec7
5
5
  SHA512:
6
- metadata.gz: 4b3ff921351521a5dcbf80e4892d6d2a66879be411a7d940f0ff60443f7a0f8cff7bc17e2f4f4d3c33996d1f85c78d412ea9a4c143259a55f7070be2c85a7603
7
- data.tar.gz: 91dc0dd40f9e4d24be962e0cff36a6a716d6b0005fdc1edb0b2df8626faa38fce4094fce9874876c56ccef998a18a37d3220346cb33c7aed2724f3989241e965
6
+ metadata.gz: b1a1f9a61d6ef4e994a9ee80d571382e8988f3777f527d7132e2ba4152a1a4a47ab80d935cf120b5e107e99d1ea9ce938c9b6c3e3fc6e103c6fb243f0ca2f9d5
7
+ data.tar.gz: 589c25150d4d1673855f196570a6f3cb761fa4aade4d30bcb57a7873e91f1e1ec975edc34349d563b34abf64930501616229f9a1735f215a70fa99f2ced5d5cb
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- peatio-thought (2.6.7)
4
+ peatio-thought (2.6.7.1)
5
5
  activesupport (~> 5.2.3)
6
6
  better-faraday (~> 1.0.5)
7
7
  faraday (~> 0.17)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Peatio
3
4
  module Thought
@@ -19,13 +20,15 @@ module Peatio
19
20
  def fetch_block!(block_number)
20
21
  block_hash = client.json_rpc(:getblockhash, [block_number])
21
22
 
22
- client.json_rpc(:getblock, [block_hash, 2])
23
+ block_txs = client.json_rpc(:getblock, [block_hash, 2])
23
24
  .fetch("tx").each_with_object([]) do |tx, txs_array|
24
25
  txs = build_transaction(tx).map do |ntx|
25
26
  Peatio::Transaction.new(ntx.merge(block_number: block_number))
26
27
  end
27
28
  txs_array.append(*txs)
28
- end.yield_self { |txs_array| Peatio::Block.new(block_number, txs_array) }
29
+ end
30
+
31
+ Peatio::Block.new(block_number, txs_array)
29
32
  rescue Client::Error => e
30
33
  raise Peatio::Blockchain::ClientError, e
31
34
  end
@@ -42,50 +45,42 @@ module Peatio
42
45
  .flatten(1)
43
46
  .find {|addr| addr[0] == address }
44
47
 
45
- if address_with_balance.blank?
46
- raise Peatio::Blockchain::UnavailableAddressBalanceError, address
47
- end
48
-
49
- address_with_balance[1].to_d
50
- rescue Client::Error => e
51
- raise Peatio::Blockchain::ClientError, e
52
- end
53
-
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
-
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|
68
- no_currency_tx =
69
- { hash: tx_hash['txid'], txout: entry['n'],
70
- to_address: entry['scriptPubKey']['addresses'][0],
71
- amount: entry.fetch('value').to_d,
72
- status: 'success' }
73
-
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
78
- end
79
- end
80
-
81
- def client
82
- @client ||= Client.new(settings_fetch(:server))
83
- end
84
-
85
- def settings_fetch(key)
86
- @settings.fetch(key) { raise Peatio::Blockchain::MissingSettingError, key.to_s }
87
- end
88
- end
89
- end
90
- end
91
- end
48
+ raise Peatio::Blockchain::UnavailableAddressBalanceError, address if address_with_balance.blank?
49
+
50
+ address_with_balance[1].to_d
51
+ rescue Client::Error => e
52
+ raise Peatio::Blockchain::ClientError, e
53
+ end
54
+
55
+ private
56
+
57
+ def filter_vout(tx_hash)
58
+ tx_hash.fetch("vout").select do |entry|
59
+ entry.fetch("value").to_d.positive? && entry["scriptPubKey"].has_key?("addresses")
60
+ end
61
+ end
62
+
63
+ def build_transaction(tx_hash)
64
+ filter_vout(tx_hash).each_with_object([]) do |entry, formatted_txs|
65
+ no_currency_tx = {hash: tx_hash["txid"], txout: entry["n"],
66
+ to_address: entry["scriptPubKey"]["addresses"][0],
67
+ amount: entry.fetch("value").to_d,
68
+ status: "success"}
69
+
70
+ # Build transaction for each currency belonging to blockchain.
71
+ settings_fetch(:currencies).pluck(:id).each do |currency_id|
72
+ formatted_txs << no_currency_tx.merge(currency_id: currency_id)
73
+ end
74
+ end
75
+ end
76
+
77
+ def client
78
+ @client ||= Client.new(settings_fetch(:server))
79
+ end
80
+
81
+ def settings_fetch(key)
82
+ @settings.fetch(key) { raise Peatio::Blockchain::MissingSettingError, key.to_s }
83
+ end
84
+ end
85
+ end
86
+ end
@@ -1,61 +1,56 @@
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 Thought
9
9
  class Client
10
- Error = Class.new(StandardError)
11
- ConnectionError = Class.new(Error)
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
23
-
18
+ end
24
19
 
25
- extend Memoist
20
+ extend Memoist
26
21
 
27
- def initialize(endpoint)
28
- @json_rpc_endpoint = URI.parse(endpoint)
29
- end
22
+ def initialize(endpoint, idle_timeout: 5)
23
+ @json_rpc_endpoint = URI.parse(endpoint)
24
+ @idle_timeout = idle_timeout
25
+ end
30
26
 
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
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
43
  private
48
44
 
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
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)
57
51
  end
58
52
  end
59
53
  end
60
54
  end
61
55
  end
56
+ end
@@ -28,8 +28,8 @@ module Peatio
28
28
  end
29
29
 
30
30
  def register
31
- Peatio::Blockchain.registry[:thought] = Thought::Blockchain.new
32
- Peatio::Wallet.registry[:thoughtd] = Thought::Wallet.new
31
+ Peatio::Blockchain.registry[:thought] = Thought::Blockchain
32
+ Peatio::Wallet.registry[:thoughtd] = Thought::Wallet
33
33
  end
34
34
  end
35
35
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Peatio
4
4
  module Thought
5
- VERSION = "2.6.7"
5
+ VERSION = "2.6.7.1"
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) do
19
+ @wallet = @settings.fetch(:wallet) {
20
20
  raise Peatio::Wallet::MissingSettingError, :wallet
21
- end.slice(:uri, :address)
21
+ }.slice(:uri, :address)
22
22
 
23
- @currency = @settings.fetch(:currency) do
23
+ @currency = @settings.fetch(:currency) {
24
24
  raise Peatio::Wallet::MissingSettingError, :currency
25
- end.slice(:id, :base_factor, :options)
25
+ }.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
@@ -61,4 +61,3 @@ module Peatio
61
61
  end
62
62
  end
63
63
  end
64
-
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.7
4
+ version: 2.6.7.1
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-17 00:00:00.000000000 Z
11
+ date: 2020-11-18 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.6
273
+ rubygems_version: 3.0.3
274
274
  signing_key:
275
275
  specification_version: 4
276
276
  summary: Peatio Thought Blockchain Plugin