Skip to content

Commit 915fcdb

Browse files
committed
callbacks: provide default implementations
1 parent 5daf449 commit 915fcdb

File tree

5 files changed

+12
-40
lines changed

5 files changed

+12
-40
lines changed

src/callbacks/balances.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ impl Callback for Balances {
4343
Ok(())
4444
}
4545

46-
fn on_header(
47-
&mut self,
48-
_header: &bitcoin::blockdata::block::Header,
49-
_block_height: u64,
50-
) -> anyhow::Result<()> {
51-
Ok(())
52-
}
53-
5446
/// For each transaction in the block
5547
/// 1. apply input transactions (remove (TxID == prevTxIDOut and prevOutID == spentOutID))
5648
/// 2. apply output transactions (add (TxID + curOutID -> HashMapVal))

src/callbacks/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,28 @@ pub trait Callback {
1515
Self: Sized;
1616

1717
/// Gets called shortly before the blocks are parsed.
18-
fn on_start(&mut self, block_height: u64) -> anyhow::Result<()>;
18+
fn on_start(&mut self, _block_height: u64) -> anyhow::Result<()> {
19+
Ok(())
20+
}
1921

2022
/// Gets called if a new header is available.
2123
fn on_header(
2224
&mut self,
2325
_header: &bitcoin::blockdata::block::Header,
2426
_block_height: u64,
25-
) -> anyhow::Result<()>;
27+
) -> anyhow::Result<()> {
28+
Ok(())
29+
}
2630

2731
/// Gets called if a new block is available.
28-
fn on_block(&mut self, block: &bitcoin::Block, block_height: u64) -> anyhow::Result<()>;
32+
fn on_block(&mut self, _block: &bitcoin::Block, _block_height: u64) -> anyhow::Result<()> {
33+
Ok(())
34+
}
2935

3036
/// Gets called if the parser has finished and all blocks are handled
31-
fn on_complete(&mut self, block_height: u64) -> anyhow::Result<()>;
37+
fn on_complete(&mut self, _block_height: u64) -> anyhow::Result<()> {
38+
Ok(())
39+
}
3240
}
3341

3442
pub struct UnspentValue {

src/callbacks/opreturn.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ impl Callback for OpReturn {
1818
Ok(())
1919
}
2020

21-
fn on_header(
22-
&mut self,
23-
_header: &bitcoin::blockdata::block::Header,
24-
_block_height: u64,
25-
) -> anyhow::Result<()> {
26-
Ok(())
27-
}
28-
2921
fn on_block(&mut self, block: &bitcoin::Block, block_height: u64) -> anyhow::Result<()> {
3022
for tx in &block.txdata {
3123
for out in &tx.output {
@@ -51,8 +43,4 @@ impl Callback for OpReturn {
5143
}
5244
Ok(())
5345
}
54-
55-
fn on_complete(&mut self, _: u64) -> anyhow::Result<()> {
56-
Ok(())
57-
}
5846
}

src/callbacks/simplestats.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,6 @@ impl Callback for SimpleStats {
186186
Ok(())
187187
}
188188

189-
fn on_header(
190-
&mut self,
191-
_header: &bitcoin::blockdata::block::Header,
192-
_block_height: u64,
193-
) -> anyhow::Result<()> {
194-
Ok(())
195-
}
196-
197189
fn on_block(&mut self, block: &bitcoin::Block, block_height: u64) -> anyhow::Result<()> {
198190
self.n_valid_blocks += 1;
199191
self.n_tx += block.txdata.len();

src/callbacks/unspentcsvdump.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ impl crate::callbacks::Callback for UnspentCsvDump {
4545
Ok(())
4646
}
4747

48-
fn on_header(
49-
&mut self,
50-
_header: &bitcoin::blockdata::block::Header,
51-
_block_height: u64,
52-
) -> anyhow::Result<()> {
53-
Ok(())
54-
}
55-
5648
/// For each transaction in the block
5749
/// 1. apply input transactions (remove (TxID == prevTxIDOut and prevOutID == spentOutID))
5850
/// 2. apply output transactions (add (TxID + curOutID -> HashMapVal))

0 commit comments

Comments
 (0)