Expand description
The FilterParser
and UtxoParser
parser must be used together in order to track UTXOs
as they move through the tx graph, giving you a map between:
This allows you to easily compute values such as mining fees and find all unspent txs.
The FilterParser
creates a ScalableCuckooFilter
which allows us to track all
unspent UTXOs with low memory-overhead similar to a bloom filter.
The filter is written to a file which is loaded into memory by UtxoParser
, allowing us to
track the flow of all transaction amounts from inputs with a far lower memory overhead and no
performance hit of using an on-disk lookup table.
Example usage:
use bitcoin_block_parser::*;
use bitcoin_block_parser::utxos::*;
// Note you only need to write the filter to a file once
let parser = FilterParser::new();
for _ in parser.parse_dir("/path/to/blocks").unwrap() {}
parser.write("filter.bin").unwrap();
let parser = UtxoParser::new("filter.bin").unwrap();
// for every block
for block in parser.parse_dir("/path/to/blocks").unwrap() {
let block = block.unwrap();
// for every transaction
for (tx, txid) in block.transactions() {
let outs = block.output_status(txid).iter().zip(tx.output.iter());
let inputs = block.input_amount(txid).iter().zip(tx.input.iter());
// for every output in the transaction
for (status, output) in outs {
if *status == OutStatus::Unspent {
let script = &output.script_pubkey;
println!("{:?} has {} unspent funds", script, output.value);
}
}
// for every input in the transaction
for (amount, input) in inputs {
let outpoint = &input.previous_output;
println!("{:?} has {} input funds", outpoint, amount);
}
}
}
Structs§
- A parser that writes a probabilistic filter of unspent
ShortOutPoint
. See the module docs for example usage. - Shortened
OutPoint
to save memory - Contains a block that has been parsed with frequently needed UTXO information
- Parser that tracks unspent outputs and input amounts to produce
UtxoBlock
Enums§
- Indicates what happens to this output