chia-datalayer 0.42.0

DataLayer modules for Chia blockchain
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::Hash;
use chia_protocol::Bytes32;
use chia_sha2::Sha256;
use num_traits::ToBytes;

pub fn sha256_num<T: ToBytes>(input: &T) -> Hash {
    let mut hasher = Sha256::new();
    hasher.update(input.to_be_bytes());

    Hash(Bytes32::new(hasher.finalize()))
}

pub fn sha256_bytes(input: &[u8]) -> Hash {
    let mut hasher = Sha256::new();
    hasher.update(input);

    Hash(Bytes32::new(hasher.finalize()))
}