signet_types/
confirmation.rs1use crate::TxLocation;
4use alloy::primitives::{BlockNumber, B256};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22pub struct ConfirmationMeta {
23 block_number: BlockNumber,
25 block_hash: B256,
27 transaction_index: u64,
29}
30
31impl ConfirmationMeta {
32 pub const fn new(block_number: BlockNumber, block_hash: B256, transaction_index: u64) -> Self {
34 Self { block_number, block_hash, transaction_index }
35 }
36
37 pub const fn block_number(&self) -> BlockNumber {
39 self.block_number
40 }
41
42 pub const fn block_hash(&self) -> B256 {
44 self.block_hash
45 }
46
47 pub const fn transaction_index(&self) -> u64 {
49 self.transaction_index
50 }
51}
52
53impl From<(TxLocation, B256)> for ConfirmationMeta {
54 fn from((loc, block_hash): (TxLocation, B256)) -> Self {
55 Self::new(loc.block, block_hash, loc.index)
56 }
57}
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn test_confirmation_meta_new() {
65 let meta = ConfirmationMeta::new(100, B256::ZERO, 5);
66 assert_eq!(meta.block_number(), 100);
67 assert_eq!(meta.block_hash(), B256::ZERO);
68 assert_eq!(meta.transaction_index(), 5);
69 }
70
71 #[test]
72 fn test_from_tx_location() {
73 let loc = TxLocation { block: 42, index: 3 };
74 let hash = B256::repeat_byte(0xAB);
75 let meta = ConfirmationMeta::from((loc, hash));
76 assert_eq!(meta.block_number(), 42);
77 assert_eq!(meta.block_hash(), hash);
78 assert_eq!(meta.transaction_index(), 3);
79 }
80}