use primitive_types::H256;
use std::str::FromStr;

use crate::common::hash::Hash256;
pub fn sha256_hex(data: &[u8]) -> String {
    sha256::digest(data)
}

pub trait IntoHash256 {
    fn hash_256(&self) -> Hash256;
}

impl<T: core::convert::AsRef<[u8]>> IntoHash256 for T {
    fn hash_256(&self) -> Hash256 {
        H256::from_str(&sha256_hex(self.as_ref())).unwrap().into()
    }
}
