0

I'm trying to use frame_support::traits::FindAuthor in my pallet for a custom logic.

I imported the traits and I tried to loose coupling it.

this is my config:

#[pallet::config]
    pub trait Config: frame_system::Config {
        /// Because this pallet emits events, it depends on the runtime's definition of an event.
        type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;

        type FindAuthor: FindAuthor<Self::AccountId>;
    }

So now I want to use find_author() function of this trait

let author = T::FindAuthor::find_author(digests???);

but I'm stuck with the digests param, I don't understand what "digests" means and how to pass it in order to get the author.

1 Answer 1

1

These are pre-runtime digests, which as the documentation says are

messages from the consensus engine to the runtime, although the consensus engine can (and should) read them itself to avoid code and state duplication. It is erroneous for a runtime to produce these, but this is not (yet) checked.

You can obtain digests for the current block like this:

let block_digest = <frame_system::Pallet<T>>::digest();
let digests = block_digest.logs.iter().filter_map(|d| d.as_pre_runtime());
let author = T::FindAuthor::find_author(digests);
1
  • Thank you, it works fine!
    – viac92
    Oct 6, 2022 at 11:59

Your Answer

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

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