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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/peatio/thought/blockchain.rb +27 -27
- data/lib/peatio/thought/client.rb +31 -39
- data/lib/peatio/thought/version.rb +1 -1
- data/lib/peatio/thought/wallet.rb +4 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2ac431dc42834213be104d8228405d166d6fbaed44de43a7c85d12e62e8cda7
|
4
|
+
data.tar.gz: d4dd5773e827047facbe616dcf4bf4002a2b5952301774a28dcc388590f27ec4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c24e9ee608e84c587d631f013ac747a752dc7814df856ff2b5f0838f9ca7878284f20b5113208beb3ff9daa063245409c4ccb209521dbcf3d5e960819c510318
|
7
|
+
data.tar.gz: 4d2f142b8cc002ca013c17194095ad80c1108e14e797edf76de3e46bad3de64bf9ef47a9acefabba558c0290d78ef93d290cdb8678ae80a740420b31f30a28ca
|
data/Gemfile.lock
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
81
|
-
|
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
|
-
|
11
|
+
|
12
|
+
class ConnectionError < Error; end
|
12
13
|
|
13
14
|
class ResponseError < Error
|
14
15
|
def initialize(code, msg)
|
15
|
-
|
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
|
-
|
28
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
@@ -54,10 +54,10 @@ module Peatio
|
|
54
54
|
|
55
55
|
private
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
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.
|
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-
|
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.
|
273
|
+
rubygems_version: 3.0.6
|
274
274
|
signing_key:
|
275
275
|
specification_version: 4
|
276
276
|
summary: Peatio Thought Blockchain Plugin
|