From cd2ce1c1e2bc05490fca7a1a87372e3d23f32155 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Sat, 8 Nov 2025 21:09:04 +0100 Subject: [PATCH] Rename pindex to entry --- src/notifications/validation.rs | 54 ++++++++++++++++----------------- src/state/context.rs | 32 +++++++++---------- tests/test.rs | 6 ++-- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/notifications/validation.rs b/src/notifications/validation.rs index 7e18a05d..6bc5c191 100644 --- a/src/notifications/validation.rs +++ b/src/notifications/validation.rs @@ -23,43 +23,43 @@ where /// Callback for when a new PoW valid block is found. pub trait NewPoWValidBlockCallback: Send + Sync { - fn on_new_pow_valid_block<'a>(&self, block: Block, pindex: BlockTreeEntry<'a>); + fn on_new_pow_valid_block<'a>(&self, block: Block, entry: BlockTreeEntry<'a>); } impl NewPoWValidBlockCallback for F where F: for<'a> Fn(BlockTreeEntry<'a>, Block) + Send + Sync + 'static, { - fn on_new_pow_valid_block<'a>(&self, block: Block, pindex: BlockTreeEntry<'a>) { - self(pindex, block) + fn on_new_pow_valid_block<'a>(&self, block: Block, entry: BlockTreeEntry<'a>) { + self(entry, block) } } /// Callback for when a block is connected to the chain. pub trait BlockConnectedCallback: Send + Sync { - fn on_block_connected<'a>(&self, block: Block, pindex: BlockTreeEntry<'a>); + fn on_block_connected<'a>(&self, block: Block, entry: BlockTreeEntry<'a>); } impl BlockConnectedCallback for F where F: for<'a> Fn(Block, BlockTreeEntry<'a>) + Send + Sync + 'static, { - fn on_block_connected<'a>(&self, block: Block, pindex: BlockTreeEntry<'a>) { - self(block, pindex) + fn on_block_connected<'a>(&self, block: Block, entry: BlockTreeEntry<'a>) { + self(block, entry) } } /// Callback for when a block is disconnected from the chain. pub trait BlockDisconnectedCallback: Send + Sync { - fn on_block_disconnected<'a>(&self, block: Block, pindex: BlockTreeEntry<'a>); + fn on_block_disconnected<'a>(&self, block: Block, entry: BlockTreeEntry<'a>); } impl BlockDisconnectedCallback for F where F: for<'a> Fn(Block, BlockTreeEntry<'a>) + Send + Sync + 'static, { - fn on_block_disconnected<'a>(&self, block: Block, pindex: BlockTreeEntry<'a>) { - self(block, pindex) + fn on_block_disconnected<'a>(&self, block: Block, entry: BlockTreeEntry<'a>) { + self(block, entry) } } @@ -134,7 +134,7 @@ pub(crate) unsafe extern "C" fn validation_block_checked_wrapper( pub(crate) unsafe extern "C" fn validation_new_pow_valid_block_wrapper( user_data: *mut c_void, block: *mut btck_Block, - pindex: *const btck_BlockTreeEntry, + entry: *const btck_BlockTreeEntry, ) { let block = Block::from_ptr(block); let registry = &*(user_data as *mut ValidationCallbackRegistry); @@ -142,7 +142,7 @@ pub(crate) unsafe extern "C" fn validation_new_pow_valid_block_wrapper( if let Some(ref handler) = registry.new_pow_valid_block_handler { handler.on_new_pow_valid_block( block, - BlockTreeEntry::from_ptr(pindex as *mut btck_BlockTreeEntry), + BlockTreeEntry::from_ptr(entry as *mut btck_BlockTreeEntry), ); } } @@ -150,7 +150,7 @@ pub(crate) unsafe extern "C" fn validation_new_pow_valid_block_wrapper( pub(crate) unsafe extern "C" fn validation_block_connected_wrapper( user_data: *mut c_void, block: *mut btck_Block, - pindex: *const btck_BlockTreeEntry, + entry: *const btck_BlockTreeEntry, ) { let block = Block::from_ptr(block); let registry = &*(user_data as *mut ValidationCallbackRegistry); @@ -158,7 +158,7 @@ pub(crate) unsafe extern "C" fn validation_block_connected_wrapper( if let Some(ref handler) = registry.block_connected_handler { handler.on_block_connected( block, - BlockTreeEntry::from_ptr(pindex as *mut btck_BlockTreeEntry), + BlockTreeEntry::from_ptr(entry as *mut btck_BlockTreeEntry), ); } } @@ -166,7 +166,7 @@ pub(crate) unsafe extern "C" fn validation_block_connected_wrapper( pub(crate) unsafe extern "C" fn validation_block_disconnected_wrapper( user_data: *mut c_void, block: *mut btck_Block, - pindex: *const btck_BlockTreeEntry, + entry: *const btck_BlockTreeEntry, ) { let block = Block::from_ptr(block); let registry = &*(user_data as *mut ValidationCallbackRegistry); @@ -174,7 +174,7 @@ pub(crate) unsafe extern "C" fn validation_block_disconnected_wrapper( if let Some(ref handler) = registry.block_disconnected_handler { handler.on_block_disconnected( block, - BlockTreeEntry::from_ptr(pindex as *mut btck_BlockTreeEntry), + BlockTreeEntry::from_ptr(entry as *mut btck_BlockTreeEntry), ); } } @@ -213,7 +213,7 @@ mod tests { #[test] fn test_new_pow_valid_block_registration() { - fn handler(_pindex: BlockTreeEntry, _block: Block) {} + fn handler(_entry: BlockTreeEntry, _block: Block) {} let mut registry = ValidationCallbackRegistry::new(); registry.register_new_pow_valid_block(handler); @@ -222,7 +222,7 @@ mod tests { #[test] fn test_block_connected_registration() { - fn handler(_block: Block, _pindex: BlockTreeEntry) {} + fn handler(_block: Block, _entry: BlockTreeEntry) {} let mut registry = ValidationCallbackRegistry::new(); registry.register_block_connected(handler); @@ -231,7 +231,7 @@ mod tests { #[test] fn test_block_disconnected_registration() { - fn handler(_block: Block, _pindex: BlockTreeEntry) {} + fn handler(_block: Block, _entry: BlockTreeEntry) {} let mut registry = ValidationCallbackRegistry::new(); registry.register_block_disconnected(handler); @@ -272,14 +272,14 @@ mod tests { let called_clone = Arc::clone(&called); let mut registry = ValidationCallbackRegistry::new(); - registry.register_new_pow_valid_block(move |_pindex: BlockTreeEntry, _block: Block| { + registry.register_new_pow_valid_block(move |_entry: BlockTreeEntry, _block: Block| { *called_clone.lock().unwrap() = true; }); if let Some(ref handler) = registry.new_pow_valid_block_handler { let block = unsafe { Block::from_ptr(std::ptr::null_mut()) }; - let pindex = unsafe { BlockTreeEntry::from_ptr(std::ptr::null_mut()) }; - handler.on_new_pow_valid_block(block, pindex); + let entry = unsafe { BlockTreeEntry::from_ptr(std::ptr::null_mut()) }; + handler.on_new_pow_valid_block(block, entry); } assert!(*called.lock().unwrap()); @@ -291,14 +291,14 @@ mod tests { let called_clone = Arc::clone(&called); let mut registry = ValidationCallbackRegistry::new(); - registry.register_block_connected(move |_block: Block, _pindex: BlockTreeEntry| { + registry.register_block_connected(move |_block: Block, _entry: BlockTreeEntry| { *called_clone.lock().unwrap() = true; }); if let Some(ref handler) = registry.block_connected_handler { let block = unsafe { Block::from_ptr(std::ptr::null_mut()) }; - let pindex = unsafe { BlockTreeEntry::from_ptr(std::ptr::null_mut()) }; - handler.on_block_connected(block, pindex); + let entry = unsafe { BlockTreeEntry::from_ptr(std::ptr::null_mut()) }; + handler.on_block_connected(block, entry); } assert!(*called.lock().unwrap()); @@ -310,14 +310,14 @@ mod tests { let called_clone = Arc::clone(&called); let mut registry = ValidationCallbackRegistry::new(); - registry.register_block_disconnected(move |_block: Block, _pindex: BlockTreeEntry| { + registry.register_block_disconnected(move |_block: Block, _entry: BlockTreeEntry| { *called_clone.lock().unwrap() = true; }); if let Some(ref handler) = registry.block_disconnected_handler { let block = unsafe { Block::from_ptr(std::ptr::null_mut()) }; - let pindex = unsafe { BlockTreeEntry::from_ptr(std::ptr::null_mut()) }; - handler.on_block_disconnected(block, pindex); + let entry = unsafe { BlockTreeEntry::from_ptr(std::ptr::null_mut()) }; + handler.on_block_disconnected(block, entry); } assert!(*called.lock().unwrap()); diff --git a/src/state/context.rs b/src/state/context.rs index a764fdb2..eaaf8e29 100644 --- a/src/state/context.rs +++ b/src/state/context.rs @@ -811,7 +811,7 @@ impl ContextBuilder { /// /// # Arguments /// * `handler` - The callback function or closure that receives: - /// - `pindex` - The [`BlockTreeEntry`](crate::BlockTreeEntry) for the new block + /// - `entry` - The [`BlockTreeEntry`](crate::BlockTreeEntry) for the new block /// - `block` - The [`Block`](crate::Block) data /// /// # Returns @@ -822,9 +822,9 @@ impl ContextBuilder { /// use bitcoinkernel::{Block, BlockTreeEntry, ContextBuilder, KernelError}; /// /// let context = ContextBuilder::new() - /// .with_new_pow_valid_block_validation(|pindex: BlockTreeEntry<'_>, block: Block| { + /// .with_new_pow_valid_block_validation(|entry: BlockTreeEntry<'_>, block: Block| { /// println!("New PoW-valid block at height {}: {}", - /// pindex.height(), block.hash()); + /// entry.height(), block.hash()); /// }) /// .build()?; /// # Ok::<(), KernelError>(()) @@ -850,7 +850,7 @@ impl ContextBuilder { /// # Arguments /// * `handler` - The callback function or closure that receives: /// - `block` - The [`Block`](crate::Block) that was connected - /// - `pindex` - The [`BlockTreeEntry`](crate::BlockTreeEntry) representing the block's position in the chain + /// - `entry` - The [`BlockTreeEntry`](crate::BlockTreeEntry) representing the block's position in the chain /// /// # Returns /// The builder instance for method chaining. @@ -860,9 +860,9 @@ impl ContextBuilder { /// use bitcoinkernel::{Block, BlockTreeEntry, ContextBuilder, KernelError}; /// /// let context = ContextBuilder::new() - /// .with_block_connected_validation(|block: Block, pindex: BlockTreeEntry<'_>| { + /// .with_block_connected_validation(|block: Block, entry: BlockTreeEntry<'_>| { /// println!("Block connected at height {}: {}", - /// pindex.height(), block.hash()); + /// entry.height(), block.hash()); /// }) /// .build()?; /// # Ok::<(), KernelError>(()) @@ -889,7 +889,7 @@ impl ContextBuilder { /// # Arguments /// * `handler` - The callback function or closure that receives: /// - `block` - The [`Block`](crate::Block) that was disconnected - /// - `pindex` - The [`BlockTreeEntry`](crate::BlockTreeEntry) for the disconnected block + /// - `entry` - The [`BlockTreeEntry`](crate::BlockTreeEntry) for the disconnected block /// /// # Returns /// The builder instance for method chaining. @@ -899,9 +899,9 @@ impl ContextBuilder { /// use bitcoinkernel::{Block, BlockTreeEntry, ContextBuilder, KernelError}; /// /// let context = ContextBuilder::new() - /// .with_block_disconnected_validation(|block: Block, pindex: BlockTreeEntry<'_>| { + /// .with_block_disconnected_validation(|block: Block, entry: BlockTreeEntry<'_>| { /// println!("Block disconnected from height {}: {} (reorg)", - /// pindex.height(), block.hash()); + /// entry.height(), block.hash()); /// }) /// .build()?; /// # Ok::<(), KernelError>(()) @@ -938,11 +938,11 @@ impl ContextBuilder { /// registry.register_block_checked(|block: Block, _state: BlockValidationStateRef<'_>| { /// println!("Checked: {}", block.hash()); /// }); - /// registry.register_block_connected(|_block, pindex: BlockTreeEntry<'_>| { - /// println!("Connected at height {}", pindex.height()); + /// registry.register_block_connected(|_block, entry: BlockTreeEntry<'_>| { + /// println!("Connected at height {}", entry.height()); /// }); - /// registry.register_block_disconnected(|_block, pindex: BlockTreeEntry<'_>| { - /// println!("Disconnected from height {}", pindex.height()); + /// registry.register_block_disconnected(|_block, entry: BlockTreeEntry<'_>| { + /// println!("Disconnected from height {}", entry.height()); /// }); /// }) /// .build()?; @@ -1187,9 +1187,9 @@ mod tests { #[test] fn test_advanced_validation_configuration() { - fn pow_handler(_pindex: crate::BlockTreeEntry, _block: crate::Block) {} - fn connected_handler(_block: crate::Block, _pindex: crate::BlockTreeEntry) {} - fn disconnected_handler(_block: crate::Block, _pindex: crate::BlockTreeEntry) {} + fn pow_handler(_entry: crate::BlockTreeEntry, _block: crate::Block) {} + fn connected_handler(_block: crate::Block, _entry: crate::BlockTreeEntry) {} + fn disconnected_handler(_block: crate::Block, _entry: crate::BlockTreeEntry) {} let mut builder = ContextBuilder::new(); diff --git a/tests/test.rs b/tests/test.rs index cd4f379e..1a7ef23c 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -36,15 +36,15 @@ mod tests { } fn create_context() -> Context { - fn pow_handler(_pindex: BlockTreeEntry, _block: Block) { + fn pow_handler(_entry: BlockTreeEntry, _block: Block) { log::info!("New PoW valid block!"); } - fn connected_handler(_block: Block, _pindex: BlockTreeEntry) { + fn connected_handler(_block: Block, _entry: BlockTreeEntry) { log::info!("Block connected!"); } - fn disconnected_handler(_block: Block, _pindex: BlockTreeEntry) { + fn disconnected_handler(_block: Block, _entry: BlockTreeEntry) { log::info!("Block disconnected!"); }