Class: BSV::Wallet::WhatsOnChainProvider
- Inherits:
-
Object
- Object
- BSV::Wallet::WhatsOnChainProvider
- Includes:
- ChainProvider
- Defined in:
- lib/bsv/wallet_interface/whats_on_chain_provider.rb
Overview
ChainProvider implementation backed by the WhatsOnChain public API.
Delegates to Network::WhatsOnChain for all HTTP communication, adapting its responses to the ChainProvider contract.
Instance Method Summary collapse
-
#get_header(_height) ⇒ String
Returns the block header at the given height.
-
#get_height ⇒ Integer
Returns the current blockchain height.
-
#get_transaction(txid) ⇒ String
Returns the raw transaction hex for the given txid.
-
#get_utxos(address) ⇒ Array<Hash>
Returns unspent transaction outputs for the given address.
-
#initialize(network: :main, http_client: nil) ⇒ WhatsOnChainProvider
constructor
A new instance of WhatsOnChainProvider.
Constructor Details
#initialize(network: :main, http_client: nil) ⇒ WhatsOnChainProvider
Returns a new instance of WhatsOnChainProvider.
19 20 21 22 |
# File 'lib/bsv/wallet_interface/whats_on_chain_provider.rb', line 19 def initialize(network: :main, http_client: nil) woc_network = network == :main ? :mainnet : :testnet @woc = BSV::Network::WhatsOnChain.new(network: woc_network, http_client: http_client) end |
Instance Method Details
#get_header(_height) ⇒ String
Returns the block header at the given height.
33 34 35 |
# File 'lib/bsv/wallet_interface/whats_on_chain_provider.rb', line 33 def get_header(_height) raise NotImplementedError, 'WhatsOnChainProvider#get_header not yet implemented' end |
#get_height ⇒ Integer
Returns the current blockchain height.
26 27 28 |
# File 'lib/bsv/wallet_interface/whats_on_chain_provider.rb', line 26 def get_height raise NotImplementedError, 'WhatsOnChainProvider#get_height not yet implemented' end |
#get_transaction(txid) ⇒ String
Returns the raw transaction hex for the given txid.
Delegates to Network::WhatsOnChain#fetch_transaction and serialises the result back to hex.
57 58 59 |
# File 'lib/bsv/wallet_interface/whats_on_chain_provider.rb', line 57 def get_transaction(txid) @woc.fetch_transaction(txid).to_hex end |
#get_utxos(address) ⇒ Array<Hash>
Returns unspent transaction outputs for the given address.
Delegates to Network::WhatsOnChain#fetch_utxos and normalises the result to plain hashes matching the ChainProvider contract.
44 45 46 47 48 |
# File 'lib/bsv/wallet_interface/whats_on_chain_provider.rb', line 44 def get_utxos(address) @woc.fetch_utxos(address).map do |utxo| { tx_hash: utxo.tx_hash, tx_pos: utxo.tx_pos, value: utxo.satoshis } end end |