Class BSV::Wallet::FeeEstimator ¶
Inherits: Object
Estimates transaction fees before a {BSV::Transaction::Transaction} object exists.
Wraps {BSV::Transaction::FeeModels::SatoshisPerKilobyte} to provide pre-construction fee estimation given only input and output counts. Once a real {Transaction} is available, delegates directly to the underlying SDK fee model via {#estimate_for_tx}.
The default rate is 100 sat/kB, matching the ARC mining policy endpoint and the SDK's own {SatoshisPerKilobyte} default.
@example Pre-construction estimate
estimator = BSV::Wallet::FeeEstimator.new
fee = estimator.estimate(p2pkh_inputs: 2, p2pkh_outputs: 3)
# => 41 (at 100 sat/kB, ceil(408/1000 * 100) = 41)
@example Custom rate
estimator = BSV::Wallet::FeeEstimator.new(sats_per_kb: 50)
fee = estimator.estimate(p2pkh_inputs: 1, p2pkh_outputs: 1)
# => 10 (ceil(192/1000 * 50) = 10)
Constants¶
DEFAULT_SATS_PER_KB ¶
Default fee rate in satoshis per kilobyte, matching ARC's mining policy endpoint (/v1/policy → miningFee 100/1000).
EF_INPUT_OVERHEAD ¶
Extended Format (BRC-30/EF) adds source_satoshis (8 bytes) + varint(25) (1 byte) + P2PKH locking script (25 bytes) = 34 bytes per input. ARC validates fees against the EF size, not raw.
EF_VERSION_OVERHEAD ¶
EF version marker: 6 bytes (x00x00x00x00x00xEF) follows the 4-byte version field, adding 6 bytes of fixed overhead.
FIXED_OVERHEAD ¶
Fixed overhead in bytes for version (4) + EF marker (6) + lock_time (4).
OVERHEAD ¶
Approximate overhead including typical 1-byte varints for input/output counts. Retained for backward compatibility with code that referenced FeeModel::OVERHEAD.
P2PKH_INPUT_SIZE ¶
Total estimated input size including EF overhead. This is the size ARC sees and charges fees against.
P2PKH_OUTPUT_SIZE ¶
Estimated size in bytes of a P2PKH output (8 satoshis + varint(25) + 25-byte script).
P2PKH_RAW_INPUT_SIZE ¶
Estimated size in bytes of an unsigned P2PKH input in raw format.
Attributes¶
sats_per_kb [R] ¶
- @return [Integer] the satoshis-per-kilobyte rate used for estimation
Public Instance Methods¶
dust_floor() ¶
Minimum viable change output value at the configured rate.
An output is economically viable only if its value exceeds twice the cost of spending it. The cost to spend a single P2PKH input is estimated as the fee for a minimal 1-input / 1-output transaction. - @return [Integer] minimum satoshis for a change output to be worth creating
estimate(p2pkh_inputs:, p2pkh_outputs:, extra_bytes: = 0) ¶
Estimate the fee for a transaction described by input and output counts.
Computes the serialised byte size using standard P2PKH sizes and correct Bitcoin varint encoding for the input/output count fields, then applies the configured sat/kB rate. Returns at least 1 satoshi. - @param p2pkh_inputs [Integer] number of P2PKH inputs - @param p2pkh_outputs [Integer] number of P2PKH outputs - @param extra_bytes [Integer] additional bytes to include (e.g. OP_RETURN data) - @return [Integer] estimated fee in satoshis (minimum 1)
estimate_for_tx(tx) ¶
Compute the fee for a fully-constructed transaction.
Delegates to the underlying {BSV::Transaction::FeeModels::SatoshisPerKilobyte} model, which uses {BSV::Transaction::Transaction#estimated_size} internally. - @param tx [BSV::Transaction::Transaction] the transaction to compute the fee for - @return [Integer] fee in satoshis
initialize(sats_per_kb: = DEFAULT_SATS_PER_KB) ¶
- @param
sats_per_kb[Integer] fee rate in satoshis per kilobyte - @raise [ArgumentError] if sats_per_kb is zero or negative
- @return [FeeEstimator] a new instance of FeeEstimator