From 518348b88df8817fdf69820a27aa9aa5ff315b59 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Tue, 2 Jun 2020 09:21:12 -0400 Subject: [PATCH] impl FindAuthor for Aura (#6205) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Something compiles * compiles _and_ maintains old version * Comments * try to pass CI * Update frame/aura/src/lib.rs Co-authored-by: Bastian Köcher * Update frame/aura/src/lib.rs Co-authored-by: Bastian Köcher Co-authored-by: Bastian Köcher --- substrate/frame/aura/src/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/substrate/frame/aura/src/lib.rs b/substrate/frame/aura/src/lib.rs index d124ef0017..ca3d1f15f4 100644 --- a/substrate/frame/aura/src/lib.rs +++ b/substrate/frame/aura/src/lib.rs @@ -162,6 +162,27 @@ impl FindAuthor for Module { } } +/// We can not implement `FindAuthor` twice, because the compiler does not know if +/// `u32 == T::AuthorityId` and thus, prevents us to implement the trait twice. +#[doc(hidden)] +pub struct FindAccountFromAuthorIndex(sp_std::marker::PhantomData<(T, Inner)>); + +impl> FindAuthor + for FindAccountFromAuthorIndex +{ + fn find_author<'a, I>(digests: I) -> Option + where I: 'a + IntoIterator + { + let i = Inner::find_author(digests)?; + + let validators = >::authorities(); + validators.get(i as usize).map(|k| k.clone()) + } +} + +/// Find the authority ID of the Aura authority who authored the current block. +pub type AuraAuthorId = FindAccountFromAuthorIndex>; + impl IsMember for Module { fn is_member(authority_id: &T::AuthorityId) -> bool { Self::authorities()