From b93c0aa390e737d9b1ed012aff770682f0ea0745 Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Fri, 17 Oct 2025 16:04:09 -0300 Subject: [PATCH] rename TreeHashType to HashType --- common/src/lib.rs | 11 ++++------- common/src/transaction.rs | 4 ++-- key_protocol/src/key_management/secret_holders.rs | 8 ++++---- sequencer_core/src/lib.rs | 4 ++-- sequencer_core/src/sequencer_store/block_store.rs | 8 ++++---- sequencer_rpc/src/process.rs | 4 ++-- 6 files changed, 18 insertions(+), 21 deletions(-) diff --git a/common/src/lib.rs b/common/src/lib.rs index c73b7a9..a2f9156 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -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; #[derive(Debug, Clone)] @@ -21,19 +21,16 @@ pub type CommitmentHashType = Vec; 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); - ::from(hasher.finalize_fixed()) + ::from(hasher.finalize_fixed()) } } -///Account id on blockchain -pub type AccountId = TreeHashType; - #[derive(Debug, Clone, Deserialize)] pub struct SequencerRpcError { pub jsonrpc: String, diff --git a/common/src/transaction.rs b/common/src/transaction.rs index 610b229..3d49556 100644 --- a/common/src/transaction.rs +++ b/common/src/transaction.rs @@ -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(); diff --git a/key_protocol/src/key_management/secret_holders.rs b/key_protocol/src/key_management/secret_holders.rs index 89da95c..57dea90 100644 --- a/key_protocol/src/key_management/secret_holders.rs +++ b/key_protocol/src/key_management/secret_holders.rs @@ -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]); - ::from(hasher.finalize_fixed()) + ::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]); - ::from(hasher.finalize_fixed()) + ::from(hasher.finalize_fixed()) } pub fn produce_private_key_holder(&self) -> PrivateKeyHolder { diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index 454faec..4459371 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -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 { diff --git a/sequencer_core/src/sequencer_store/block_store.rs b/sequencer_core/src/sequencer_store/block_store.rs index 42e4ec5..e1dbb2b 100644 --- a/sequencer_core/src/sequencer_store/block_store.rs +++ b/sequencer_core/src/sequencer_store/block_store.rs @@ -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, + tx_hash_to_block_map: HashMap, 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 { + pub fn get_transaction_by_hash(&self, hash: HashType) -> Option { 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 { +fn block_to_transactions_map(block: &Block) -> HashMap { block .body .transactions diff --git a/sequencer_rpc/src/process.rs b/sequencer_rpc/src/process.rs index f376f94..584b097 100644 --- a/sequencer_rpc/src/process.rs +++ b/sequencer_rpc/src/process.rs @@ -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 = 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()))?;