Skip to content

Commit

Permalink
single time hash calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Nov 18, 2024
1 parent eaf9d6d commit 45065b2
Show file tree
Hide file tree
Showing 19 changed files with 1,272 additions and 863 deletions.
2,103 changes: 1,249 additions & 854 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions custom-pallets/anonymous-account/src/extras.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;

use parity_scale_codec::Encode;
use scale_info::prelude::vec::Vec;
use sp_io::hashing::blake2_256;

Expand All @@ -15,6 +16,20 @@ impl<T: Config> Pallet<T> {
blake2_256(&input_data)
}

pub fn calculate_hash_for_accounts(accounts: &[(T::AccountId, [u8; 64])]) -> [u8; 32] {
let mut input_data = Vec::new();

// Concatenate all account IDs into a single byte vector
for account in accounts {
let encoded_id = account.0.encode();
input_data.extend_from_slice(encoded_id.as_ref());
input_data.extend_from_slice(account.1.as_ref());
}

// Compute the hash of the combined data
blake2_256(&input_data)
}

pub fn get_slice_hash(
department_id: DepartmentId,
slice_number: u32,
Expand Down
17 changes: 8 additions & 9 deletions custom-pallets/anonymous-account/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#![cfg_attr(not(feature = "std"), no_std)]

/// Edit this file to define custom logic or remove it if it is not needed.
/// Learn more about FRAME and the core library of Substrate FRAME pallets:
/// <https://docs.substrate.io/reference/frame-pallets/>
pub use pallet::*;

#[cfg(test)]
Expand Down Expand Up @@ -164,15 +161,17 @@ pub mod pallet {

// Process accounts in the specified slice
let slice = &accounts[start_index..end_index];
let mut current_hash = [0; 32]; // Initial hash for the slice
let hash = Self::calculate_hash_for_accounts(&slice);

for (account_id, _) in slice {
let encoded_id = account_id.encode();
current_hash = Self::update_hash_incrementally(current_hash, encoded_id);
}
// let mut current_hash = [0; 32]; // Initial hash for the slice

// for (account_id, _) in slice {
// let encoded_id = account_id.encode();
// current_hash = Self::update_hash_incrementally(current_hash, encoded_id);
// }

// Store the computed hash in storage
KYCHashes::<T>::insert(department_id, slice_number, current_hash);
KYCHashes::<T>::insert(department_id, slice_number, hash);

Ok(())
}
Expand Down

0 comments on commit 45065b2

Please sign in to comment.