peatio-electrum 0.1.0 → 2.6.0
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/.rspec +1 -0
- data/Gemfile.lock +90 -34
- data/README.md +2 -2
- data/lib/peatio/electrum/blockchain.rb +55 -5
- data/lib/peatio/electrum/client.rb +93 -0
- data/lib/peatio/electrum/hooks.rb +3 -10
- data/lib/peatio/electrum/version.rb +1 -1
- data/lib/peatio/electrum/wallet.rb +26 -31
- data/lib/peatio/electrum.rb +12 -5
- data/peatio-electrum.gemspec +10 -4
- metadata +73 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 50df12238fd4fba9831a9d92f2fec6ea8a30e53ebdc9271a443a042a01ec09ad
|
|
4
|
+
data.tar.gz: 0b55deaab7a4ac88c31d1ab71f6e0d4b05feb562766d360a2b16c46aa208e878
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e65206ef966d3d7fbae20bf284776ad4ac69a54376cbc8a85df52e9242c975c30af36fa8ebbcb9146132c29431ce74f85e13565c8c276ee20fec546c41bef472
|
|
7
|
+
data.tar.gz: 3a869b3a570b0fb00000353d7332e87617a0d7e12c3bb0ef1d88da522f74fa70ae5146b09530f5500cb76169011d5b4ddaf97b99396491b404fe44afb8709ba7
|
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--require spec_helper
|
data/Gemfile.lock
CHANGED
|
@@ -1,37 +1,102 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
peatio-electrum (
|
|
4
|
+
peatio-electrum (2.6.0)
|
|
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.4.2)
|
|
14
|
+
activesupport (= 5.2.4.2)
|
|
15
|
+
activesupport (5.2.4.2)
|
|
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
|
-
|
|
20
|
+
addressable (2.7.0)
|
|
21
|
+
public_suffix (>= 2.0.2, < 5.0)
|
|
22
|
+
amq-protocol (2.3.1)
|
|
23
|
+
amqp (1.8.0)
|
|
24
|
+
amq-protocol (>= 2.2.0)
|
|
25
|
+
eventmachine
|
|
26
|
+
bunny (2.15.0)
|
|
27
|
+
amq-protocol (~> 2.3, >= 2.3.1)
|
|
28
|
+
byebug (11.1.3)
|
|
29
|
+
clamp (1.3.1)
|
|
16
30
|
concurrent-ruby (1.1.6)
|
|
31
|
+
connection_pool (2.2.2)
|
|
32
|
+
cookiejar (0.3.3)
|
|
33
|
+
crack (0.4.3)
|
|
34
|
+
safe_yaml (~> 1.0.0)
|
|
35
|
+
daemons (1.3.1)
|
|
17
36
|
diff-lcs (1.3)
|
|
18
37
|
docile (1.3.2)
|
|
38
|
+
em-http-request (1.1.5)
|
|
39
|
+
addressable (>= 2.3.4)
|
|
40
|
+
cookiejar (!= 0.3.1)
|
|
41
|
+
em-socksify (>= 0.3)
|
|
42
|
+
eventmachine (>= 1.0.3)
|
|
43
|
+
http_parser.rb (>= 0.6.0)
|
|
44
|
+
em-socksify (0.3.2)
|
|
45
|
+
eventmachine (>= 1.0.0.beta.4)
|
|
46
|
+
em-synchrony (1.0.6)
|
|
47
|
+
eventmachine (>= 1.0.0.beta.1)
|
|
48
|
+
em-websocket (0.5.1)
|
|
49
|
+
eventmachine (>= 0.12.9)
|
|
50
|
+
http_parser.rb (~> 0.6.0)
|
|
51
|
+
eventmachine (1.2.7)
|
|
52
|
+
faraday (0.17.3)
|
|
53
|
+
multipart-post (>= 1.2, < 3)
|
|
54
|
+
faraday_middleware (0.13.1)
|
|
55
|
+
faraday (>= 0.7.4, < 1.0)
|
|
56
|
+
faye (1.2.5)
|
|
57
|
+
cookiejar (>= 0.3.0)
|
|
58
|
+
em-http-request (>= 0.3.0)
|
|
59
|
+
eventmachine (>= 0.12.0)
|
|
60
|
+
faye-websocket (>= 0.9.1)
|
|
61
|
+
multi_json (>= 1.0.0)
|
|
62
|
+
rack (>= 1.0.0)
|
|
63
|
+
websocket-driver (>= 0.5.1)
|
|
64
|
+
faye-websocket (0.10.9)
|
|
65
|
+
eventmachine (>= 0.12.0)
|
|
66
|
+
websocket-driver (>= 0.5.1)
|
|
67
|
+
hashdiff (1.0.1)
|
|
68
|
+
http_parser.rb (0.6.0)
|
|
19
69
|
i18n (1.8.2)
|
|
20
70
|
concurrent-ruby (~> 1.0)
|
|
21
71
|
io-console (0.5.6)
|
|
22
72
|
irb (1.2.4)
|
|
23
73
|
reline (>= 0.0.1)
|
|
24
|
-
|
|
74
|
+
jwt (2.2.1)
|
|
25
75
|
minitest (5.14.0)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
76
|
+
multi_json (1.14.1)
|
|
77
|
+
multipart-post (2.1.1)
|
|
78
|
+
mysql2 (0.5.3)
|
|
79
|
+
net-http-persistent (3.0.1)
|
|
80
|
+
connection_pool (~> 2.2)
|
|
81
|
+
peatio (2.4.4)
|
|
82
|
+
activemodel (> 5.2, <= 6.0.0)
|
|
83
|
+
amqp
|
|
84
|
+
bunny
|
|
85
|
+
clamp
|
|
86
|
+
em-synchrony (~> 1.0)
|
|
87
|
+
em-websocket
|
|
88
|
+
eventmachine
|
|
89
|
+
faraday_middleware (~> 0.13.1)
|
|
90
|
+
faye (~> 1.2)
|
|
91
|
+
jwt
|
|
92
|
+
mysql2
|
|
93
|
+
prometheus-client
|
|
94
|
+
thin
|
|
95
|
+
prometheus-client (2.0.0)
|
|
96
|
+
public_suffix (4.0.5)
|
|
29
97
|
rack (2.2.2)
|
|
30
|
-
rainbow (3.0.0)
|
|
31
|
-
rake (10.5.0)
|
|
32
98
|
reline (0.1.4)
|
|
33
99
|
io-console (~> 0.5)
|
|
34
|
-
rexml (3.2.4)
|
|
35
100
|
rspec (3.9.0)
|
|
36
101
|
rspec-core (~> 3.9.0)
|
|
37
102
|
rspec-expectations (~> 3.9.0)
|
|
@@ -45,46 +110,37 @@ GEM
|
|
|
45
110
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
46
111
|
rspec-support (~> 3.9.0)
|
|
47
112
|
rspec-support (3.9.3)
|
|
48
|
-
|
|
49
|
-
jaro_winkler (~> 1.5.1)
|
|
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)
|
|
113
|
+
safe_yaml (1.0.5)
|
|
67
114
|
simplecov (0.18.5)
|
|
68
115
|
docile (~> 1.1)
|
|
69
116
|
simplecov-html (~> 0.11)
|
|
70
117
|
simplecov-html (0.12.2)
|
|
118
|
+
thin (1.7.2)
|
|
119
|
+
daemons (~> 1.0, >= 1.0.9)
|
|
120
|
+
eventmachine (~> 1.0, >= 1.0.4)
|
|
121
|
+
rack (>= 1, < 3)
|
|
71
122
|
thread_safe (0.3.6)
|
|
72
123
|
tzinfo (1.2.7)
|
|
73
124
|
thread_safe (~> 0.1)
|
|
74
|
-
|
|
75
|
-
|
|
125
|
+
webmock (3.7.6)
|
|
126
|
+
addressable (>= 2.3.6)
|
|
127
|
+
crack (>= 0.3.2)
|
|
128
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
129
|
+
websocket-driver (0.7.1)
|
|
130
|
+
websocket-extensions (>= 0.1.0)
|
|
131
|
+
websocket-extensions (0.1.4)
|
|
76
132
|
|
|
77
133
|
PLATFORMS
|
|
78
134
|
ruby
|
|
79
135
|
|
|
80
136
|
DEPENDENCIES
|
|
81
137
|
bundler
|
|
138
|
+
byebug
|
|
82
139
|
irb
|
|
83
140
|
peatio-electrum!
|
|
84
|
-
rake (~> 10.0)
|
|
85
141
|
rspec (~> 3.0)
|
|
86
|
-
rubocop-github
|
|
87
142
|
simplecov
|
|
143
|
+
webmock (~> 3.5)
|
|
88
144
|
|
|
89
145
|
BUNDLED WITH
|
|
90
146
|
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,51 @@ 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
|
+
(tx['outputs'] || []).each_with_index do |out, i|
|
|
77
|
+
@currencies_ids.each do |currency_id|
|
|
78
|
+
txs << Peatio::Transaction.new(
|
|
79
|
+
hash: tx['txid'],
|
|
80
|
+
txout: i,
|
|
81
|
+
to_address: out['address'],
|
|
82
|
+
amount: out['value'].to_d,
|
|
83
|
+
status: 'success',
|
|
84
|
+
block_number: tx['height'],
|
|
85
|
+
currency_id: currency_id
|
|
86
|
+
)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
blocks << Peatio::Block.new(current_height, txs) unless txs.empty?
|
|
91
|
+
blocks
|
|
44
92
|
end
|
|
45
93
|
|
|
46
94
|
# Fetches current blockchain height by calling API and returns it as number.
|
|
@@ -49,7 +97,9 @@ module Peatio::Electrum
|
|
|
49
97
|
# @raise [Peatio::Blockchain::ClientError] if error was raised
|
|
50
98
|
# on blockchain API call.
|
|
51
99
|
def latest_block_number
|
|
52
|
-
|
|
100
|
+
client.get_local_height
|
|
101
|
+
rescue Client::Error => e
|
|
102
|
+
raise Peatio::Blockchain::ClientError, e
|
|
53
103
|
end
|
|
54
104
|
|
|
55
105
|
# Fetches address balance of specific currency.
|
|
@@ -64,8 +114,8 @@ module Peatio::Electrum
|
|
|
64
114
|
# if error was raised on blockchain API call ClientError is raised.
|
|
65
115
|
# if blockchain API call was successful but we can't detect balance
|
|
66
116
|
# for address Error is raised.
|
|
67
|
-
def load_balance_of_address!(address,
|
|
68
|
-
|
|
117
|
+
def load_balance_of_address!(address, _currency_id)
|
|
118
|
+
client.get_address_balance(address)['confirmed']
|
|
69
119
|
end
|
|
70
120
|
end
|
|
71
121
|
end
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
def payto(destination, amount, fee = nil, from_addr = nil, change_addr = nil, nocheck = false, unsigned = false, rbf = nil, password = nil, locktime = nil)
|
|
86
|
+
call('payto', [destination, amount, fee, from_addr, change_addr, nocheck, unsigned, rbf, password, locktime])
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def broadcast(tx)
|
|
90
|
+
call('broadcast', [tx])
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
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,6 +6,7 @@ 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
|
def initialize(settings = {})
|
|
11
12
|
@settings = settings
|
|
@@ -28,8 +29,6 @@ module Peatio::Electrum
|
|
|
28
29
|
# Clean everything what could be related to other wallet configuration.
|
|
29
30
|
# E.g. client state.
|
|
30
31
|
def configure(settings = {})
|
|
31
|
-
# Clean client state during configure.
|
|
32
|
-
@client = nil
|
|
33
32
|
@settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
|
|
34
33
|
|
|
35
34
|
@wallet = @settings.fetch(:wallet) do
|
|
@@ -39,6 +38,12 @@ module Peatio::Electrum
|
|
|
39
38
|
@currency = @settings.fetch(:currency) do
|
|
40
39
|
raise Peatio::Wallet::MissingSettingError, :currency
|
|
41
40
|
end.slice(:id, :base_factor, :options)
|
|
41
|
+
|
|
42
|
+
unless @settings[:wallet][:uri]
|
|
43
|
+
raise Peatio::Wallet::MissingSettingError, 'Missing uri in wallet'
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
@client = Client.new(@settings[:wallet][:uri])
|
|
42
47
|
end
|
|
43
48
|
|
|
44
49
|
# Performs API call for address creation and returns it.
|
|
@@ -48,15 +53,19 @@ module Peatio::Electrum
|
|
|
48
53
|
#
|
|
49
54
|
# @return [Hash] newly created blockchain address.
|
|
50
55
|
#
|
|
51
|
-
# @raise [Peatio::
|
|
56
|
+
# @raise [Peatio::Wallet::ClientError] if error was raised
|
|
52
57
|
# on wallet API call.
|
|
53
58
|
#
|
|
54
59
|
# @example
|
|
55
60
|
# { address: :fake_address,
|
|
56
61
|
# secret: :changeme,
|
|
57
62
|
# details: { uid: account.member.uid } }
|
|
58
|
-
def create_address!(
|
|
59
|
-
|
|
63
|
+
def create_address!(_options = {})
|
|
64
|
+
{
|
|
65
|
+
address: client.create_address
|
|
66
|
+
}
|
|
67
|
+
rescue Peatio::Electrum::Client::Error => e
|
|
68
|
+
raise Peatio::Wallet::ClientError, e
|
|
60
69
|
end
|
|
61
70
|
|
|
62
71
|
# Performs API call for creating transaction and returns updated transaction.
|
|
@@ -77,10 +86,15 @@ module Peatio::Electrum
|
|
|
77
86
|
#
|
|
78
87
|
# @return [Peatio::Transaction] transaction with updated hash.
|
|
79
88
|
#
|
|
80
|
-
# @raise [Peatio::
|
|
89
|
+
# @raise [Peatio::Wallet::ClientError] if error was raised
|
|
81
90
|
# on wallet API call.
|
|
82
|
-
def create_transaction!(transaction,
|
|
83
|
-
|
|
91
|
+
def create_transaction!(transaction, _options = {})
|
|
92
|
+
tx = client.payto(transaction.to_address, transaction.amount)['hex']
|
|
93
|
+
txid = client.broadcast(tx)
|
|
94
|
+
transaction.hash = txid
|
|
95
|
+
transaction
|
|
96
|
+
rescue Peatio::Electrum::Client::Error => e
|
|
97
|
+
raise Peatio::Wallet::ClientError, e
|
|
84
98
|
end
|
|
85
99
|
|
|
86
100
|
# Fetches address balance of specific currency.
|
|
@@ -90,33 +104,14 @@ module Peatio::Electrum
|
|
|
90
104
|
#
|
|
91
105
|
# @return [BigDecimal] the current address balance.
|
|
92
106
|
#
|
|
93
|
-
# @raise [Peatio::
|
|
107
|
+
# @raise [Peatio::Wallet::ClientError]
|
|
94
108
|
# if error was raised on wallet API call ClientError is raised.
|
|
95
109
|
# if wallet API call was successful but we can't detect balance
|
|
96
110
|
# for address Error is raised.
|
|
97
111
|
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
|
-
[]
|
|
112
|
+
client.get_balance
|
|
113
|
+
rescue Peatio::Electrum::Client::Error => e
|
|
114
|
+
raise Peatio::Wallet::ClientError, e
|
|
120
115
|
end
|
|
121
116
|
|
|
122
117
|
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.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Camille Meulien
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-05-
|
|
11
|
+
date: 2020-05-15 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
|
|
@@ -138,5 +196,5 @@ requirements: []
|
|
|
138
196
|
rubygems_version: 3.0.3
|
|
139
197
|
signing_key:
|
|
140
198
|
specification_version: 4
|
|
141
|
-
summary: Peatio Electrum
|
|
199
|
+
summary: Peatio Plugin for Electrum server
|
|
142
200
|
test_files: []
|