diff --git a/bitcoin/src/blockdata/script/builder.rs b/bitcoin/src/blockdata/script/builder.rs index 855d04c61..ec842f7c9 100644 --- a/bitcoin/src/blockdata/script/builder.rs +++ b/bitcoin/src/blockdata/script/builder.rs @@ -21,6 +21,10 @@ impl Builder { #[inline] pub const fn new() -> Self { Builder(ScriptBuf::new(), None) } + /// Constructs a new empty script builder with at least the specified capacity. + #[inline] + pub fn with_capacity(capacity: usize) -> Self { Builder(ScriptBuf::with_capacity(capacity), None) } + /// Returns the length in bytes of the script. pub fn len(&self) -> usize { self.0.len() } diff --git a/bitcoin/src/blockdata/script/tests.rs b/bitcoin/src/blockdata/script/tests.rs index 51d24b25b..8fae24288 100644 --- a/bitcoin/src/blockdata/script/tests.rs +++ b/bitcoin/src/blockdata/script/tests.rs @@ -209,6 +209,13 @@ fn script_builder() { ); } +#[test] +fn script_builder_with_capacity() { + let script = Builder::with_capacity(42); + + assert!(script.into_script().capacity() >= 42); +} + #[test] fn script_generators() { let pubkey = "0234e6a79c5359c613762d537e0e19d86c77c1666d8c9ab050f23acd198e97f93e"