Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Blockchain by (12.7k 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 (29.5k 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

Browse Categories