2

I want add pallet-evm in my substrate node. and my substrate node use Babe instead of Aura. How can I Impl FindAuthor whih Babe ? this is the example of Aura. I want to impl it with Babe

pub struct FindAuthorTruncated<F>(PhantomData<F>);
impl<F: FindAuthor<u32>> FindAuthor<H160> for FindAuthorTruncated<F> {
    fn find_author<'a, I>(digests: I) -> Option<H160>
    where
        I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,
    {
        if let Some(author_index) = F::find_author(digests) {
            let authority_id = Aura
::authorities()[author_index as usi
ze].clone();
            return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]))
        }
        None
    }
}

1 Answer 1

1

There is not that much difference. Basically you just need to replace Aura with Babe.

pub struct FindAuthorTruncated<F>(PhantomData<F>);
impl<F: FindAuthor<u32>> FindAuthor<H160> for FindAuthorTruncated<F> {
    fn find_author<'a, I>(digests: I) -> Option<H160>
    where
        I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,
    {
        let author_index = F::find_author(digests)?;

        let authority_id = Babe
::authorities()[author_index as usi
ze].clone();
        Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]))
    }
}
1
  • H160::from_slice(&(authority_id.0).to_raw_vec()[4..24]) Should be this Commented May 4 at 16:52

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.