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
SUPPORTED_FEATURES =
Note:

Features list:

skip_deposit_collection - defines if deposit will be collected to hot, warm, cold wallets.

List of features supported by peatio.

%i[skip_deposit_collection].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)


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

def initialize(*)
  abstract_method
end

Instance Attribute Details

#featuresHash (readonly)

This method is abstract.

Hash of features supported by wallet.

Returns:

  • (Hash)

    list of features supported by wallet.

See Also:



47
48
49
# File 'lib/peatio/wallet/abstract.rb', line 47

def features
  @features
end

#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.
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.



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

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:



116
117
118
# File 'lib/peatio/wallet/abstract.rb', line 116

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:



142
143
144
# File 'lib/peatio/wallet/abstract.rb', line 142

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:



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

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:



176
177
178
179
180
# File 'lib/peatio/wallet/abstract.rb', line 176

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