Move builder script functions to primitives
What changed, and why it matters
This commit is a routine internal code reorganization. It moves two helper functions that create a 'script builder' from one module to another within the same project. The functions themselves are unchanged, and there is no indication this affects security.
No security action required. Review as normal code-quality/API refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch relocates ScriptExt::builder() and ScriptBufExt::builder() from the bitcoin::blockdata::script extension traits into inherent impl blocks on Script<T> and ScriptBuf<T> in the primitives::script module. The implementation body remains identical (Builder::new()). This is a pure refactor to reflect the prior move of the Builder type into primitives.
Changed components
bitcoin/src/blockdata/script/borrowed.rsbitcoin/src/blockdata/script/owned.rsprimitives/src/script/borrowed.rsprimitives/src/script/owned.rsInspect captured patch +11 / −10
diff --git a/bitcoin/src/blockdata/script/borrowed.rs b/bitcoin/src/blockdata/script/borrowed.rs
index 71516d14..aeca24a3 100644
--- a/bitcoin/src/blockdata/script/borrowed.rs
+++ b/bitcoin/src/blockdata/script/borrowed.rs
@@ -6,9 +6,9 @@ use internals::array::ArrayExt; // For `split_first`.
use super::witness_version::WitnessVersion;
use super::{
- Builder, Instruction, InstructionIndices, Instructions, PushBytes, RedeemScript,
- RedeemScriptSizeError, Script, ScriptHashableTag, ScriptPubKey, ScriptSig, TapScript,
- WitnessScript, WitnessScriptSizeError,
+ Instruction, InstructionIndices, Instructions, PushBytes, RedeemScript, RedeemScriptSizeError,
+ Script, ScriptHashableTag, ScriptPubKey, ScriptSig, TapScript, WitnessScript,
+ WitnessScriptSizeError,
};
use crate::encoding::{Encode, ExactSizeEncoder};
use crate::key::{LegacyPublicKey, UntweakedPublicKey, WPubkeyHash};
@@ -23,9 +23,6 @@ use crate::{internal_macros, Amount, FeeRate, ScriptPubKeyBuf, ToU64 as _, Witne
internal_macros::define_extension_trait! {
/// Extension functionality for the [`Script`] type.
pub trait ScriptExt<T> impl<T> for Script<T> {
- /// Constructs a new script builder
- fn builder() -> Builder<T> { Builder::new() }
-
/// Counts the sigops for this Script using accurate counting.
///
/// In Bitcoin Core, there are two ways to count sigops, "accurate" and "legacy".
diff --git a/bitcoin/src/blockdata/script/owned.rs b/bitcoin/src/blockdata/script/owned.rs
index 5706fe57..a40b0331 100644
--- a/bitcoin/src/blockdata/script/owned.rs
+++ b/bitcoin/src/blockdata/script/owned.rs
@@ -22,9 +22,6 @@ pub use addresses::ScriptPubKeyBufExt;
internal_macros::define_extension_trait! {
/// Extension functionality for the [`ScriptBuf`] type.
pub trait ScriptBufExt<T> impl<T> for ScriptBuf<T> {
- /// Constructs a new script builder
- fn builder() -> Builder<T> { Builder::new() }
-
/// Adds instructions to push an integer onto the stack.
///
/// Integers are encoded as little-endian signed-magnitude numbers, but there are dedicated
diff --git a/primitives/src/script/borrowed.rs b/primitives/src/script/borrowed.rs
index 9bb94fc2..e2f11d31 100644
--- a/primitives/src/script/borrowed.rs
+++ b/primitives/src/script/borrowed.rs
@@ -17,7 +17,8 @@ use crate::opcodes::all::{OP_CHECKSIG, OP_DUP, OP_EQUAL, OP_EQUALVERIFY, OP_HASH
use crate::opcodes::{Opcode, OP_PUSHBYTES_2, OP_PUSHBYTES_20, OP_PUSHBYTES_32};
use crate::prelude::{Box, ToOwned, Vec};
use crate::script::{
- RedeemScriptSizeError, ScriptHash, ScriptHashableTag, WScriptHash, WitnessScriptSizeError,
+ Builder, RedeemScriptSizeError, ScriptHash, ScriptHashableTag, WScriptHash,
+ WitnessScriptSizeError,
};
use crate::witness_version::WitnessVersion;
use crate::{ScriptPubKey, WitnessScript};
@@ -189,6 +190,9 @@ impl<T> Script<T> {
#[deprecated(since = "1.0.0-rc.0", note = "use `format!(\"{var:x}\")` instead")]
pub fn to_hex(&self) -> alloc::string::String { alloc::format!("{:x}", self) }
+ /// Constructs a new script builder
+ pub fn builder() -> Builder<T> { Builder::new() }
+
/// Returns witness version of the script, if any.
///
/// # Returns
diff --git a/primitives/src/script/owned.rs b/primitives/src/script/owned.rs
index e0ff74a2..32f2fe36 100644
--- a/primitives/src/script/owned.rs
+++ b/primitives/src/script/owned.rs
@@ -166,6 +166,9 @@ impl<T> ScriptBuf<T> {
#[deprecated(since = "1.0.0-rc.0", note = "use `format!(\"{var:x}\")` instead")]
pub fn to_hex(&self) -> alloc::string::String { alloc::format!("{:x}", self) }
+ /// Constructs a new script builder
+ pub fn builder() -> Builder<T> { Builder::new() }
+
/// Adds a single opcode to the script.
pub fn push_opcode(&mut self, data: Opcode) { self.as_byte_vec().push(data.to_u8()); }
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.