Skip to content

Commit

Permalink
Include the SPK length field weight in TXOUT_BASE_weight
Browse files Browse the repository at this point in the history
it's inconsistent to not include it and I confused myself.
  • Loading branch information
LLFourn authored and evanlinjin committed Aug 9, 2023
1 parent 4e51d18 commit 30c6469
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions nursery/coin_select/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ pub mod change_policy;
/// length.
pub const TXIN_BASE_WEIGHT: u32 = (32 + 4 + 4 + 1) * 4;

/// The weight of a TXOUT without the `scriptPubkey` (and script pubkey length field).
/// Just the weight of the value field.
pub const TXOUT_BASE_WEIGHT: u32 = 4 * core::mem::size_of::<u64>() as u32; // just the value

/// The weight of a TXOUT with a zero length `scriptPubkey`
pub const TXOUT_BASE_WEIGHT: u32 =
// The value
4 * core::mem::size_of::<u64>() as u32
// The spk length
+ (4 * 1);

/// The additional weight over [`TXIN_BASE_WEIGHT`] incurred by satisfying an input with a keyspend
/// and the default sighash.
pub const TR_KEYSPEND_SATISFACTION_WEIGHT: u32 = 66;

/// The weight of a taproot script pubkey
/// The additional weight of an output with segwit `v1` (taproot) script pubkey over a blank output (i.e. with weight [`TXOUT_BASE_WEIGHT`]).
pub const TR_SPK_WEIGHT: u32 = (1 + 1 + 32) * 4; // version + push + key

/// Helper to calculate varint size. `v` is the value the varint represents.
Expand Down

0 comments on commit 30c6469

Please sign in to comment.