I have a hash string "0xf8dd02cc2a3174933fac4e87d7f6360c3cc67167db105b28d0bc434a60674e49"
. How can i convert back to H256.
I used function below but it return difference H256 0xa8fb46593dfc218a4de6fcf14e0c9baa4bcf947b953c181689015793883b3a1d
let hex_string = "0xf8dd02cc2a3174933fac4e87d7f6360c3cc67167db105b28d0bc434a60674e49".as_bytes().to_vec();
info!("{:?}", hex_string);
let hex_string_hash = hash::<Runtime>(&hex_string);
info!("{:?}", hex_string_hash);
pub fn hash<Runtime>(data: &[u8]) -> H256
where
Runtime: frame_system::Config,
H256: From<<Runtime as frame_system::Config>::Hash>,
{
<Runtime as frame_system::Config>::Hashing::hash(data).into()
}
Edit: As aurevoirxavier answer. I have updated my code like this:
use primitive_types::H256;
fn main() {
let hex = "0xf8dd02cc2a3174933fac4e87d7f6360c3cc67167db105b28d0bc434a60674e49";
match array_bytes::hex_n_into::<H256, 32>(hex) {
Ok(h256) => {
println!("{:?}", h256);
}
_ => (),
}
}
let hex_string_hash = hash::<Runtime>(&hex_string.into());