peatio-thought 2.6.5 → 2.6.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/peatio/thought/blockchain.rb +14 -8
- data/lib/peatio/thought/client.rb +35 -30
- data/lib/peatio/thought/version.rb +1 -1
- data/lib/peatio/thought/wallet.rb +14 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 497ca16ccc4eda7ac0fb035c68ef543a378364f6b142f2f85dccb57803e1ea88
|
4
|
+
data.tar.gz: a1d194a397cee8e577e9665f17b4a8dae3238e0cecbb39925a3d1857524a4e55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b3ff921351521a5dcbf80e4892d6d2a66879be411a7d940f0ff60443f7a0f8cff7bc17e2f4f4d3c33996d1f85c78d412ea9a4c143259a55f7070be2c85a7603
|
7
|
+
data.tar.gz: 91dc0dd40f9e4d24be962e0cff36a6a716d6b0005fdc1edb0b2df8626faa38fce4094fce9874876c56ccef998a18a37d3220346cb33c7aed2724f3989241e965
|
data/Gemfile.lock
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
15
|
+
@code = code
|
16
|
+
@msg = msg
|
17
|
+
end
|
18
|
+
|
19
|
+
def message
|
20
|
+
"#{@msg} (#{@code})"
|
21
|
+
end
|
17
22
|
end
|
18
|
-
|
23
|
+
|
19
24
|
|
20
25
|
extend Memoist
|
21
26
|
|
22
|
-
def initialize(endpoint
|
23
|
-
|
24
|
-
|
25
|
-
end
|
27
|
+
def initialize(endpoint)
|
28
|
+
@json_rpc_endpoint = URI.parse(endpoint)
|
29
|
+
end
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
@@ -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
|
-
|
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
|
-
|
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 ==
|
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
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
64
|
+
|