brk_computer 0.3.0-beta.6

A Bitcoin dataset computer built on top of brk_indexer
Documentation
use brk_error::Result;
use brk_types::{Height, Indexes, StoredU64};
use vecdb::Exit;

use super::Vecs;
use crate::{
    inputs,
    internal::PerBlockCumulativeRolling,
    outputs::{ByTypeVecs, CountVecs},
};

impl Vecs {
    pub(crate) fn compute(
        &mut self,
        count: &CountVecs,
        inputs_count: &inputs::CountVecs,
        by_type: &ByTypeVecs,
        starting_indexes: &Indexes,
        exit: &Exit,
    ) -> Result<()> {
        let op_return: &PerBlockCumulativeRolling<StoredU64, StoredU64> =
            &by_type.output_count.by_type.unspendable.op_return;

        self.count.height.compute_transform3(
            starting_indexes.height,
            &count.total.cumulative.height,
            &inputs_count.cumulative.height,
            &op_return.cumulative.height,
            |(h, output_count, input_count, op_return_count, ..)| {
                let block_count = u64::from(h + 1_usize);
                // -1 > genesis output is unspendable
                let mut utxo_count =
                    *output_count - (*input_count - block_count) - *op_return_count - 1;

                // BIP30 duplicate txid corrections
                if h >= Height::new(91_842) {
                    utxo_count -= 1;
                }
                if h >= Height::new(91_880) {
                    utxo_count -= 1;
                }

                (h, StoredU64::from(utxo_count))
            },
            exit,
        )?;
        Ok(())
    }
}