2

I'm trying to get the length of hash. Currently, I tried to make use of len_bytes() like in this docs. But I encountered an error like the below image. Please help to solve this.! Thanks in advanced. enter image description here

5
  • Depending on how your pallet is configured, T::Hash::len_bytes() should work. Commented Jul 19, 2022 at 12:09
  • Can you make it clearer? I'm very new on this @OliverTale-Yazdi
    – shyoski
    Commented Jul 19, 2022 at 12:59
  • please provide more context to your question... how is your Hash type configured? what are you trying to achieve? Commented Jul 19, 2022 at 20:44
  • shot in the dark: try dereferencing dna: (*dna).len_bytes()
    – Squirrel
    Commented Jul 21, 2022 at 10:30
  • You dont even need an instance of the type. The length of the hash output is fixed in the type, as written above T::Hash::len_bytes() returns it. Commented Aug 7, 2022 at 13:26

1 Answer 1

1

If your T::Hash comes from frame_system::Config here is the def:

/// The output of the `Hashing` function.
type Hash: Parameter
    + Member
    + MaybeSerializeDeserialize
    + Debug
    + MaybeDisplay
    + SimpleBitOps
    + Ord
    + Default
    + Copy
    + CheckEqual
    + sp_std::hash::Hash
    + AsRef<[u8]>
    + AsMut<[u8]>
    + MaybeMallocSizeOf
    + MaxEncodedLen;

Then you could simply do:

dna.as_ref().len()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.