0 votes
1 view
in Blockchain by (11.8k points)

Given some Hash value that is generated within a substrate runtime, how do I modify or access the individual bytes of that hash?

1 Answer

0 votes
by (27.7k points)

The Hash trait Output has the AsRef and AsMut traits which allows you to interact with the hash as a byteslice ([u8]):

pub trait Hash: 'static + MaybeSerializeDebug + Clone + Eq + PartialEq {
    type Output: Member + MaybeSerializeDebug + AsRef<[u8]> + AsMut<[u8]>;

    // ... removed for brevity
}
Using the as_ref() or as_mut() on a hash will return a slice of bytes which you can use as normal

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...