Class: Peatio::Electrum::Wallet

Inherits:
Wallet::Abstract
  • Object
show all
Defined in:
lib/peatio/electrum/wallet.rb

Overview

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Wallet

Returns a new instance of Wallet.



10
11
12
# File 'lib/peatio/electrum/wallet.rb', line 10

def initialize(settings = {})
  @settings = settings
end

Instance Method Details

#configure(settings = {}) ⇒ Hash

Note:

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.

Parameters:

  • settings (Hash) (defaults to: {})

    configurations to use.

Options Hash (settings):

  • :wallet (Hash)

    Wallet settings for performing API calls.

  • :currencies (Array<Hash>)

    List of currency hashes with :id,:base_factor,:options(deprecated) keys. Custom keys could be added by defining them in Currency #options.

Returns:

  • (Hash)

    merged settings.



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/peatio/electrum/wallet.rb', line 30

def configure(settings = {})
  # Clean client state during configure.
  @client = nil
  @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)
end

#create_address!(options = {}) ⇒ Hash

Performs API call for address creation and returns it.

Examples:

{ address: :fake_address,
  secret:  :changeme,
  details: { uid: .member.uid } }

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (Hash)

    newly created blockchain address.

Raises:

  • (Peatio::Blockchain::ClientError)

    if error was raised on wallet API call.



58
59
60
# File 'lib/peatio/electrum/wallet.rb', line 58

def create_address!(options = {})
  method_not_implemented
end

#create_transaction!(transaction, options = {}) ⇒ Peatio::Transaction

Performs API call for creating transaction and returns updated transaction.

to_address, amount & currency_id.

Parameters:

  • transaction (Peatio::Transaction)

    transaction with defined

  • options (Hash) (defaults to: {})

Returns:

  • (Peatio::Transaction)

    transaction with updated hash.

Raises:

  • (Peatio::Blockchain::ClientError)

    if error was raised on wallet API call.



82
83
84
# File 'lib/peatio/electrum/wallet.rb', line 82

def create_transaction!(transaction, options = {})
  method_not_implemented
end

#load_balance!BigDecimal

Note:

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.

Returns:

  • (BigDecimal)

    the current address balance.

Raises:

  • (Peatio::Blockchain::ClientError, Peatio::Blockchain::UnavailableAddressBalanceError)


97
98
99
# File 'lib/peatio/electrum/wallet.rb', line 97

def load_balance!
  raise Peatio::Wallet::UnavailableAddressBalanceError
end

#prepare_deposit_collection!(deposit_transaction, spread_transactions, deposit_currency) ⇒ Array<Peatio::Transaction>

Note:

Optional. Override this method only if you need additional step

Performs API call(s) for preparing for deposit collection. E.g deposits ETH for collecting ERC20 tokens in case of Ethereum blockchain.

before deposit collection.

describes received deposit.

spread between wallets.

deposit collection preparing. By default return empty [Array]

Parameters:

  • deposit_transaction (Peatio::Transaction)

    transaction which

  • spread_transactions (Array<Peatio::Transaction>)

    result of deposit

Returns:

  • (Array<Peatio::Transaction>)

    transaction created for



116
117
118
119
120
# File 'lib/peatio/electrum/wallet.rb', line 116

def prepare_deposit_collection!(deposit_transaction, spread_transactions, deposit_currency)
  # This method is mostly used for coins which needs additional fees
  # to be deposited before deposit collection.
  []
end