Module: BSV::Wallet::ChainProvider

Included in:
NullChainProvider, WhatsOnChainProvider
Defined in:
lib/bsv/wallet_interface/chain_provider.rb

Overview

Duck-typed interface for blockchain data providers.

Include this module in chain provider adapters and override all methods. The default implementations raise NotImplementedError.

Examples:

Custom provider

class MyChainProvider
  include BSV::Wallet::ChainProvider

  def get_height
    # query your node/API
  end

  def get_header(height)
    # return 80-byte hex block header
  end
end

Instance Method Summary collapse

Instance Method Details

#get_header(_height) ⇒ String

Returns the block header at the given height.

Parameters:

  • _height (Integer)

    block height

Returns:

  • (String)

    80-byte hex-encoded block header

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/bsv/wallet_interface/chain_provider.rb', line 32

def get_header(_height)
  raise NotImplementedError, "#{self.class}#get_header not implemented"
end

#get_heightInteger

Returns the current blockchain height.

Returns:

  • (Integer)

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/bsv/wallet_interface/chain_provider.rb', line 25

def get_height
  raise NotImplementedError, "#{self.class}#get_height not implemented"
end

#get_transaction(_txid) ⇒ String

Returns the raw transaction hex for the given txid.

Parameters:

  • _txid (String)

    transaction ID (hex)

Returns:

  • (String)

    raw transaction hex string

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/bsv/wallet_interface/chain_provider.rb', line 46

def get_transaction(_txid)
  raise NotImplementedError, "#{self.class}#get_transaction not implemented"
end

#get_utxos(_address) ⇒ Array<Hash>

Returns unspent transaction outputs for the given address.

Parameters:

  • _address (String)

    BSV address

Returns:

  • (Array<Hash>)

    array of hashes with :tx_hash, :tx_pos, :value keys

Raises:

  • (NotImplementedError)


39
40
41
# File 'lib/bsv/wallet_interface/chain_provider.rb', line 39

def get_utxos(_address)
  raise NotImplementedError, "#{self.class}#get_utxos not implemented"
end