Skip to content

Commit 6e01c6d

Browse files
feat(core): add is_all_zeros() and is_null() methods
Add convenience methods for identifying null outpoints and zero txids: - TxidExt::is_all_zeros() checks if a txid consists of all zero bytes - TxOutPointExt::is_null() identifies coinbase outpoints(index u32::MAX with all-zero txid)
1 parent 72d6174 commit 6e01c6d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/core/transaction.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,11 @@ pub trait TxOutPointExt: AsPtr<btck_TransactionOutPoint> {
553553
let ptr = unsafe { btck_transaction_out_point_get_txid(self.as_ptr()) };
554554
unsafe { TxidRef::from_ptr(ptr) }
555555
}
556+
557+
/// Returns true if this OutPoint is the "null" coinbase OutPoint.
558+
fn is_null(&self) -> bool {
559+
self.index() == u32::MAX && self.txid().is_all_zeros()
560+
}
556561
}
557562

558563
/// A reference to a specific output in a previous transaction.
@@ -655,6 +660,11 @@ pub trait TxidExt: AsPtr<btck_Txid> {
655660
}
656661
bytes
657662
}
663+
664+
/// Returns true if all bytes of the txid are zero (null txid).
665+
fn is_all_zeros(&self) -> bool {
666+
self.to_bytes().iter().all(|&b| b == 0)
667+
}
658668
}
659669

660670
pub struct Txid {

0 commit comments

Comments
 (0)