Skip to content

Commit f023c39

Browse files
committed
Merge #824: plan: add some clarifying docs
e89e226 plan: add some clarifying docs (Marko Bencun) Pull request description: "The size in bytes of the script sig that" is ambiguous and could refer to the actual scriptSig, exlcuding the varint prefix that indicates its size. The code comment in witness_size is promoted to the docstring, as its helpful to anyone trying to compute the right size of a transaction. ACKs for top commit: apoelstra: ACK e89e226; successfully ran local tests; nice, good call Tree-SHA512: 3798d921ddc477965023e6275178c42ff8b37ab03f593dd65078a4d57e7c922659a74db57f5858cc69931781e1ceff3a45d6c7b263b8220d04b594db180229ec
2 parents 1c4e959 + e89e226 commit f023c39

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/plan.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ impl Plan {
248248
/// the script sig weight and the witness weight)
249249
pub fn satisfaction_weight(&self) -> usize { self.witness_size() + self.scriptsig_size() * 4 }
250250

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

267-
/// The size in bytes of the witness that satisfies this plan
268+
/// The size in bytes of the witness that satisfies this plan.
269+
///
270+
/// NOTE: Returns 0 if there is no witness. You need to manually take care to count it as 1 byte
271+
/// 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).
268272
pub fn witness_size(&self) -> usize {
269273
if self.descriptor.desc_type().segwit_version().is_some() {
270274
witness_size(self.template.as_ref())
271275
} else {
272-
0 // should be 1 if there's at least one segwit input in the tx, but that's out of
273-
// scope as we can't possibly know that just by looking at the descriptor
276+
0
274277
}
275278
}
276279

0 commit comments

Comments
 (0)