primitives: Move is_coinbase into primitives
What changed, and why it matters
This commit is a routine internal code reorganization. It moves a helper method, is_coinbase, from one module to another within the same project. The method's logic and behavior are unchanged, and there is no indication of a security fix or vulnerability.
No security action needed. Treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change relocates the is_coinbase() implementation from the TransactionExt trait in bitcoin/src/blockdata/transaction.rs directly onto the Transaction struct in primitives/src/transaction.rs. The implementation remains identical: it returns true when the transaction has exactly one input whose previous output is OutPoint::COINBASE_PREVOUT. API snapshot files are updated to reflect the new public method location. No functional or security-relevant change is present.
Changed components
bitcoin/src/blockdata/transaction.rsprimitives/src/transaction.rsInspect captured patch +13 / −14
diff --git a/api/primitives/all-features.txt b/api/primitives/all-features.txt
index ef9ebd90..0ffdd551 100644
--- a/api/primitives/all-features.txt
+++ b/api/primitives/all-features.txt
@@ -1708,6 +1708,7 @@ pub fn bitcoin_primitives::transaction::Transaction::encoder(&self) -> Self::Enc
pub fn bitcoin_primitives::transaction::Transaction::eq(&self, other: &bitcoin_primitives::transaction::Transaction) -> bool
pub fn bitcoin_primitives::transaction::Transaction::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
pub fn bitcoin_primitives::transaction::Transaction::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
+pub fn bitcoin_primitives::transaction::Transaction::is_coinbase(&self) -> bool
pub fn bitcoin_primitives::transaction::Transaction::partial_cmp(&self, other: &Self) -> core::option::Option<core::cmp::Ordering>
pub fn bitcoin_primitives::transaction::TransactionDecoder::default() -> Self
pub fn bitcoin_primitives::transaction::TransactionDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
diff --git a/api/primitives/alloc-only.txt b/api/primitives/alloc-only.txt
index 3d8a81f2..dcddfe10 100644
--- a/api/primitives/alloc-only.txt
+++ b/api/primitives/alloc-only.txt
@@ -1508,6 +1508,7 @@ pub fn bitcoin_primitives::transaction::Transaction::encoder(&self) -> Self::Enc
pub fn bitcoin_primitives::transaction::Transaction::eq(&self, other: &bitcoin_primitives::transaction::Transaction) -> bool
pub fn bitcoin_primitives::transaction::Transaction::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
pub fn bitcoin_primitives::transaction::Transaction::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
+pub fn bitcoin_primitives::transaction::Transaction::is_coinbase(&self) -> bool
pub fn bitcoin_primitives::transaction::Transaction::partial_cmp(&self, other: &Self) -> core::option::Option<core::cmp::Ordering>
pub fn bitcoin_primitives::transaction::TransactionDecoder::default() -> Self
pub fn bitcoin_primitives::transaction::TransactionDecoder::end(self) -> core::result::Result<Self::Output, Self::Error>
diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs
index de043691..f779179d 100644
--- a/bitcoin/src/blockdata/transaction.rs
+++ b/bitcoin/src/blockdata/transaction.rs
@@ -318,15 +318,6 @@ pub trait TransactionExt: sealed::Sealed {
/// [`policy`]: crate::policy
fn vsize(&self) -> usize;
- /// Checks if this is a coinbase transaction.
- ///
- /// The first transaction in the block distributes the mining reward and is called the coinbase
- /// transaction. It is impossible to check if the transaction is first in the block, so this
- /// function checks the structure of the transaction instead - the previous output must be
- /// all-zeros (creates satoshis "out of thin air").
- #[doc(alias = "is_coin_base")] // method previously had this name
- fn is_coinbase(&self) -> bool;
-
/// Returns `true` if the transaction itself opted in to be BIP-0125-replaceable (RBF).
///
/// # Warning
@@ -436,11 +427,6 @@ impl TransactionExt for Transaction {
self.weight().to_vbytes_ceil() as usize
}
- #[doc(alias = "is_coin_base")] // method previously had this name
- fn is_coinbase(&self) -> bool {
- self.inputs.len() == 1 && self.inputs[0].previous_output == OutPoint::COINBASE_PREVOUT
- }
-
fn is_explicitly_rbf(&self) -> bool { self.inputs.iter().any(|input| input.sequence.is_rbf()) }
fn is_absolute_timelock_satisfied(&self, height: Height, time: MedianTimePast) -> bool {
diff --git a/primitives/src/transaction.rs b/primitives/src/transaction.rs
index 54fc4bf3..ffee0263 100644
--- a/primitives/src/transaction.rs
+++ b/primitives/src/transaction.rs
@@ -195,6 +195,17 @@ impl Transaction {
// `Transaction` docs for full explanation).
self.inputs.is_empty()
}
+
+ /// Checks if this is a coinbase transaction.
+ ///
+ /// The first transaction in the block distributes the mining reward and is called the coinbase
+ /// transaction. It is impossible to check if the transaction is first in the block, so this
+ /// function checks the structure of the transaction instead - the previous output must be
+ /// all-zeros (creates satoshis "out of thin air").
+ #[doc(alias = "is_coin_base")] // method previously had this name
+ pub fn is_coinbase(&self) -> bool {
+ self.inputs.len() == 1 && self.inputs[0].previous_output == OutPoint::COINBASE_PREVOUT
+ }
}
#[cfg(feature = "alloc")]
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.