Class: Peatio::Electrum::Blockchain

Inherits:
Blockchain::Abstract
  • Object
show all
Defined in:
lib/peatio/electrum/blockchain.rb

Overview

Constant Summary collapse

DEFAULT_FEATURES =
{case_sensitive: true}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(custom_features = {}) ⇒ Blockchain

You could override default features by passing them to initializer.



12
13
14
# File 'lib/peatio/electrum/blockchain.rb', line 12

def initialize(custom_features = {})
  @features = DEFAULT_FEATURES.merge(custom_features)
end

Instance Method Details

#configure(settings = {}) ⇒ Hash

Note:

Be careful with your blockchain state after configure. Clean everything what could be related to other blockchain configuration. E.g. client state.

Merges given configuration parameters with defined during initialization and returns the result.

Parameters:

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

    parameters to use.

Options Hash (settings):

  • :server (String)

    Public blockchain API endpoint.

  • :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.



31
32
33
# File 'lib/peatio/electrum/blockchain.rb', line 31

def configure(settings = {})
  @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))
end

#fetch_block!(block_number) ⇒ Peatio::Block

Fetches blockchain block by calling API and builds block object from response payload.

Parameters:

  • block_number (Integer)

    the block number.

Returns:

  • (Peatio::Block)

    the block object.

Raises:

  • (Peatio::Blockchain::ClientError)

    if error was raised on blockchain API call.



42
43
44
# File 'lib/peatio/electrum/blockchain.rb', line 42

def fetch_block!(block_number)
  method_not_implemented
end

#latest_block_numberInteger

Fetches current blockchain height by calling API and returns it as number.

Returns:

  • (Integer)

    the current blockchain height.

Raises:

  • (Peatio::Blockchain::ClientError)

    if error was raised on blockchain API call.



51
52
53
# File 'lib/peatio/electrum/blockchain.rb', line 51

def latest_block_number
  method_not_implemented
end

#load_balance_of_address!(address, currency_id) ⇒ 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 blockchain API call ClientError is raised. if blockchain API call was successful but we can’t detect balance for address Error is raised.

Parameters:

  • address (String)

    the address for requesting balance.

  • currency_id (String)

    which currency balance we need to request.

Returns:

  • (BigDecimal)

    the current address balance.

Raises:

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


67
68
69
# File 'lib/peatio/electrum/blockchain.rb', line 67

def load_balance_of_address!(address, currency_id)
  raise Peatio::Blockchain::UnavailableAddressBalanceError
end