peatio-electrum 0.1.0 → 2.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/Gemfile.lock +101 -39
- data/README.md +2 -2
- data/lib/peatio/electrum/blockchain.rb +59 -5
- data/lib/peatio/electrum/client.rb +105 -0
- data/lib/peatio/electrum/hooks.rb +3 -10
- data/lib/peatio/electrum/version.rb +1 -1
- data/lib/peatio/electrum/wallet.rb +31 -33
- data/lib/peatio/electrum.rb +12 -5
- data/peatio-electrum.gemspec +10 -4
- metadata +74 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ffeef075773466c5d82e4056223f1d259cc8fbef84021530c17a9dfc7e7bdf6
|
4
|
+
data.tar.gz: b6daa277f52c9e016cc68993db78b90136e40b859fe2bb7b836e10eb4aacd921
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 698483cff5a219b66f96dba7a8a7736b47287180161be52e8ba91745c898a0d99fe2b84440b9d625c580cd45229d010eb30c50b1eb10c0a6601237b8a6ad279b
|
7
|
+
data.tar.gz: ac9914a3c5495e8c6e2b94883b20cdb8f3b5a437c2beae654d3034c41f6b692dbd053e630c65c876ba1a0e5240db7c13e2c360862f35e0779608980a4c73a68d
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/Gemfile.lock
CHANGED
@@ -1,37 +1,104 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
peatio-electrum (
|
4
|
+
peatio-electrum (2.6.3)
|
5
|
+
activesupport (~> 5.2.3)
|
6
|
+
faraday (~> 0.17)
|
7
|
+
net-http-persistent (~> 3.0.1)
|
8
|
+
peatio (>= 0.6.3)
|
5
9
|
|
6
10
|
GEM
|
7
11
|
remote: https://rubygems.org/
|
8
12
|
specs:
|
9
|
-
|
13
|
+
activemodel (5.2.6)
|
14
|
+
activesupport (= 5.2.6)
|
15
|
+
activesupport (5.2.6)
|
10
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
17
|
i18n (>= 0.7, < 2)
|
12
18
|
minitest (~> 5.1)
|
13
19
|
tzinfo (~> 1.1)
|
14
|
-
|
15
|
-
|
16
|
-
|
20
|
+
addressable (2.8.0)
|
21
|
+
public_suffix (>= 2.0.2, < 5.0)
|
22
|
+
amq-protocol (2.3.2)
|
23
|
+
amqp (1.8.0)
|
24
|
+
amq-protocol (>= 2.2.0)
|
25
|
+
eventmachine
|
26
|
+
bunny (2.19.0)
|
27
|
+
amq-protocol (~> 2.3, >= 2.3.1)
|
28
|
+
sorted_set (~> 1, >= 1.0.2)
|
29
|
+
byebug (11.1.3)
|
30
|
+
clamp (1.3.2)
|
31
|
+
concurrent-ruby (1.1.9)
|
32
|
+
connection_pool (2.2.5)
|
33
|
+
cookiejar (0.3.3)
|
34
|
+
crack (0.4.3)
|
35
|
+
safe_yaml (~> 1.0.0)
|
36
|
+
daemons (1.4.1)
|
17
37
|
diff-lcs (1.3)
|
18
38
|
docile (1.3.2)
|
19
|
-
|
39
|
+
em-http-request (1.1.7)
|
40
|
+
addressable (>= 2.3.4)
|
41
|
+
cookiejar (!= 0.3.1)
|
42
|
+
em-socksify (>= 0.3)
|
43
|
+
eventmachine (>= 1.0.3)
|
44
|
+
http_parser.rb (>= 0.6.0)
|
45
|
+
em-socksify (0.3.2)
|
46
|
+
eventmachine (>= 1.0.0.beta.4)
|
47
|
+
em-synchrony (1.0.6)
|
48
|
+
eventmachine (>= 1.0.0.beta.1)
|
49
|
+
em-websocket (0.5.3)
|
50
|
+
eventmachine (>= 0.12.9)
|
51
|
+
http_parser.rb (~> 0)
|
52
|
+
eventmachine (1.2.7)
|
53
|
+
faraday (0.17.4)
|
54
|
+
multipart-post (>= 1.2, < 3)
|
55
|
+
faraday_middleware (0.13.1)
|
56
|
+
faraday (>= 0.7.4, < 1.0)
|
57
|
+
faye (1.4.0)
|
58
|
+
cookiejar (>= 0.3.0)
|
59
|
+
em-http-request (>= 1.1.6)
|
60
|
+
eventmachine (>= 0.12.0)
|
61
|
+
faye-websocket (>= 0.11.0)
|
62
|
+
multi_json (>= 1.0.0)
|
63
|
+
rack (>= 1.0.0)
|
64
|
+
websocket-driver (>= 0.5.1)
|
65
|
+
faye-websocket (0.11.1)
|
66
|
+
eventmachine (>= 0.12.0)
|
67
|
+
websocket-driver (>= 0.5.1)
|
68
|
+
hashdiff (1.0.1)
|
69
|
+
http_parser.rb (0.8.0)
|
70
|
+
i18n (1.9.1)
|
20
71
|
concurrent-ruby (~> 1.0)
|
21
72
|
io-console (0.5.6)
|
22
73
|
irb (1.2.4)
|
23
74
|
reline (>= 0.0.1)
|
24
|
-
|
25
|
-
minitest (5.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
75
|
+
jwt (2.3.0)
|
76
|
+
minitest (5.15.0)
|
77
|
+
multi_json (1.15.0)
|
78
|
+
multipart-post (2.1.1)
|
79
|
+
mysql2 (0.5.3)
|
80
|
+
net-http-persistent (3.0.1)
|
81
|
+
connection_pool (~> 2.2)
|
82
|
+
peatio (2.6.5)
|
83
|
+
activemodel (> 5.2, <= 6.0.0)
|
84
|
+
amqp
|
85
|
+
bunny
|
86
|
+
clamp
|
87
|
+
em-synchrony (~> 1.0)
|
88
|
+
em-websocket
|
89
|
+
eventmachine
|
90
|
+
faraday_middleware (~> 0.13.1)
|
91
|
+
faye (~> 1.2)
|
92
|
+
jwt
|
93
|
+
mysql2
|
94
|
+
prometheus-client
|
95
|
+
thin
|
96
|
+
prometheus-client (2.1.0)
|
97
|
+
public_suffix (4.0.6)
|
98
|
+
rack (2.2.3)
|
99
|
+
rbtree (0.4.5)
|
32
100
|
reline (0.1.4)
|
33
101
|
io-console (~> 0.5)
|
34
|
-
rexml (3.2.4)
|
35
102
|
rspec (3.9.0)
|
36
103
|
rspec-core (~> 3.9.0)
|
37
104
|
rspec-expectations (~> 3.9.0)
|
@@ -45,46 +112,41 @@ GEM
|
|
45
112
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
113
|
rspec-support (~> 3.9.0)
|
47
114
|
rspec-support (3.9.3)
|
48
|
-
|
49
|
-
|
50
|
-
parallel (~> 1.10)
|
51
|
-
parser (>= 2.7.0.1)
|
52
|
-
rainbow (>= 2.2.2, < 4.0)
|
53
|
-
rexml
|
54
|
-
ruby-progressbar (~> 1.7)
|
55
|
-
unicode-display_width (>= 1.4.0, < 2.0)
|
56
|
-
rubocop-github (0.15.0)
|
57
|
-
rubocop (<= 0.82.0)
|
58
|
-
rubocop-performance (~> 1.0)
|
59
|
-
rubocop-rails (~> 2.0)
|
60
|
-
rubocop-performance (1.5.2)
|
61
|
-
rubocop (>= 0.71.0)
|
62
|
-
rubocop-rails (2.5.2)
|
63
|
-
activesupport
|
64
|
-
rack (>= 1.1)
|
65
|
-
rubocop (>= 0.72.0)
|
66
|
-
ruby-progressbar (1.10.1)
|
115
|
+
safe_yaml (1.0.5)
|
116
|
+
set (1.0.2)
|
67
117
|
simplecov (0.18.5)
|
68
118
|
docile (~> 1.1)
|
69
119
|
simplecov-html (~> 0.11)
|
70
120
|
simplecov-html (0.12.2)
|
121
|
+
sorted_set (1.0.3)
|
122
|
+
rbtree
|
123
|
+
set (~> 1.0)
|
124
|
+
thin (1.8.1)
|
125
|
+
daemons (~> 1.0, >= 1.0.9)
|
126
|
+
eventmachine (~> 1.0, >= 1.0.4)
|
127
|
+
rack (>= 1, < 3)
|
71
128
|
thread_safe (0.3.6)
|
72
|
-
tzinfo (1.2.
|
129
|
+
tzinfo (1.2.9)
|
73
130
|
thread_safe (~> 0.1)
|
74
|
-
|
75
|
-
|
131
|
+
webmock (3.7.6)
|
132
|
+
addressable (>= 2.3.6)
|
133
|
+
crack (>= 0.3.2)
|
134
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
135
|
+
websocket-driver (0.7.5)
|
136
|
+
websocket-extensions (>= 0.1.0)
|
137
|
+
websocket-extensions (0.1.5)
|
76
138
|
|
77
139
|
PLATFORMS
|
78
140
|
ruby
|
79
141
|
|
80
142
|
DEPENDENCIES
|
81
143
|
bundler
|
144
|
+
byebug
|
82
145
|
irb
|
83
146
|
peatio-electrum!
|
84
|
-
rake (~> 10.0)
|
85
147
|
rspec (~> 3.0)
|
86
|
-
rubocop-github
|
87
148
|
simplecov
|
149
|
+
webmock (~> 3.5)
|
88
150
|
|
89
151
|
BUNDLED WITH
|
90
152
|
1.17.3
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Peatio Electrum
|
1
|
+
# Peatio plugin for Electrum wallet
|
2
2
|
|
3
|
-
This gem is a [peatio](https://github.com/openware/peatio) plugin adding the support of Electrum
|
3
|
+
This gem is a [peatio](https://github.com/openware/peatio) plugin adding the support of Electrum server to manage wallets.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -6,11 +6,13 @@ module Peatio::Electrum
|
|
6
6
|
# https://github.com/openware/peatio-core/blob/master/lib/peatio/blockchain/abstract.rb
|
7
7
|
#
|
8
8
|
class Blockchain < Peatio::Blockchain::Abstract
|
9
|
-
|
9
|
+
attr_reader :client
|
10
|
+
DEFAULT_FEATURES = { case_sensitive: true }.freeze
|
10
11
|
|
11
12
|
# You could override default features by passing them to initializer.
|
12
13
|
def initialize(custom_features = {})
|
13
14
|
@features = DEFAULT_FEATURES.merge(custom_features)
|
15
|
+
@settings = {}
|
14
16
|
end
|
15
17
|
|
16
18
|
# Merges given configuration parameters with defined during initialization
|
@@ -30,6 +32,8 @@ module Peatio::Electrum
|
|
30
32
|
# E.g. client state.
|
31
33
|
def configure(settings = {})
|
32
34
|
@settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
|
35
|
+
@client = Client.new(@settings[:server])
|
36
|
+
@currencies_ids = @settings[:currencies].pluck(:id)
|
33
37
|
end
|
34
38
|
|
35
39
|
# Fetches blockchain block by calling API and builds block object
|
@@ -40,7 +44,55 @@ module Peatio::Electrum
|
|
40
44
|
# @raise [Peatio::Blockchain::ClientError] if error was raised
|
41
45
|
# on blockchain API call.
|
42
46
|
def fetch_block!(block_number)
|
43
|
-
|
47
|
+
block = fetch_multi_blocks!(block_number, block_number + 1).first
|
48
|
+
return Peatio::Block.new(block_number, []) if block.nil?
|
49
|
+
|
50
|
+
block
|
51
|
+
end
|
52
|
+
|
53
|
+
# Fetches multiple blocks from the blockchain and builds an aggregated object
|
54
|
+
# from response payload.
|
55
|
+
#
|
56
|
+
# @param block_number_from [Integer] the block number to start from
|
57
|
+
# @param block_number_to [Integer] the endding block number (included)
|
58
|
+
# @return [Peatio::Block] the block object.
|
59
|
+
# @raise [Peatio::Blockchain::ClientError] if error was raised
|
60
|
+
# on blockchain API call.
|
61
|
+
def fetch_multi_blocks!(block_number_from, block_number_to)
|
62
|
+
unless client.is_synchronized
|
63
|
+
raise Peatio::Blockchain::ClientError, 'Electrum is synchronizing'
|
64
|
+
end
|
65
|
+
|
66
|
+
txs = []
|
67
|
+
blocks = []
|
68
|
+
current_height = block_number_from
|
69
|
+
|
70
|
+
client.history(nil, true, false, true, block_number_from, block_number_to)['transactions'].each do |tx|
|
71
|
+
if tx['height'] != current_height
|
72
|
+
blocks << Peatio::Block.new(current_height, txs) unless txs.empty?
|
73
|
+
txs = []
|
74
|
+
current_height = tx['height']
|
75
|
+
end
|
76
|
+
fee = tx['fee']
|
77
|
+
|
78
|
+
(tx['outputs'] || []).each_with_index do |out, i|
|
79
|
+
@currencies_ids.each do |currency_id|
|
80
|
+
txs << Peatio::Transaction.new(
|
81
|
+
hash: tx['txid'],
|
82
|
+
txout: i,
|
83
|
+
to_address: out['address'],
|
84
|
+
amount: out['value'].to_d,
|
85
|
+
status: 'success',
|
86
|
+
block_number: tx['height'],
|
87
|
+
currency_id: currency_id,
|
88
|
+
fee_currency_id: currency_id,
|
89
|
+
fee: fee
|
90
|
+
)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
blocks << Peatio::Block.new(current_height, txs) unless txs.empty?
|
95
|
+
blocks
|
44
96
|
end
|
45
97
|
|
46
98
|
# Fetches current blockchain height by calling API and returns it as number.
|
@@ -49,7 +101,9 @@ module Peatio::Electrum
|
|
49
101
|
# @raise [Peatio::Blockchain::ClientError] if error was raised
|
50
102
|
# on blockchain API call.
|
51
103
|
def latest_block_number
|
52
|
-
|
104
|
+
client.get_local_height
|
105
|
+
rescue Client::Error => e
|
106
|
+
raise Peatio::Blockchain::ClientError, e
|
53
107
|
end
|
54
108
|
|
55
109
|
# Fetches address balance of specific currency.
|
@@ -64,8 +118,8 @@ module Peatio::Electrum
|
|
64
118
|
# if error was raised on blockchain API call ClientError is raised.
|
65
119
|
# if blockchain API call was successful but we can't detect balance
|
66
120
|
# for address Error is raised.
|
67
|
-
def load_balance_of_address!(address,
|
68
|
-
|
121
|
+
def load_balance_of_address!(address, _currency_id)
|
122
|
+
client.get_address_balance(address)['confirmed']
|
69
123
|
end
|
70
124
|
end
|
71
125
|
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Peatio::Electrum
|
4
|
+
class Client
|
5
|
+
attr_reader :connection
|
6
|
+
|
7
|
+
Error = Class.new(StandardError)
|
8
|
+
ConfigurationError = Class.new(Error)
|
9
|
+
|
10
|
+
class ResponseError < Error
|
11
|
+
def initialize(code, msg)
|
12
|
+
@code = code
|
13
|
+
@msg = msg
|
14
|
+
end
|
15
|
+
|
16
|
+
def message
|
17
|
+
"#{@msg} (#{@code})"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(wallet_url)
|
22
|
+
@connection = Faraday.new(url: wallet_url)
|
23
|
+
end
|
24
|
+
|
25
|
+
def new_id
|
26
|
+
(Time.now.to_f * 1000).to_i
|
27
|
+
end
|
28
|
+
|
29
|
+
def call(method, params = [])
|
30
|
+
body = {
|
31
|
+
id: new_id,
|
32
|
+
method: method,
|
33
|
+
params: params
|
34
|
+
}.to_json
|
35
|
+
|
36
|
+
headers = {
|
37
|
+
'Accept' => 'application/json',
|
38
|
+
'Content-Type' => 'application/json'
|
39
|
+
}
|
40
|
+
|
41
|
+
response = JSON.parse(connection.post('/', body, headers).body)
|
42
|
+
error = response['error']
|
43
|
+
raise ResponseError.new(error['code'], error['message']) unless error.nil?
|
44
|
+
|
45
|
+
response['result']
|
46
|
+
end
|
47
|
+
|
48
|
+
def is_synchronized
|
49
|
+
call('is_synchronized', [])
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_local_height
|
53
|
+
call('get_local_height', [])
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_balance
|
57
|
+
call('getbalance')['confirmed'].to_d
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_address_balance(address)
|
61
|
+
call('getaddressbalance', [address])
|
62
|
+
.map { |k, v| [k, v.to_d] }.to_h
|
63
|
+
end
|
64
|
+
|
65
|
+
def create_address
|
66
|
+
call('createnewaddress')
|
67
|
+
end
|
68
|
+
|
69
|
+
def list_unspent
|
70
|
+
call('listunspent')
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_tx_status(txid)
|
74
|
+
call('get_tx_status', [txid])
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_transaction(txid)
|
78
|
+
call('gettransaction', [txid])
|
79
|
+
end
|
80
|
+
|
81
|
+
def history(year = nil, show_addresses = true, show_fiat = false, show_fees = true, from_height = nil, to_height = nil)
|
82
|
+
JSON.parse(call('history', [year, show_addresses, show_fiat, show_fees, from_height, to_height]))
|
83
|
+
end
|
84
|
+
|
85
|
+
## Default options:
|
86
|
+
## fee: nil
|
87
|
+
## from_addr: nil
|
88
|
+
## change_addr: nil
|
89
|
+
## nocheck: false
|
90
|
+
## unsigned: false
|
91
|
+
## rbf: nil
|
92
|
+
## password: nil
|
93
|
+
## locktime: nil
|
94
|
+
def payto(destination, amount, opts = {})
|
95
|
+
call('payto', {
|
96
|
+
destination: destination,
|
97
|
+
amount: amount
|
98
|
+
}.merge(opts).compact)
|
99
|
+
end
|
100
|
+
|
101
|
+
def broadcast(tx)
|
102
|
+
call('broadcast', [tx])
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -3,13 +3,6 @@
|
|
3
3
|
module Peatio::Electrum::Hooks
|
4
4
|
class << self
|
5
5
|
def check_compatibility
|
6
|
-
if Peatio::Blockchain::VERSION >= '2.0'
|
7
|
-
[
|
8
|
-
"Electrum plugin was designed for work with 1.x. Blockchain.",
|
9
|
-
"You have #{Peatio::Electrum::Blockchain::VERSION}."
|
10
|
-
].join('\n').tap { |s| Kernel.abort s }
|
11
|
-
end
|
12
|
-
|
13
6
|
if Peatio::Wallet::VERSION >= '2.0'
|
14
7
|
[
|
15
8
|
"Electrum plugin was designed for work with 1.x. Wallet.",
|
@@ -19,13 +12,13 @@ module Peatio::Electrum::Hooks
|
|
19
12
|
end
|
20
13
|
|
21
14
|
def register
|
22
|
-
Peatio::Blockchain.registry[:
|
23
|
-
Peatio::Wallet.registry[:
|
15
|
+
Peatio::Blockchain.registry[:electrum] = ::Peatio::Electrum::Blockchain
|
16
|
+
Peatio::Wallet.registry[:electrum] = ::Peatio::Electrum::Wallet
|
24
17
|
end
|
25
18
|
end
|
26
19
|
|
27
20
|
if defined?(Rails::Railtie)
|
28
|
-
require "peatio/
|
21
|
+
require "peatio/electrum/railtie"
|
29
22
|
else
|
30
23
|
check_compatibility
|
31
24
|
register
|
@@ -6,9 +6,13 @@ module Peatio::Electrum
|
|
6
6
|
# https://github.com/openware/peatio-core/blob/master/lib/peatio/wallet/abstract.rb
|
7
7
|
#
|
8
8
|
class Wallet < Peatio::Wallet::Abstract
|
9
|
+
attr_reader :client
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
DEFAULT_FEATURES = { skip_deposit_collection: false }.freeze
|
12
|
+
|
13
|
+
def initialize(custom_features = {})
|
14
|
+
@features = DEFAULT_FEATURES.merge(custom_features).slice(*SUPPORTED_FEATURES)
|
15
|
+
@settings = {}
|
12
16
|
end
|
13
17
|
|
14
18
|
# Merges given configuration parameters with defined during initialization
|
@@ -28,8 +32,6 @@ module Peatio::Electrum
|
|
28
32
|
# Clean everything what could be related to other wallet configuration.
|
29
33
|
# E.g. client state.
|
30
34
|
def configure(settings = {})
|
31
|
-
# Clean client state during configure.
|
32
|
-
@client = nil
|
33
35
|
@settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
|
34
36
|
|
35
37
|
@wallet = @settings.fetch(:wallet) do
|
@@ -39,6 +41,12 @@ module Peatio::Electrum
|
|
39
41
|
@currency = @settings.fetch(:currency) do
|
40
42
|
raise Peatio::Wallet::MissingSettingError, :currency
|
41
43
|
end.slice(:id, :base_factor, :options)
|
44
|
+
|
45
|
+
unless @settings[:wallet][:uri]
|
46
|
+
raise Peatio::Wallet::MissingSettingError, 'Missing uri in wallet'
|
47
|
+
end
|
48
|
+
|
49
|
+
@client = Client.new(@settings[:wallet][:uri])
|
42
50
|
end
|
43
51
|
|
44
52
|
# Performs API call for address creation and returns it.
|
@@ -48,15 +56,19 @@ module Peatio::Electrum
|
|
48
56
|
#
|
49
57
|
# @return [Hash] newly created blockchain address.
|
50
58
|
#
|
51
|
-
# @raise [Peatio::
|
59
|
+
# @raise [Peatio::Wallet::ClientError] if error was raised
|
52
60
|
# on wallet API call.
|
53
61
|
#
|
54
62
|
# @example
|
55
63
|
# { address: :fake_address,
|
56
64
|
# secret: :changeme,
|
57
65
|
# details: { uid: account.member.uid } }
|
58
|
-
def create_address!(
|
59
|
-
|
66
|
+
def create_address!(_options = {})
|
67
|
+
{
|
68
|
+
address: client.create_address
|
69
|
+
}
|
70
|
+
rescue Peatio::Electrum::Client::Error => e
|
71
|
+
raise Peatio::Wallet::ClientError, e
|
60
72
|
end
|
61
73
|
|
62
74
|
# Performs API call for creating transaction and returns updated transaction.
|
@@ -77,10 +89,15 @@ module Peatio::Electrum
|
|
77
89
|
#
|
78
90
|
# @return [Peatio::Transaction] transaction with updated hash.
|
79
91
|
#
|
80
|
-
# @raise [Peatio::
|
92
|
+
# @raise [Peatio::Wallet::ClientError] if error was raised
|
81
93
|
# on wallet API call.
|
82
|
-
def create_transaction!(transaction,
|
83
|
-
|
94
|
+
def create_transaction!(transaction, _options = {})
|
95
|
+
tx = client.payto(transaction.to_address, transaction.amount, password: @settings[:wallet][:secret])['hex']
|
96
|
+
txid = client.broadcast(tx)
|
97
|
+
transaction.hash = txid
|
98
|
+
transaction
|
99
|
+
rescue Peatio::Electrum::Client::Error => e
|
100
|
+
raise Peatio::Wallet::ClientError, e
|
84
101
|
end
|
85
102
|
|
86
103
|
# Fetches address balance of specific currency.
|
@@ -90,33 +107,14 @@ module Peatio::Electrum
|
|
90
107
|
#
|
91
108
|
# @return [BigDecimal] the current address balance.
|
92
109
|
#
|
93
|
-
# @raise [Peatio::
|
110
|
+
# @raise [Peatio::Wallet::ClientError]
|
94
111
|
# if error was raised on wallet API call ClientError is raised.
|
95
112
|
# if wallet API call was successful but we can't detect balance
|
96
113
|
# for address Error is raised.
|
97
114
|
def load_balance!
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
# Performs API call(s) for preparing for deposit collection.
|
102
|
-
# E.g deposits ETH for collecting ERC20 tokens in case of Ethereum blockchain.
|
103
|
-
#
|
104
|
-
# @note Optional. Override this method only if you need additional step
|
105
|
-
# before deposit collection.
|
106
|
-
#
|
107
|
-
# @param [Peatio::Transaction] deposit_transaction transaction which
|
108
|
-
# describes received deposit.
|
109
|
-
#
|
110
|
-
# @param [Array<Peatio::Transaction>] spread_transactions result of deposit
|
111
|
-
# spread between wallets.
|
112
|
-
#
|
113
|
-
# @return [Array<Peatio::Transaction>] transaction created for
|
114
|
-
# deposit collection preparing.
|
115
|
-
# By default return empty [Array]
|
116
|
-
def prepare_deposit_collection!(deposit_transaction, spread_transactions, deposit_currency)
|
117
|
-
# This method is mostly used for coins which needs additional fees
|
118
|
-
# to be deposited before deposit collection.
|
119
|
-
[]
|
115
|
+
client.get_balance
|
116
|
+
rescue Peatio::Electrum::Client::Error => e
|
117
|
+
raise Peatio::Wallet::ClientError, e
|
120
118
|
end
|
121
119
|
|
122
120
|
end
|
data/lib/peatio/electrum.rb
CHANGED
@@ -1,13 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'active_support/core_ext/object/blank'
|
4
|
+
require 'active_support/core_ext/enumerable'
|
5
|
+
require 'peatio'
|
6
|
+
require 'faraday'
|
7
|
+
require 'faraday_middleware'
|
8
|
+
require 'json'
|
9
|
+
|
3
10
|
module Peatio
|
4
11
|
module Electrum
|
5
12
|
Error = Class.new(StandardError)
|
6
13
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
14
|
+
require 'peatio/electrum/version'
|
15
|
+
require 'peatio/electrum/client'
|
16
|
+
require 'peatio/electrum/blockchain'
|
17
|
+
require 'peatio/electrum/wallet'
|
18
|
+
require 'peatio/electrum/hooks'
|
11
19
|
end
|
12
20
|
end
|
13
|
-
|
data/peatio-electrum.gemspec
CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ["Camille Meulien"]
|
11
11
|
spec.email = ["cmeulien@heliostech.fr"]
|
12
12
|
|
13
|
-
spec.summary = "Peatio Electrum
|
14
|
-
spec.description = "Peatio Electrum
|
13
|
+
spec.summary = "Peatio Plugin for Electrum server"
|
14
|
+
spec.description = "Peatio Plugin for Electrum server"
|
15
15
|
spec.homepage = "https://www.openware.com"
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
@@ -34,10 +34,16 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
|
35
35
|
spec.require_paths = ["lib"]
|
36
36
|
|
37
|
+
spec.add_dependency "activesupport", "~> 5.2.3"
|
38
|
+
spec.add_dependency "faraday", "~> 0.17"
|
39
|
+
|
40
|
+
spec.add_dependency "peatio", ">= 0.6.3"
|
41
|
+
spec.add_dependency 'net-http-persistent', '~> 3.0.1'
|
42
|
+
|
37
43
|
spec.add_development_dependency "bundler"
|
44
|
+
spec.add_development_dependency "byebug"
|
38
45
|
spec.add_development_dependency "irb"
|
39
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
40
46
|
spec.add_development_dependency "rspec", "~> 3.0"
|
41
|
-
spec.add_development_dependency "
|
47
|
+
spec.add_development_dependency "webmock", "~> 3.5"
|
42
48
|
spec.add_development_dependency "simplecov"
|
43
49
|
end
|
metadata
CHANGED
@@ -1,15 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peatio-electrum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Camille Meulien
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.2.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.17'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.17'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: peatio
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.6.3
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.6.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: net-http-persistent
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.1
|
13
69
|
- !ruby/object:Gem::Dependency
|
14
70
|
name: bundler
|
15
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -25,7 +81,7 @@ dependencies:
|
|
25
81
|
- !ruby/object:Gem::Version
|
26
82
|
version: '0'
|
27
83
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
84
|
+
name: byebug
|
29
85
|
requirement: !ruby/object:Gem::Requirement
|
30
86
|
requirements:
|
31
87
|
- - ">="
|
@@ -39,19 +95,19 @@ dependencies:
|
|
39
95
|
- !ruby/object:Gem::Version
|
40
96
|
version: '0'
|
41
97
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
98
|
+
name: irb
|
43
99
|
requirement: !ruby/object:Gem::Requirement
|
44
100
|
requirements:
|
45
|
-
- - "
|
101
|
+
- - ">="
|
46
102
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
103
|
+
version: '0'
|
48
104
|
type: :development
|
49
105
|
prerelease: false
|
50
106
|
version_requirements: !ruby/object:Gem::Requirement
|
51
107
|
requirements:
|
52
|
-
- - "
|
108
|
+
- - ">="
|
53
109
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
110
|
+
version: '0'
|
55
111
|
- !ruby/object:Gem::Dependency
|
56
112
|
name: rspec
|
57
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,19 +123,19 @@ dependencies:
|
|
67
123
|
- !ruby/object:Gem::Version
|
68
124
|
version: '3.0'
|
69
125
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
126
|
+
name: webmock
|
71
127
|
requirement: !ruby/object:Gem::Requirement
|
72
128
|
requirements:
|
73
|
-
- - "
|
129
|
+
- - "~>"
|
74
130
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
131
|
+
version: '3.5'
|
76
132
|
type: :development
|
77
133
|
prerelease: false
|
78
134
|
version_requirements: !ruby/object:Gem::Requirement
|
79
135
|
requirements:
|
80
|
-
- - "
|
136
|
+
- - "~>"
|
81
137
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
138
|
+
version: '3.5'
|
83
139
|
- !ruby/object:Gem::Dependency
|
84
140
|
name: simplecov
|
85
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,13 +150,14 @@ dependencies:
|
|
94
150
|
- - ">="
|
95
151
|
- !ruby/object:Gem::Version
|
96
152
|
version: '0'
|
97
|
-
description: Peatio Electrum
|
153
|
+
description: Peatio Plugin for Electrum server
|
98
154
|
email:
|
99
155
|
- cmeulien@heliostech.fr
|
100
156
|
executables: []
|
101
157
|
extensions: []
|
102
158
|
extra_rdoc_files: []
|
103
159
|
files:
|
160
|
+
- ".rspec"
|
104
161
|
- Gemfile
|
105
162
|
- Gemfile.lock
|
106
163
|
- README.md
|
@@ -109,6 +166,7 @@ files:
|
|
109
166
|
- bin/peatio-electrum-setup
|
110
167
|
- lib/peatio/electrum.rb
|
111
168
|
- lib/peatio/electrum/blockchain.rb
|
169
|
+
- lib/peatio/electrum/client.rb
|
112
170
|
- lib/peatio/electrum/hooks.rb
|
113
171
|
- lib/peatio/electrum/railtie.rb
|
114
172
|
- lib/peatio/electrum/version.rb
|
@@ -135,8 +193,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
193
|
- !ruby/object:Gem::Version
|
136
194
|
version: '0'
|
137
195
|
requirements: []
|
138
|
-
rubygems_version: 3.0.3
|
196
|
+
rubygems_version: 3.0.3.1
|
139
197
|
signing_key:
|
140
198
|
specification_version: 4
|
141
|
-
summary: Peatio Electrum
|
199
|
+
summary: Peatio Plugin for Electrum server
|
142
200
|
test_files: []
|