ouroboros-peatio-electrum 3.1.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 43894306eb1ef5bf5f2e59d5e00ece2b185b52a047d32a1c677978e60440dcb0
4
+ data.tar.gz: 4e50f8fba11daf84f708edc769e4a118fa2f93930a38e46ca83d431aed1bee74
5
+ SHA512:
6
+ metadata.gz: 81606e83a34677e6c2ea81a8b191d298097e56db6f775f3b0fb7bf2f49be5453a1d82d9813d4dc4051f4dad5c691e8489da66bd3a16afe0c093c009dad3043fc
7
+ data.tar.gz: 897275123c92dcb155815647858cbb37bdb47dc04a6f6e0f83ce14543126044a57d87cc9f533cbc7c7130bbdfdb9d23330e98a06ef9555e1f9ce6281280e217c
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in peatio-electrum.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,175 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ peatio-electrum (3.1.0)
5
+ activesupport (~> 6.1.0)
6
+ faraday (~> 1.10)
7
+ net-http-persistent (~> 4.0.1)
8
+ peatio (>= 3.1.1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activemodel (6.1.7.2)
14
+ activesupport (= 6.1.7.2)
15
+ activesupport (6.1.7.2)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ tzinfo (~> 2.0)
20
+ zeitwerk (~> 2.3)
21
+ addressable (2.8.1)
22
+ public_suffix (>= 2.0.2, < 6.0)
23
+ amq-protocol (2.3.2)
24
+ amqp (1.8.0)
25
+ amq-protocol (>= 2.2.0)
26
+ eventmachine
27
+ bunny (2.20.3)
28
+ amq-protocol (~> 2.3, >= 2.3.1)
29
+ sorted_set (~> 1, >= 1.0.2)
30
+ byebug (11.1.3)
31
+ clamp (1.3.2)
32
+ concurrent-ruby (1.2.2)
33
+ connection_pool (2.3.0)
34
+ cookiejar (0.3.3)
35
+ crack (0.4.5)
36
+ rexml
37
+ daemons (1.4.1)
38
+ diff-lcs (1.5.0)
39
+ docile (1.4.0)
40
+ em-http-request (1.1.7)
41
+ addressable (>= 2.3.4)
42
+ cookiejar (!= 0.3.1)
43
+ em-socksify (>= 0.3)
44
+ eventmachine (>= 1.0.3)
45
+ http_parser.rb (>= 0.6.0)
46
+ em-socksify (0.3.2)
47
+ eventmachine (>= 1.0.0.beta.4)
48
+ em-synchrony (1.0.6)
49
+ eventmachine (>= 1.0.0.beta.1)
50
+ em-websocket (0.5.3)
51
+ eventmachine (>= 0.12.9)
52
+ http_parser.rb (~> 0)
53
+ eventmachine (1.2.7)
54
+ faraday (1.10.3)
55
+ faraday-em_http (~> 1.0)
56
+ faraday-em_synchrony (~> 1.0)
57
+ faraday-excon (~> 1.1)
58
+ faraday-httpclient (~> 1.0)
59
+ faraday-multipart (~> 1.0)
60
+ faraday-net_http (~> 1.0)
61
+ faraday-net_http_persistent (~> 1.0)
62
+ faraday-patron (~> 1.0)
63
+ faraday-rack (~> 1.0)
64
+ faraday-retry (~> 1.0)
65
+ ruby2_keywords (>= 0.0.4)
66
+ faraday-em_http (1.0.0)
67
+ faraday-em_synchrony (1.0.0)
68
+ faraday-excon (1.1.0)
69
+ faraday-httpclient (1.0.1)
70
+ faraday-multipart (1.0.4)
71
+ multipart-post (~> 2)
72
+ faraday-net_http (1.0.1)
73
+ faraday-net_http_persistent (1.2.0)
74
+ faraday-patron (1.0.0)
75
+ faraday-rack (1.0.0)
76
+ faraday-retry (1.0.3)
77
+ faye (1.4.0)
78
+ cookiejar (>= 0.3.0)
79
+ em-http-request (>= 1.1.6)
80
+ eventmachine (>= 0.12.0)
81
+ faye-websocket (>= 0.11.0)
82
+ multi_json (>= 1.0.0)
83
+ rack (>= 1.0.0)
84
+ websocket-driver (>= 0.5.1)
85
+ faye-websocket (0.11.1)
86
+ eventmachine (>= 0.12.0)
87
+ websocket-driver (>= 0.5.1)
88
+ hashdiff (1.0.1)
89
+ http_parser.rb (0.8.0)
90
+ i18n (1.12.0)
91
+ concurrent-ruby (~> 1.0)
92
+ io-console (0.6.0)
93
+ irb (1.6.2)
94
+ reline (>= 0.3.0)
95
+ jwt (2.7.0)
96
+ minitest (5.17.0)
97
+ multi_json (1.15.0)
98
+ multipart-post (2.3.0)
99
+ mysql2 (0.5.5)
100
+ net-http-persistent (4.0.1)
101
+ connection_pool (~> 2.2)
102
+ peatio (3.1.1)
103
+ activemodel (> 5.2)
104
+ amqp
105
+ bunny
106
+ clamp
107
+ em-synchrony (~> 1.0)
108
+ em-websocket
109
+ eventmachine
110
+ faraday (~> 1.10)
111
+ faye (~> 1.2)
112
+ jwt
113
+ mysql2
114
+ prometheus-client
115
+ thin
116
+ prometheus-client (4.0.0)
117
+ public_suffix (5.0.1)
118
+ rack (2.2.6.2)
119
+ rbtree (0.4.6)
120
+ reline (0.3.2)
121
+ io-console (~> 0.5)
122
+ rexml (3.2.5)
123
+ rspec (3.12.0)
124
+ rspec-core (~> 3.12.0)
125
+ rspec-expectations (~> 3.12.0)
126
+ rspec-mocks (~> 3.12.0)
127
+ rspec-core (3.12.1)
128
+ rspec-support (~> 3.12.0)
129
+ rspec-expectations (3.12.2)
130
+ diff-lcs (>= 1.2.0, < 2.0)
131
+ rspec-support (~> 3.12.0)
132
+ rspec-mocks (3.12.3)
133
+ diff-lcs (>= 1.2.0, < 2.0)
134
+ rspec-support (~> 3.12.0)
135
+ rspec-support (3.12.0)
136
+ ruby2_keywords (0.0.5)
137
+ set (1.0.3)
138
+ simplecov (0.22.0)
139
+ docile (~> 1.1)
140
+ simplecov-html (~> 0.11)
141
+ simplecov_json_formatter (~> 0.1)
142
+ simplecov-html (0.12.3)
143
+ simplecov_json_formatter (0.1.4)
144
+ sorted_set (1.0.3)
145
+ rbtree
146
+ set (~> 1.0)
147
+ thin (1.8.1)
148
+ daemons (~> 1.0, >= 1.0.9)
149
+ eventmachine (~> 1.0, >= 1.0.4)
150
+ rack (>= 1, < 3)
151
+ tzinfo (2.0.6)
152
+ concurrent-ruby (~> 1.0)
153
+ webmock (3.18.1)
154
+ addressable (>= 2.8.0)
155
+ crack (>= 0.3.2)
156
+ hashdiff (>= 0.4.0, < 2.0.0)
157
+ websocket-driver (0.7.5)
158
+ websocket-extensions (>= 0.1.0)
159
+ websocket-extensions (0.1.5)
160
+ zeitwerk (2.6.7)
161
+
162
+ PLATFORMS
163
+ arm64-darwin-21
164
+
165
+ DEPENDENCIES
166
+ bundler (~> 2.4.7)
167
+ byebug
168
+ irb
169
+ peatio-electrum!
170
+ rspec (~> 3.0)
171
+ simplecov
172
+ webmock (~> 3.5)
173
+
174
+ BUNDLED WITH
175
+ 2.4.7
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # Peatio plugin for Electrum wallet
2
+
3
+ This gem is a [peatio](https://github.com/openware/peatio) plugin adding the support of Electrum server to manage wallets.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'peatio-electrum'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install peatio-electrum
20
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "peatio/electrum"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "peatio/electrum"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peatio::Electrum
4
+ #
5
+ # See the abstract class here:
6
+ # https://github.com/openware/peatio-core/blob/master/lib/peatio/blockchain/abstract.rb
7
+ #
8
+ class Blockchain < Peatio::Blockchain::Abstract
9
+ attr_reader :client
10
+ DEFAULT_FEATURES = { case_sensitive: true }.freeze
11
+
12
+ # You could override default features by passing them to initializer.
13
+ def initialize(custom_features = {})
14
+ @features = DEFAULT_FEATURES.merge(custom_features)
15
+ @settings = {}
16
+ end
17
+
18
+ # Merges given configuration parameters with defined during initialization
19
+ # and returns the result.
20
+ #
21
+ # @param [Hash] settings parameters to use.
22
+ #
23
+ # @option settings [String] :server Public blockchain API endpoint.
24
+ # @option settings [Array<Hash>] :currencies List of currency hashes
25
+ # with :id,:base_factor,:options(deprecated) keys.
26
+ # Custom keys could be added by defining them in Currency #options.
27
+ #
28
+ # @return [Hash] merged settings.
29
+ #
30
+ # @note Be careful with your blockchain state after configure.
31
+ # Clean everything what could be related to other blockchain configuration.
32
+ # E.g. client state.
33
+ def configure(settings = {})
34
+ @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
35
+ @client = Client.new(@settings[:server])
36
+ @currencies_ids = @settings[:currencies].pluck(:id)
37
+ end
38
+
39
+ # Fetches blockchain block by calling API and builds block object
40
+ # from response payload.
41
+ #
42
+ # @param block_number [Integer] the block number.
43
+ # @return [Peatio::Block] the block object.
44
+ # @raise [Peatio::Blockchain::ClientError] if error was raised
45
+ # on blockchain API call.
46
+ def fetch_block!(block_number)
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
96
+ end
97
+
98
+ # Fetches current blockchain height by calling API and returns it as number.
99
+ #
100
+ # @return [Integer] the current blockchain height.
101
+ # @raise [Peatio::Blockchain::ClientError] if error was raised
102
+ # on blockchain API call.
103
+ def latest_block_number
104
+ client.get_local_height
105
+ rescue Client::Error => e
106
+ raise Peatio::Blockchain::ClientError, e
107
+ end
108
+
109
+ # Fetches address balance of specific currency.
110
+ #
111
+ # @note Optional. Don't override this method if your blockchain
112
+ # doesn't provide functionality to get balance by address.
113
+ #
114
+ # @param address [String] the address for requesting balance.
115
+ # @param currency_id [String] which currency balance we need to request.
116
+ # @return [BigDecimal] the current address balance.
117
+ # @raise [Peatio::Blockchain::ClientError,Peatio::Blockchain::UnavailableAddressBalanceError]
118
+ # if error was raised on blockchain API call ClientError is raised.
119
+ # if blockchain API call was successful but we can't detect balance
120
+ # for address Error is raised.
121
+ def load_balance_of_address!(address, _currency_id)
122
+ client.get_address_balance(address)['confirmed']
123
+ end
124
+ end
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
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peatio::Electrum::Hooks
4
+ class << self
5
+ def check_compatibility
6
+ if Peatio::Wallet::VERSION >= '2.0'
7
+ [
8
+ "Electrum plugin was designed for work with 1.x. Wallet.",
9
+ "You have #{Peatio::Electrum::Wallet::VERSION}."
10
+ ].join('\n').tap { |s| Kernel.abort s }
11
+ end
12
+ end
13
+
14
+ def register
15
+ Peatio::Blockchain.registry[:electrum] = ::Peatio::Electrum::Blockchain
16
+ Peatio::Wallet.registry[:electrum] = ::Peatio::Electrum::Wallet
17
+ end
18
+ end
19
+
20
+ if defined?(Rails::Railtie)
21
+ require "peatio/electrum/railtie"
22
+ else
23
+ check_compatibility
24
+ register
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peatio::Electrum
4
+ class Railtie < Rails::Railtie
5
+ config.before_initialize do
6
+ Hooks.check_compatibility
7
+ end
8
+
9
+ config.after_initialize do
10
+ Hooks.register
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peatio
4
+ module Electrum
5
+ VERSION = "3.1.2".freeze
6
+ end
7
+ end
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peatio::Electrum
4
+ #
5
+ # See the abstract class here:
6
+ # https://github.com/openware/peatio-core/blob/master/lib/peatio/wallet/abstract.rb
7
+ #
8
+ class Wallet < Peatio::Wallet::Abstract
9
+ attr_reader :client
10
+
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 = {}
16
+ end
17
+
18
+ # Merges given configuration parameters with defined during initialization
19
+ # and returns the result.
20
+ #
21
+ # @param [Hash] settings configurations to use.
22
+ # @option settings [Hash] :wallet Wallet settings for performing API calls.
23
+ # With :address required key other settings could be customized
24
+ # using Wallet#settings.
25
+ # @option settings [Array<Hash>] :currencies List of currency hashes
26
+ # with :id,:base_factor,:options(deprecated) keys.
27
+ # Custom keys could be added by defining them in Currency #options.
28
+ #
29
+ # @return [Hash] merged settings.
30
+ #
31
+ # @note Be careful with your wallet state after configure.
32
+ # Clean everything what could be related to other wallet configuration.
33
+ # E.g. client state.
34
+ def configure(settings = {})
35
+ @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
36
+
37
+ @wallet = @settings.fetch(:wallet) do
38
+ raise Peatio::Wallet::MissingSettingError, :wallet
39
+ end.slice(:uri, :address, :secret)
40
+
41
+ @currency = @settings.fetch(:currency) do
42
+ raise Peatio::Wallet::MissingSettingError, :currency
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])
50
+ end
51
+
52
+ # Performs API call for address creation and returns it.
53
+ #
54
+ # @param [Hash] options
55
+ # @options options [String] :uid User UID which requested address creation.
56
+ #
57
+ # @return [Hash] newly created blockchain address.
58
+ #
59
+ # @raise [Peatio::Wallet::ClientError] if error was raised
60
+ # on wallet API call.
61
+ #
62
+ # @example
63
+ # { address: :fake_address,
64
+ # secret: :changeme,
65
+ # details: { uid: account.member.uid } }
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
72
+ end
73
+
74
+ # Performs API call for creating transaction and returns updated transaction.
75
+ #
76
+ # @param [Peatio::Transaction] transaction transaction with defined
77
+ # to_address, amount & currency_id.
78
+ #
79
+ # @param [Hash] options
80
+ # @options options [String] :subtract_fee Defines if you need to subtract
81
+ # fee from amount defined in transaction.
82
+ # It means that you need to deduct fee from amount declared in
83
+ # transaction and send only remaining amount.
84
+ # If transaction amount is 1.0 and estimated fee
85
+ # for sending transaction is 0.01 you need to send 0.09
86
+ # so 1.0 (0.9 + 0.1) will be subtracted from wallet balance
87
+ #
88
+ # @options options [String] custon options for wallet client.
89
+ #
90
+ # @return [Peatio::Transaction] transaction with updated hash.
91
+ #
92
+ # @raise [Peatio::Wallet::ClientError] if error was raised
93
+ # on wallet API call.
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
101
+ end
102
+
103
+ # Fetches address balance of specific currency.
104
+ #
105
+ # @note Optional. Don't override this method if your blockchain
106
+ # doesn't provide functionality to get balance by address.
107
+ #
108
+ # @return [BigDecimal] the current address balance.
109
+ #
110
+ # @raise [Peatio::Wallet::ClientError]
111
+ # if error was raised on wallet API call ClientError is raised.
112
+ # if wallet API call was successful but we can't detect balance
113
+ # for address Error is raised.
114
+ def load_balance!
115
+ client.get_balance
116
+ rescue Peatio::Electrum::Client::Error => e
117
+ raise Peatio::Wallet::ClientError, e
118
+ end
119
+
120
+ end
121
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/object/blank'
4
+ require 'active_support/core_ext/enumerable'
5
+ require 'peatio'
6
+ require 'faraday'
7
+ require 'json'
8
+
9
+ module Peatio
10
+ module Electrum
11
+ Error = Class.new(StandardError)
12
+
13
+ require 'peatio/electrum/version'
14
+ require 'peatio/electrum/client'
15
+ require 'peatio/electrum/blockchain'
16
+ require 'peatio/electrum/wallet'
17
+ require 'peatio/electrum/hooks'
18
+ end
19
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "peatio/electrum/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "ouroboros-peatio-electrum"
9
+ spec.version = Peatio::Electrum::VERSION
10
+ spec.authors = ["Camille Meulien"]
11
+ spec.email = ["cmeulien@heliostech.fr"]
12
+
13
+ spec.summary = "Peatio Plugin for Electrum server"
14
+ spec.description = "Peatio Plugin for Electrum server"
15
+ spec.homepage = "https://www.openware.com"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = "https://github.com/openware/peatio-contrib"
22
+ spec.metadata["changelog_uri"] = "https://github.com/openware/peatio-contrib/blob/master/CHANGELOG.md"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
31
+ `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_dependency "activesupport", "~> 6.1.0"
38
+ spec.add_dependency "faraday", "~> 1.10"
39
+
40
+ spec.add_dependency "peatio", ">= 3.1.1"
41
+ spec.add_dependency 'net-http-persistent', "~> 4.0.1"
42
+
43
+ spec.add_development_dependency "bundler", "~> 2.4.7"
44
+ spec.add_development_dependency "byebug"
45
+ spec.add_development_dependency "irb"
46
+ spec.add_development_dependency "rspec", "~> 3.0"
47
+ spec.add_development_dependency "webmock", "~> 3.5"
48
+ spec.add_development_dependency "simplecov"
49
+ end
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ouroboros-peatio-electrum
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Camille Meulien
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-08-17 00:00:00.000000000 Z
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: 6.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 6.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: peatio
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.1
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: 4.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: 4.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.4.7
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.4.7
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: irb
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.5'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.5'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Peatio Plugin for Electrum server
154
+ email:
155
+ - cmeulien@heliostech.fr
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".rspec"
161
+ - Gemfile
162
+ - Gemfile.lock
163
+ - README.md
164
+ - Rakefile
165
+ - bin/peatio-electrum-console
166
+ - bin/peatio-electrum-setup
167
+ - lib/peatio/electrum.rb
168
+ - lib/peatio/electrum/blockchain.rb
169
+ - lib/peatio/electrum/client.rb
170
+ - lib/peatio/electrum/hooks.rb
171
+ - lib/peatio/electrum/railtie.rb
172
+ - lib/peatio/electrum/version.rb
173
+ - lib/peatio/electrum/wallet.rb
174
+ - ouroboros-peatio-electrum.gemspec
175
+ homepage: https://www.openware.com
176
+ licenses: []
177
+ metadata:
178
+ homepage_uri: https://www.openware.com
179
+ source_code_uri: https://github.com/openware/peatio-contrib
180
+ changelog_uri: https://github.com/openware/peatio-contrib/blob/master/CHANGELOG.md
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubygems_version: 3.1.6
197
+ signing_key:
198
+ specification_version: 4
199
+ summary: Peatio Plugin for Electrum server
200
+ test_files: []