rename TreeHashType to HashType

This commit is contained in:
Sergio Chouhy 2025-10-17 16:04:09 -03:00
parent 217551f960
commit b93c0aa390
6 changed files with 18 additions and 21 deletions

View File

@ -12,7 +12,7 @@ pub mod test_utils;
use rpc_primitives::errors::RpcError;
pub type TreeHashType = [u8; 32];
pub type HashType = [u8; 32];
pub type CommitmentHashType = Vec<u8>;
#[derive(Debug, Clone)]
@ -21,19 +21,16 @@ pub type CommitmentHashType = Vec<u8>;
pub struct OwnHasher {}
impl Hasher for OwnHasher {
type Hash = TreeHashType;
type Hash = HashType;
fn hash(data: &[u8]) -> TreeHashType {
fn hash(data: &[u8]) -> HashType {
let mut hasher = Sha256::new();
hasher.update(data);
<TreeHashType>::from(hasher.finalize_fixed())
<HashType>::from(hasher.finalize_fixed())
}
}
///Account id on blockchain
pub type AccountId = TreeHashType;
#[derive(Debug, Clone, Deserialize)]
pub struct SequencerRpcError {
pub jsonrpc: String,

View File

@ -91,7 +91,7 @@ mod tests {
use sha2::{Digest, digest::FixedOutput};
use crate::{
TreeHashType,
HashType,
transaction::{EncodedTransaction, TxKind},
};
@ -109,7 +109,7 @@ mod tests {
let data = borsh::to_vec(&body).unwrap();
let mut hasher = sha2::Sha256::new();
hasher.update(&data);
TreeHashType::from(hasher.finalize_fixed())
HashType::from(hasher.finalize_fixed())
};
let hash = body.hash();

View File

@ -1,5 +1,5 @@
use bip39::Mnemonic;
use common::TreeHashType;
use common::HashType;
use nssa_core::{
NullifierPublicKey, NullifierSecretKey,
encryption::{IncomingViewingPublicKey, Scalar},
@ -44,7 +44,7 @@ impl SeedHolder {
}
}
pub fn generate_secret_spending_key_hash(&self) -> TreeHashType {
pub fn generate_secret_spending_key_hash(&self) -> HashType {
let mut hash = hmac_sha512::HMAC::mac(&self.seed, "NSSA_seed");
for _ in 1..2048 {
@ -80,7 +80,7 @@ impl SecretSpendingKey {
hasher.update([2u8]);
hasher.update([0u8; 22]);
<TreeHashType>::from(hasher.finalize_fixed())
<HashType>::from(hasher.finalize_fixed())
}
pub fn generate_outgoing_viewing_secret_key(&self) -> OutgoingViewingSecretKey {
@ -91,7 +91,7 @@ impl SecretSpendingKey {
hasher.update([3u8]);
hasher.update([0u8; 22]);
<TreeHashType>::from(hasher.finalize_fixed())
<HashType>::from(hasher.finalize_fixed())
}
pub fn produce_private_key_holder(&self) -> PrivateKeyHolder {

View File

@ -2,7 +2,7 @@ use std::fmt::Display;
use anyhow::Result;
use common::{
TreeHashType,
HashType,
block::HashableBlockData,
transaction::{EncodedTransaction, NSSATransaction},
};
@ -26,7 +26,7 @@ pub struct SequencerCore {
pub enum TransactionMalformationError {
MempoolFullForRound,
InvalidSignature,
FailedToDecode { tx: TreeHashType },
FailedToDecode { tx: HashType },
}
impl Display for TransactionMalformationError {

View File

@ -1,13 +1,13 @@
use std::{collections::HashMap, path::Path};
use anyhow::Result;
use common::{TreeHashType, block::Block, transaction::EncodedTransaction};
use common::{HashType, block::Block, transaction::EncodedTransaction};
use storage::RocksDBIO;
pub struct SequecerBlockStore {
dbio: RocksDBIO,
// TODO: Consider adding the hashmap to the database for faster recovery.
tx_hash_to_block_map: HashMap<TreeHashType, u64>,
tx_hash_to_block_map: HashMap<HashType, u64>,
pub genesis_id: u64,
pub signing_key: nssa::PrivateKey,
}
@ -57,7 +57,7 @@ impl SequecerBlockStore {
}
/// Returns the transaction corresponding to the given hash, if it exists in the blockchain.
pub fn get_transaction_by_hash(&self, hash: TreeHashType) -> Option<EncodedTransaction> {
pub fn get_transaction_by_hash(&self, hash: HashType) -> Option<EncodedTransaction> {
let block_id = self.tx_hash_to_block_map.get(&hash);
let block = block_id.map(|&id| self.get_block_at_id(id));
if let Some(Ok(block)) = block {
@ -71,7 +71,7 @@ impl SequecerBlockStore {
}
}
fn block_to_transactions_map(block: &Block) -> HashMap<TreeHashType, u64> {
fn block_to_transactions_map(block: &Block) -> HashMap<HashType, u64> {
block
.body
.transactions

View File

@ -5,7 +5,7 @@ use sequencer_core::config::AccountInitialData;
use serde_json::Value;
use common::{
TreeHashType,
HashType,
block::HashableBlockData,
rpc_primitives::{
errors::RpcError,
@ -233,7 +233,7 @@ impl JsonHandler {
let get_transaction_req = GetTransactionByHashRequest::parse(Some(request.params))?;
let bytes: Vec<u8> = hex::decode(get_transaction_req.hash)
.map_err(|_| RpcError::invalid_params("invalid hex".to_string()))?;
let hash: TreeHashType = bytes
let hash: HashType = bytes
.try_into()
.map_err(|_| RpcError::invalid_params("invalid length".to_string()))?;