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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/peatio/thought/blockchain.rb +44 -49
- data/lib/peatio/thought/client.rb +36 -41
- data/lib/peatio/thought/hooks.rb +2 -2
- data/lib/peatio/thought/version.rb +1 -1
- data/lib/peatio/thought/wallet.rb +9 -10
- 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: 3863bcba08ebff661b9bcd89a85b17dc3af9ed90ea3dafe80ae8fa57edf97e4f
|
4
|
+
data.tar.gz: 0a7f7d64cdd64c8aae0b9dc296685305335b12f763f04af5c6fa248cdc3c7ec7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1a1f9a61d6ef4e994a9ee80d571382e8988f3777f527d7132e2ba4152a1a4a47ab80d935cf120b5e107e99d1ea9ce938c9b6c3e3fc6e103c6fb243f0ca2f9d5
|
7
|
+
data.tar.gz: 589c25150d4d1673855f196570a6f3cb761fa4aade4d30bcb57a7873e91f1e1ec975edc34349d563b34abf64930501616229f9a1735f215a70fa99f2ced5d5cb
|
data/Gemfile.lock
CHANGED
@@ -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
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
4
|
-
require
|
5
|
-
require
|
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
|
-
|
11
|
-
ConnectionError = Class.new(Error)
|
10
|
+
Error = Class.new(StandardError)
|
12
11
|
|
13
|
-
|
14
|
-
def initialize(code, msg)
|
15
|
-
@code = code
|
16
|
-
@msg = msg
|
17
|
-
end
|
12
|
+
class ConnectionError < Error; end
|
18
13
|
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
class ResponseError < Error
|
15
|
+
def initialize(code, msg)
|
16
|
+
super "#{msg} (#{code})"
|
22
17
|
end
|
23
|
-
|
18
|
+
end
|
24
19
|
|
25
|
-
|
20
|
+
extend Memoist
|
26
21
|
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
def initialize(endpoint, idle_timeout: 5)
|
23
|
+
@json_rpc_endpoint = URI.parse(endpoint)
|
24
|
+
@idle_timeout = idle_timeout
|
25
|
+
end
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
43
|
private
|
48
44
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
data/lib/peatio/thought/hooks.rb
CHANGED
@@ -28,8 +28,8 @@ module Peatio
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def register
|
31
|
-
Peatio::Blockchain.registry[:thought] = Thought::Blockchain
|
32
|
-
Peatio::Wallet.registry[:thoughtd] = Thought::Wallet
|
31
|
+
Peatio::Blockchain.registry[:thought] = Thought::Blockchain
|
32
|
+
Peatio::Wallet.registry[:thoughtd] = Thought::Wallet
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -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) {
|
20
20
|
raise Peatio::Wallet::MissingSettingError, :wallet
|
21
|
-
|
21
|
+
}.slice(:uri, :address)
|
22
22
|
|
23
|
-
@currency = @settings.fetch(:currency)
|
23
|
+
@currency = @settings.fetch(:currency) {
|
24
24
|
raise Peatio::Wallet::MissingSettingError, :currency
|
25
|
-
|
25
|
+
}.slice(:id, :base_factor, :options)
|
26
26
|
end
|
27
27
|
|
28
|
-
def create_address!(_options
|
29
|
-
{
|
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
|
@@ -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-
|
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.
|
273
|
+
rubygems_version: 3.0.3
|
274
274
|
signing_key:
|
275
275
|
specification_version: 4
|
276
276
|
summary: Peatio Thought Blockchain Plugin
|