pub mod blocks;
pub mod chain_storage;
pub mod consensus;
pub mod iterators;
pub mod proof_of_work;
pub mod validation;
#[macro_use]
pub mod test_helpers;
pub mod base_node;
pub mod mempool;
pub mod proto;
mod common;
pub use common::AuxChainHashes;
mod domain_hashing {
use std::convert::TryFrom;
use blake2::Blake2b;
use digest::consts::U32;
use tari_common_types::types::{FixedHash, FixedHashSizeError};
use tari_crypto::{hash_domain, hashing::DomainSeparatedHasher};
use tari_hashing::{ValidatorNodeMerkleHashDomain, hashers::KernelMmrHasherBlake256};
use tari_mmr::{
Hash,
MerkleMountainRange,
error::MerkleMountainRangeError,
pruned_hashset::PrunedHashSet,
sparse_merkle_tree::SparseMerkleTree,
};
pub type KernelMmr = MerkleMountainRange<KernelMmrHasherBlake256, Vec<Hash>>;
pub type PrunedKernelMmr = MerkleMountainRange<KernelMmrHasherBlake256, PrunedHashSet>;
hash_domain!(OutputSmtHashDomain, "com.tari.base_layer.core.output_smt", 1);
pub type OutputSmtHasherBlake256 = DomainSeparatedHasher<Blake2b<U32>, OutputSmtHashDomain>;
hash_domain!(InputMmrHashDomain, "com.tari.base_layer.core.input_mmr", 1);
pub type InputMmrHasherBlake256 = DomainSeparatedHasher<Blake2b<U32>, InputMmrHashDomain>;
pub type PrunedInputMmr = MerkleMountainRange<InputMmrHasherBlake256, PrunedHashSet>;
pub type PrunedOutputMmr = MerkleMountainRange<InputMmrHasherBlake256, PrunedHashSet>;
pub type OutputSmt = SparseMerkleTree<OutputSmtHasherBlake256>;
pub type ValidatorNodeMerkleHasherBlake256 = DomainSeparatedHasher<Blake2b<U32>, ValidatorNodeMerkleHashDomain>;
#[inline]
pub fn kernel_mr_hash_from_mmr(kernel_mmr: &KernelMmr) -> Result<FixedHash, MrHashError> {
Ok(FixedHash::try_from(kernel_mmr.get_merkle_root()?)?)
}
#[inline]
pub fn kernel_mr_hash_from_pruned_mmr(kernel_mmr: &PrunedKernelMmr) -> Result<FixedHash, MrHashError> {
Ok(FixedHash::try_from(kernel_mmr.get_merkle_root()?)?)
}
#[inline]
pub fn input_mr_hash_from_pruned_mmr(input_mmr: &PrunedInputMmr) -> Result<FixedHash, MrHashError> {
Ok(FixedHash::try_from(input_mmr.get_merkle_root()?)?)
}
#[inline]
pub fn block_output_mr_hash_from_pruned_mmr(output_mmr: &PrunedOutputMmr) -> Result<FixedHash, MrHashError> {
Ok(FixedHash::try_from(output_mmr.get_merkle_root()?)?)
}
#[derive(Debug, thiserror::Error)]
pub enum MrHashError {
#[error("Output SMT conversion error: {0}")]
FixedHashSizeError(#[from] FixedHashSizeError),
#[error("Input MR conversion error: {0}")]
MerkleMountainRangeError(#[from] MerkleMountainRangeError),
}
}
pub use domain_hashing::*;