Skip to content

Commit 5b69a6a

Browse files
authored
Merge pull request #101 from TheCharlatan/rename_pindex_to_entry
Rename pindex to entry
2 parents efbaf32 + cd2ce1c commit 5b69a6a

File tree

3 files changed

+46
-46
lines changed

3 files changed

+46
-46
lines changed

src/notifications/validation.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,43 @@ where
2323

2424
/// Callback for when a new PoW valid block is found.
2525
pub trait NewPoWValidBlockCallback: Send + Sync {
26-
fn on_new_pow_valid_block<'a>(&self, block: Block, pindex: BlockTreeEntry<'a>);
26+
fn on_new_pow_valid_block<'a>(&self, block: Block, entry: BlockTreeEntry<'a>);
2727
}
2828

2929
impl<F> NewPoWValidBlockCallback for F
3030
where
3131
F: for<'a> Fn(BlockTreeEntry<'a>, Block) + Send + Sync + 'static,
3232
{
33-
fn on_new_pow_valid_block<'a>(&self, block: Block, pindex: BlockTreeEntry<'a>) {
34-
self(pindex, block)
33+
fn on_new_pow_valid_block<'a>(&self, block: Block, entry: BlockTreeEntry<'a>) {
34+
self(entry, block)
3535
}
3636
}
3737

3838
/// Callback for when a block is connected to the chain.
3939
pub trait BlockConnectedCallback: Send + Sync {
40-
fn on_block_connected<'a>(&self, block: Block, pindex: BlockTreeEntry<'a>);
40+
fn on_block_connected<'a>(&self, block: Block, entry: BlockTreeEntry<'a>);
4141
}
4242

4343
impl<F> BlockConnectedCallback for F
4444
where
4545
F: for<'a> Fn(Block, BlockTreeEntry<'a>) + Send + Sync + 'static,
4646
{
47-
fn on_block_connected<'a>(&self, block: Block, pindex: BlockTreeEntry<'a>) {
48-
self(block, pindex)
47+
fn on_block_connected<'a>(&self, block: Block, entry: BlockTreeEntry<'a>) {
48+
self(block, entry)
4949
}
5050
}
5151

5252
/// Callback for when a block is disconnected from the chain.
5353
pub trait BlockDisconnectedCallback: Send + Sync {
54-
fn on_block_disconnected<'a>(&self, block: Block, pindex: BlockTreeEntry<'a>);
54+
fn on_block_disconnected<'a>(&self, block: Block, entry: BlockTreeEntry<'a>);
5555
}
5656

5757
impl<F> BlockDisconnectedCallback for F
5858
where
5959
F: for<'a> Fn(Block, BlockTreeEntry<'a>) + Send + Sync + 'static,
6060
{
61-
fn on_block_disconnected<'a>(&self, block: Block, pindex: BlockTreeEntry<'a>) {
62-
self(block, pindex)
61+
fn on_block_disconnected<'a>(&self, block: Block, entry: BlockTreeEntry<'a>) {
62+
self(block, entry)
6363
}
6464
}
6565

@@ -134,47 +134,47 @@ pub(crate) unsafe extern "C" fn validation_block_checked_wrapper(
134134
pub(crate) unsafe extern "C" fn validation_new_pow_valid_block_wrapper(
135135
user_data: *mut c_void,
136136
block: *mut btck_Block,
137-
pindex: *const btck_BlockTreeEntry,
137+
entry: *const btck_BlockTreeEntry,
138138
) {
139139
let block = Block::from_ptr(block);
140140
let registry = &*(user_data as *mut ValidationCallbackRegistry);
141141

142142
if let Some(ref handler) = registry.new_pow_valid_block_handler {
143143
handler.on_new_pow_valid_block(
144144
block,
145-
BlockTreeEntry::from_ptr(pindex as *mut btck_BlockTreeEntry),
145+
BlockTreeEntry::from_ptr(entry as *mut btck_BlockTreeEntry),
146146
);
147147
}
148148
}
149149

150150
pub(crate) unsafe extern "C" fn validation_block_connected_wrapper(
151151
user_data: *mut c_void,
152152
block: *mut btck_Block,
153-
pindex: *const btck_BlockTreeEntry,
153+
entry: *const btck_BlockTreeEntry,
154154
) {
155155
let block = Block::from_ptr(block);
156156
let registry = &*(user_data as *mut ValidationCallbackRegistry);
157157

158158
if let Some(ref handler) = registry.block_connected_handler {
159159
handler.on_block_connected(
160160
block,
161-
BlockTreeEntry::from_ptr(pindex as *mut btck_BlockTreeEntry),
161+
BlockTreeEntry::from_ptr(entry as *mut btck_BlockTreeEntry),
162162
);
163163
}
164164
}
165165

166166
pub(crate) unsafe extern "C" fn validation_block_disconnected_wrapper(
167167
user_data: *mut c_void,
168168
block: *mut btck_Block,
169-
pindex: *const btck_BlockTreeEntry,
169+
entry: *const btck_BlockTreeEntry,
170170
) {
171171
let block = Block::from_ptr(block);
172172
let registry = &*(user_data as *mut ValidationCallbackRegistry);
173173

174174
if let Some(ref handler) = registry.block_disconnected_handler {
175175
handler.on_block_disconnected(
176176
block,
177-
BlockTreeEntry::from_ptr(pindex as *mut btck_BlockTreeEntry),
177+
BlockTreeEntry::from_ptr(entry as *mut btck_BlockTreeEntry),
178178
);
179179
}
180180
}
@@ -213,7 +213,7 @@ mod tests {
213213

214214
#[test]
215215
fn test_new_pow_valid_block_registration() {
216-
fn handler(_pindex: BlockTreeEntry, _block: Block) {}
216+
fn handler(_entry: BlockTreeEntry, _block: Block) {}
217217

218218
let mut registry = ValidationCallbackRegistry::new();
219219
registry.register_new_pow_valid_block(handler);
@@ -222,7 +222,7 @@ mod tests {
222222

223223
#[test]
224224
fn test_block_connected_registration() {
225-
fn handler(_block: Block, _pindex: BlockTreeEntry) {}
225+
fn handler(_block: Block, _entry: BlockTreeEntry) {}
226226

227227
let mut registry = ValidationCallbackRegistry::new();
228228
registry.register_block_connected(handler);
@@ -231,7 +231,7 @@ mod tests {
231231

232232
#[test]
233233
fn test_block_disconnected_registration() {
234-
fn handler(_block: Block, _pindex: BlockTreeEntry) {}
234+
fn handler(_block: Block, _entry: BlockTreeEntry) {}
235235

236236
let mut registry = ValidationCallbackRegistry::new();
237237
registry.register_block_disconnected(handler);
@@ -272,14 +272,14 @@ mod tests {
272272
let called_clone = Arc::clone(&called);
273273

274274
let mut registry = ValidationCallbackRegistry::new();
275-
registry.register_new_pow_valid_block(move |_pindex: BlockTreeEntry, _block: Block| {
275+
registry.register_new_pow_valid_block(move |_entry: BlockTreeEntry, _block: Block| {
276276
*called_clone.lock().unwrap() = true;
277277
});
278278

279279
if let Some(ref handler) = registry.new_pow_valid_block_handler {
280280
let block = unsafe { Block::from_ptr(std::ptr::null_mut()) };
281-
let pindex = unsafe { BlockTreeEntry::from_ptr(std::ptr::null_mut()) };
282-
handler.on_new_pow_valid_block(block, pindex);
281+
let entry = unsafe { BlockTreeEntry::from_ptr(std::ptr::null_mut()) };
282+
handler.on_new_pow_valid_block(block, entry);
283283
}
284284

285285
assert!(*called.lock().unwrap());
@@ -291,14 +291,14 @@ mod tests {
291291
let called_clone = Arc::clone(&called);
292292

293293
let mut registry = ValidationCallbackRegistry::new();
294-
registry.register_block_connected(move |_block: Block, _pindex: BlockTreeEntry| {
294+
registry.register_block_connected(move |_block: Block, _entry: BlockTreeEntry| {
295295
*called_clone.lock().unwrap() = true;
296296
});
297297

298298
if let Some(ref handler) = registry.block_connected_handler {
299299
let block = unsafe { Block::from_ptr(std::ptr::null_mut()) };
300-
let pindex = unsafe { BlockTreeEntry::from_ptr(std::ptr::null_mut()) };
301-
handler.on_block_connected(block, pindex);
300+
let entry = unsafe { BlockTreeEntry::from_ptr(std::ptr::null_mut()) };
301+
handler.on_block_connected(block, entry);
302302
}
303303

304304
assert!(*called.lock().unwrap());
@@ -310,14 +310,14 @@ mod tests {
310310
let called_clone = Arc::clone(&called);
311311

312312
let mut registry = ValidationCallbackRegistry::new();
313-
registry.register_block_disconnected(move |_block: Block, _pindex: BlockTreeEntry| {
313+
registry.register_block_disconnected(move |_block: Block, _entry: BlockTreeEntry| {
314314
*called_clone.lock().unwrap() = true;
315315
});
316316

317317
if let Some(ref handler) = registry.block_disconnected_handler {
318318
let block = unsafe { Block::from_ptr(std::ptr::null_mut()) };
319-
let pindex = unsafe { BlockTreeEntry::from_ptr(std::ptr::null_mut()) };
320-
handler.on_block_disconnected(block, pindex);
319+
let entry = unsafe { BlockTreeEntry::from_ptr(std::ptr::null_mut()) };
320+
handler.on_block_disconnected(block, entry);
321321
}
322322

323323
assert!(*called.lock().unwrap());

src/state/context.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ impl ContextBuilder {
811811
///
812812
/// # Arguments
813813
/// * `handler` - The callback function or closure that receives:
814-
/// - `pindex` - The [`BlockTreeEntry`](crate::BlockTreeEntry) for the new block
814+
/// - `entry` - The [`BlockTreeEntry`](crate::BlockTreeEntry) for the new block
815815
/// - `block` - The [`Block`](crate::Block) data
816816
///
817817
/// # Returns
@@ -822,9 +822,9 @@ impl ContextBuilder {
822822
/// use bitcoinkernel::{Block, BlockTreeEntry, ContextBuilder, KernelError};
823823
///
824824
/// let context = ContextBuilder::new()
825-
/// .with_new_pow_valid_block_validation(|pindex: BlockTreeEntry<'_>, block: Block| {
825+
/// .with_new_pow_valid_block_validation(|entry: BlockTreeEntry<'_>, block: Block| {
826826
/// println!("New PoW-valid block at height {}: {}",
827-
/// pindex.height(), block.hash());
827+
/// entry.height(), block.hash());
828828
/// })
829829
/// .build()?;
830830
/// # Ok::<(), KernelError>(())
@@ -850,7 +850,7 @@ impl ContextBuilder {
850850
/// # Arguments
851851
/// * `handler` - The callback function or closure that receives:
852852
/// - `block` - The [`Block`](crate::Block) that was connected
853-
/// - `pindex` - The [`BlockTreeEntry`](crate::BlockTreeEntry) representing the block's position in the chain
853+
/// - `entry` - The [`BlockTreeEntry`](crate::BlockTreeEntry) representing the block's position in the chain
854854
///
855855
/// # Returns
856856
/// The builder instance for method chaining.
@@ -860,9 +860,9 @@ impl ContextBuilder {
860860
/// use bitcoinkernel::{Block, BlockTreeEntry, ContextBuilder, KernelError};
861861
///
862862
/// let context = ContextBuilder::new()
863-
/// .with_block_connected_validation(|block: Block, pindex: BlockTreeEntry<'_>| {
863+
/// .with_block_connected_validation(|block: Block, entry: BlockTreeEntry<'_>| {
864864
/// println!("Block connected at height {}: {}",
865-
/// pindex.height(), block.hash());
865+
/// entry.height(), block.hash());
866866
/// })
867867
/// .build()?;
868868
/// # Ok::<(), KernelError>(())
@@ -889,7 +889,7 @@ impl ContextBuilder {
889889
/// # Arguments
890890
/// * `handler` - The callback function or closure that receives:
891891
/// - `block` - The [`Block`](crate::Block) that was disconnected
892-
/// - `pindex` - The [`BlockTreeEntry`](crate::BlockTreeEntry) for the disconnected block
892+
/// - `entry` - The [`BlockTreeEntry`](crate::BlockTreeEntry) for the disconnected block
893893
///
894894
/// # Returns
895895
/// The builder instance for method chaining.
@@ -899,9 +899,9 @@ impl ContextBuilder {
899899
/// use bitcoinkernel::{Block, BlockTreeEntry, ContextBuilder, KernelError};
900900
///
901901
/// let context = ContextBuilder::new()
902-
/// .with_block_disconnected_validation(|block: Block, pindex: BlockTreeEntry<'_>| {
902+
/// .with_block_disconnected_validation(|block: Block, entry: BlockTreeEntry<'_>| {
903903
/// println!("Block disconnected from height {}: {} (reorg)",
904-
/// pindex.height(), block.hash());
904+
/// entry.height(), block.hash());
905905
/// })
906906
/// .build()?;
907907
/// # Ok::<(), KernelError>(())
@@ -938,11 +938,11 @@ impl ContextBuilder {
938938
/// registry.register_block_checked(|block: Block, _state: BlockValidationStateRef<'_>| {
939939
/// println!("Checked: {}", block.hash());
940940
/// });
941-
/// registry.register_block_connected(|_block, pindex: BlockTreeEntry<'_>| {
942-
/// println!("Connected at height {}", pindex.height());
941+
/// registry.register_block_connected(|_block, entry: BlockTreeEntry<'_>| {
942+
/// println!("Connected at height {}", entry.height());
943943
/// });
944-
/// registry.register_block_disconnected(|_block, pindex: BlockTreeEntry<'_>| {
945-
/// println!("Disconnected from height {}", pindex.height());
944+
/// registry.register_block_disconnected(|_block, entry: BlockTreeEntry<'_>| {
945+
/// println!("Disconnected from height {}", entry.height());
946946
/// });
947947
/// })
948948
/// .build()?;
@@ -1187,9 +1187,9 @@ mod tests {
11871187

11881188
#[test]
11891189
fn test_advanced_validation_configuration() {
1190-
fn pow_handler(_pindex: crate::BlockTreeEntry, _block: crate::Block) {}
1191-
fn connected_handler(_block: crate::Block, _pindex: crate::BlockTreeEntry) {}
1192-
fn disconnected_handler(_block: crate::Block, _pindex: crate::BlockTreeEntry) {}
1190+
fn pow_handler(_entry: crate::BlockTreeEntry, _block: crate::Block) {}
1191+
fn connected_handler(_block: crate::Block, _entry: crate::BlockTreeEntry) {}
1192+
fn disconnected_handler(_block: crate::Block, _entry: crate::BlockTreeEntry) {}
11931193

11941194
let mut builder = ContextBuilder::new();
11951195

tests/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ mod tests {
3434
}
3535

3636
fn create_context() -> Context {
37-
fn pow_handler(_pindex: BlockTreeEntry, _block: Block) {
37+
fn pow_handler(_entry: BlockTreeEntry, _block: Block) {
3838
log::info!("New PoW valid block!");
3939
}
4040

41-
fn connected_handler(_block: Block, _pindex: BlockTreeEntry) {
41+
fn connected_handler(_block: Block, _entry: BlockTreeEntry) {
4242
log::info!("Block connected!");
4343
}
4444

45-
fn disconnected_handler(_block: Block, _pindex: BlockTreeEntry) {
45+
fn disconnected_handler(_block: Block, _entry: BlockTreeEntry) {
4646
log::info!("Block disconnected!");
4747
}
4848

0 commit comments

Comments
 (0)