Class: Peatio::Electrum::Wallet
- Inherits:
-
Wallet::Abstract
- Object
- Wallet::Abstract
- Peatio::Electrum::Wallet
- Defined in:
- lib/peatio/electrum/wallet.rb
Overview
See the abstract class here: github.com/openware/peatio-core/blob/master/lib/peatio/wallet/abstract.rb
Constant Summary collapse
- DEFAULT_FEATURES =
{ skip_deposit_collection: false }.freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#configure(settings = {}) ⇒ Hash
Merges given configuration parameters with defined during initialization and returns the result.
-
#create_address!(_options = {}) ⇒ Hash
Performs API call for address creation and returns it.
-
#create_transaction!(transaction, _options = {}) ⇒ Peatio::Transaction
Performs API call for creating transaction and returns updated transaction.
-
#initialize(custom_features = {}) ⇒ Wallet
constructor
A new instance of Wallet.
-
#load_balance! ⇒ BigDecimal
Fetches address balance of specific currency.
Constructor Details
#initialize(custom_features = {}) ⇒ Wallet
Returns a new instance of Wallet.
13 14 15 16 |
# File 'lib/peatio/electrum/wallet.rb', line 13 def initialize(custom_features = {}) @features = DEFAULT_FEATURES.merge(custom_features).slice(*SUPPORTED_FEATURES) @settings = {} end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/peatio/electrum/wallet.rb', line 9 def client @client end |
Instance Method Details
#configure(settings = {}) ⇒ Hash
Be careful with your wallet state after configure. Clean everything what could be related to other wallet configuration. E.g. client state.
Merges given configuration parameters with defined during initialization and returns the result.
With :address required key other settings could be customized using Wallet#settings.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/peatio/electrum/wallet.rb', line 34 def configure(settings = {}) @settings.merge!(settings.slice(*SUPPORTED_SETTINGS)) @wallet = @settings.fetch(:wallet) do raise Peatio::Wallet::MissingSettingError, :wallet end.slice(:uri, :address, :secret) @currency = @settings.fetch(:currency) do raise Peatio::Wallet::MissingSettingError, :currency end.slice(:id, :base_factor, :options) unless @settings[:wallet][:uri] raise Peatio::Wallet::MissingSettingError, 'Missing uri in wallet' end @client = Client.new(@settings[:wallet][:uri]) end |
#create_address!(_options = {}) ⇒ Hash
Performs API call for address creation and returns it.
66 67 68 69 70 71 72 |
# File 'lib/peatio/electrum/wallet.rb', line 66 def create_address!( = {}) { address: client.create_address } rescue Peatio::Electrum::Client::Error => e raise Peatio::Wallet::ClientError, e end |
#create_transaction!(transaction, _options = {}) ⇒ Peatio::Transaction
Performs API call for creating transaction and returns updated transaction.
to_address, amount & currency_id.
94 95 96 97 98 99 100 101 |
# File 'lib/peatio/electrum/wallet.rb', line 94 def create_transaction!(transaction, = {}) tx = client.payto(transaction.to_address, transaction.amount, password: @settings[:wallet][:secret])['hex'] txid = client.broadcast(tx) transaction.hash = txid transaction rescue Peatio::Electrum::Client::Error => e raise Peatio::Wallet::ClientError, e end |
#load_balance! ⇒ BigDecimal
Optional. Don’t override this method if your blockchain
Fetches address balance of specific currency.
doesn’t provide functionality to get balance by address.
if error was raised on wallet API call ClientError is raised. if wallet API call was successful but we can’t detect balance for address Error is raised.
114 115 116 117 118 |
# File 'lib/peatio/electrum/wallet.rb', line 114 def load_balance! client.get_balance rescue Peatio::Electrum::Client::Error => e raise Peatio::Wallet::ClientError, e end |