Move push_int_non_minimal to BuilderExtPriv
What changed, and why it matters
This commit is a routine internal code reorganization. It moves a helper function for building Bitcoin scripts from a public-ish location on the Builder type into a private extension trait only visible inside one module. There is no security bug being fixed here; the change is about keeping an internal implementation detail from accidentally becoming part of the public API.
No security action required. Reviewers may verify that `BuilderExtPriv` is not exported publicly and that `push_int_non_minimal` remains accessible where needed inside blockdata.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch moves push_int_non_minimal from Builder<T> to a new sealed, crate-private extension trait BuilderExtPriv (visible only in crate::blockdata). The function itself is unchanged: it still pushes an integer onto the script using the non-minimal explicit encoding. The change only affects visibility and API surface, not behavior.
Changed components
bitcoin/src/blockdata/script/builder.rsbitcoin/src/blockdata/script/mod.rsbitcoin/src/blockdata/constants.rsInspect captured patch +22 / −10
diff --git a/bitcoin/src/blockdata/constants.rs b/bitcoin/src/blockdata/constants.rs
index e7458f8b..2f1053e5 100644
--- a/bitcoin/src/blockdata/constants.rs
+++ b/bitcoin/src/blockdata/constants.rs
@@ -12,9 +12,10 @@ use crate::locktime::absolute;
use crate::network::{Network, Params};
use crate::opcodes::all::*;
use crate::pow::CompactTarget;
+use crate::script::{self, BuilderExtPriv as _};
use crate::transaction::{self, OutPoint, Transaction, TxIn, TxOut};
use crate::witness::Witness;
-use crate::{script, Amount, BlockHash, BlockTime, Sequence, TestnetVersion};
+use crate::{Amount, BlockHash, BlockTime, Sequence, TestnetVersion};
/// How many seconds between blocks we expect on average.
pub const TARGET_BLOCK_SPACING: u32 = 600;
diff --git a/bitcoin/src/blockdata/script/builder.rs b/bitcoin/src/blockdata/script/builder.rs
index ace9d278..7a9f37f1 100644
--- a/bitcoin/src/blockdata/script/builder.rs
+++ b/bitcoin/src/blockdata/script/builder.rs
@@ -70,15 +70,6 @@ impl<T> Builder<T> {
Self::from(script.into_bytes())
}
- /// Adds instructions to push an integer onto the stack without optimization.
- ///
- /// This uses the explicit encoding regardless of the availability of dedicated opcodes.
- pub(in crate::blockdata) fn push_int_non_minimal(self, data: i64) -> Self {
- let mut script = self.into_script();
- script.push_int_non_minimal(data);
- Self::from(script.into_bytes())
- }
-
/// Adds instructions to push some arbitrary data onto the stack.
///
/// If the data can be exactly produced by a numeric opcode, that opcode
@@ -190,6 +181,25 @@ impl<T> Builder<T> {
pub fn as_bytes(&self) -> &[u8] { self.as_script().as_bytes() }
}
+mod sealed {
+ pub trait Sealed {}
+ impl<T> Sealed for super::Builder<T> {}
+}
+
+crate::internal_macros::define_extension_trait! {
+ /// Extension functionality for [`Builder`] that should be private.
+ pub(in crate::blockdata) trait BuilderExtPriv<T> impl<T> for Builder<T> {
+ /// Adds instructions to push an integer onto the stack without optimization.
+ ///
+ /// This uses the explicit encoding regardless of the availability of dedicated opcodes.
+ fn push_int_non_minimal(self, data: i64) -> Self {
+ let mut script = self.into_script();
+ script.push_int_non_minimal(data);
+ Self::from(script.into_bytes())
+ }
+ }
+}
+
impl<T> Default for Builder<T> {
fn default() -> Self { Self::new() }
}
diff --git a/bitcoin/src/blockdata/script/mod.rs b/bitcoin/src/blockdata/script/mod.rs
index 10bc098a..b04488d4 100644
--- a/bitcoin/src/blockdata/script/mod.rs
+++ b/bitcoin/src/blockdata/script/mod.rs
@@ -85,6 +85,7 @@ pub use primitives::script::{
};
pub(crate) use self::borrowed::ScriptExtPriv;
+pub(in crate::blockdata) use self::builder::BuilderExtPriv;
#[doc(no_inline)]
pub use self::error::{
Error, PushBytesError, RedeemScriptSizeError, ScriptIntError, WitnessScriptSizeError,
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.