impl FindAuthor<T::AuthorityId> for Aura (#6205)

* Something compiles

* compiles _and_ maintains old version

* Comments

* try to pass CI

* Update frame/aura/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/aura/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Joshy Orndorff
2020-06-02 09:21:12 -04:00
committed by GitHub
parent 4b6537fbba
commit 518348b88d
+21
View File
@@ -162,6 +162,27 @@ impl<T: Trait> FindAuthor<u32> for Module<T> {
}
}
/// 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<T, Inner>(sp_std::marker::PhantomData<(T, Inner)>);
impl<T: Trait, Inner: FindAuthor<u32>> FindAuthor<T::AuthorityId>
for FindAccountFromAuthorIndex<T, Inner>
{
fn find_author<'a, I>(digests: I) -> Option<T::AuthorityId>
where I: 'a + IntoIterator<Item=(ConsensusEngineId, &'a [u8])>
{
let i = Inner::find_author(digests)?;
let validators = <Module<T>>::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<T> = FindAccountFromAuthorIndex<T, Module<T>>;
impl<T: Trait> IsMember<T::AuthorityId> for Module<T> {
fn is_member(authority_id: &T::AuthorityId) -> bool {
Self::authorities()