Class: Peatio::Wallet::Abstract Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/peatio/wallet/abstract.rb

Overview

This class is abstract.

Represents basic wallet interface.

Subclass and override abstract methods to implement a peatio plugable wallet. Than you need to register your wallet implementation.

Examples:


class MyWallet < Peatio::Abstract::Wallet
  def create_address(options = {})
    # do something
  end
  ...
end

# Register MyWallet as peatio plugable wallet.
Peatio::Wallet.registry[:my_wallet] = MyWallet.new

See Also:

  • Bitcoin as example of Abstract imlementation.

Author:

Constant Summary collapse

SUPPORTED_SETTINGS =

List of configurable settings.

See Also:

%i[wallet currency].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAbstract

This method is abstract.

Abstract constructor.

Examples:

class MyWallet< Peatio::Abstract::Wallet

  # You could customize your wallet by passing features.
  def initialize(my_custom_features = {})
    @features = my_custom_features
  end
  ...
end

# Register MyWallet as peatio plugable wallet.
custom_features = {cash_addr_format: true}
Peatio::Wallet.registry[:my_wallet] = MyWallet.new(custom_features)


57
58
59
# File 'lib/peatio/wallet/abstract.rb', line 57

def initialize(*)
  abstract_method
end

Instance Attribute Details

#settingsHash (readonly)

This method is abstract.

Current wallet settings for performing API calls.

Returns:

  • (Hash)

    current wallet settings.



32
33
34
# File 'lib/peatio/wallet/abstract.rb', line 32

def settings
  @settings
end

Instance Method Details

#configure(settings = {}) ⇒ Hash

This method is abstract.

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.



75
76
77
# File 'lib/peatio/wallet/abstract.rb', line 75

def configure(settings = {})
  abstract_method
end

#create_address!(options = {}) ⇒ Hash

This method is abstract.

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:



95
96
97
# File 'lib/peatio/wallet/abstract.rb', line 95

def create_address!(options = {})
  abstract_method
end

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

This method is abstract.

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:

Raises:



121
122
123
# File 'lib/peatio/wallet/abstract.rb', line 121

def create_transaction!(transaction, options = {})
  abstract_method
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:



136
137
138
# File 'lib/peatio/wallet/abstract.rb', line 136

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:

Returns:



155
156
157
158
159
# File 'lib/peatio/wallet/abstract.rb', line 155

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