Module: BSV::Wallet::Client::Network
- Included in:
- BSV::Wallet::Client
- Defined in:
- lib/bsv/wallet/client/brc100/network.rb
Overview
Blockchain and network data methods for BSV::Wallet::Client.
Instance Method Summary collapse
-
#get_header_for_height(args, originator: nil) ⇒ Hash
Returns the block header at the given height.
-
#get_height(args = {}, originator: nil) ⇒ Hash
Returns the current blockchain height.
-
#get_network(args = {}, originator: nil) ⇒ Hash
Returns the network this wallet is configured for.
-
#get_version(args = {}, originator: nil) ⇒ Hash
Returns the wallet version string.
Instance Method Details
#get_header_for_height(args, originator: nil) ⇒ Hash
Returns the block header at the given height.
Delegates to the substrate when configured; falls back to the local chain data source otherwise.
Note: BRC-100 specifies { header: String } (80-byte raw hex), but the local fallback returns the richer WoC JSON hash (containing hash, merkleroot, previousblockhash, time, nonce, bits, version, and height) under the header key. This is strictly more useful for local callers and avoids error-prone byte-order reassembly.
Warning: the WalletWire binary serialiser expects header to be a hex string. This local fallback should not be used behind a wire transport without first converting the JSON hash to raw 80-byte hex.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bsv/wallet/client/brc100/network.rb', line 41 def get_header_for_height(args, originator: nil) return @substrate.get_header_for_height(args, originator: originator) if @substrate raise UnsupportedActionError, 'get_header_for_height requires a chain_data_source or remote substrate' unless @chain_data_source height = args[:height] raise InvalidParameterError.new('height', 'a non-negative Integer') unless height.is_a?(Integer) && !height.negative? { header: @chain_data_source.get_block_header(height) } end |
#get_height(args = {}, originator: nil) ⇒ Hash
Returns the current blockchain height.
Delegates to the substrate when configured. Falls back to the local chain data source when present. Raises UnsupportedActionError when neither is available.
15 16 17 18 19 20 21 |
# File 'lib/bsv/wallet/client/brc100/network.rb', line 15 def get_height(args = {}, originator: nil) return @substrate.get_height(args, originator: originator) if @substrate raise UnsupportedActionError, 'get_height requires a chain_data_source or remote substrate' unless @chain_data_source { height: @chain_data_source.current_height } end |
#get_network(args = {}, originator: nil) ⇒ Hash
Returns the network this wallet is configured for.
55 56 57 58 59 |
# File 'lib/bsv/wallet/client/brc100/network.rb', line 55 def get_network(args = {}, originator: nil) return @substrate.get_network(args, originator: originator) if @substrate { network: @network } end |
#get_version(args = {}, originator: nil) ⇒ Hash
Returns the wallet version string.
64 65 66 67 68 |
# File 'lib/bsv/wallet/client/brc100/network.rb', line 64 def get_version(args = {}, originator: nil) return @substrate.get_version(args, originator: originator) if @substrate { version: "bsv-wallet-#{BSV::Wallet::VERSION}" } end |