Skip to content

plan: add some clarifying docs #824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ impl Plan {
/// the script sig weight and the witness weight)
pub fn satisfaction_weight(&self) -> usize { self.witness_size() + self.scriptsig_size() * 4 }

/// The size in bytes of the script sig that satisfies this plan
/// The size in bytes of the script sig that satisfies this plan, including the size of the
/// var-int prefix.
pub fn scriptsig_size(&self) -> usize {
match (self.descriptor.desc_type().segwit_version(), self.descriptor.desc_type()) {
// Entire witness goes in the script_sig
Expand All @@ -264,13 +265,15 @@ impl Plan {
}
}

/// The size in bytes of the witness that satisfies this plan
/// The size in bytes of the witness that satisfies this plan.
///
/// NOTE: Returns 0 if there is no witness. You need to manually take care to count it as 1 byte
/// if there's at least one segwit input in the tx. See ["Empty script witnesses are encoded as a zero byte"](https://github.com/bitcoin/bips/blob/d8a56c9f2b521bf4af5d588f217e7618cc44952c/bip-0144.mediawiki#serialization).
pub fn witness_size(&self) -> usize {
if self.descriptor.desc_type().segwit_version().is_some() {
witness_size(self.template.as_ref())
} else {
0 // should be 1 if there's at least one segwit input in the tx, but that's out of
// scope as we can't possibly know that just by looking at the descriptor
0
}
}

Expand Down
Loading