ghost-node/pallets/traits/src/hashing.rs
Uncle Stretch d83ee59508
let the EXODUS begin...
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2026-08-29 14:48:50 +03:00

28 lines
772 B
Rust

use sp_std::vec::Vec;
pub trait GhostHasher {
type Hash: PartialEq + Copy + AsRef<[u8]> + AsMut<[u8]>;
type HashBytes: AsRef<[u8]> + AsMut<[u8]> + TryFrom<Vec<u8>> + Default;
fn from_slice(bytes: &[u8]) -> Self::Hash {
let mut target_hash = Self::empty();
let hash_buffer = target_hash.as_mut();
let copy_len = bytes.len().min(hash_buffer.len());
hash_buffer[..copy_len].copy_from_slice(&bytes[..copy_len]);
target_hash
}
fn hash_to_bytes(hash: Self::Hash) -> Self::HashBytes {
let mut bytes = Self::HashBytes::default();
bytes.as_mut().copy_from_slice(hash.as_ref());
bytes
}
fn hash(data: &[u8]) -> Self::Hash;
fn empty() -> Self::Hash;
fn hash_len() -> usize;
}