Skip to content

Commit 57fb554

Browse files
JoshOrndorffbkchr
andauthored
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 <[email protected]> * Update frame/aura/src/lib.rs Co-authored-by: Bastian Köcher <[email protected]> Co-authored-by: Bastian Köcher <[email protected]>
1 parent 1db6c65 commit 57fb554

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,27 @@ impl<T: Trait> FindAuthor<u32> for Module<T> {
162162
}
163163
}
164164

165+
/// We can not implement `FindAuthor` twice, because the compiler does not know if
166+
/// `u32 == T::AuthorityId` and thus, prevents us to implement the trait twice.
167+
#[doc(hidden)]
168+
pub struct FindAccountFromAuthorIndex<T, Inner>(sp_std::marker::PhantomData<(T, Inner)>);
169+
170+
impl<T: Trait, Inner: FindAuthor<u32>> FindAuthor<T::AuthorityId>
171+
for FindAccountFromAuthorIndex<T, Inner>
172+
{
173+
fn find_author<'a, I>(digests: I) -> Option<T::AuthorityId>
174+
where I: 'a + IntoIterator<Item=(ConsensusEngineId, &'a [u8])>
175+
{
176+
let i = Inner::find_author(digests)?;
177+
178+
let validators = <Module<T>>::authorities();
179+
validators.get(i as usize).map(|k| k.clone())
180+
}
181+
}
182+
183+
/// Find the authority ID of the Aura authority who authored the current block.
184+
pub type AuraAuthorId<T> = FindAccountFromAuthorIndex<T, Module<T>>;
185+
165186
impl<T: Trait> IsMember<T::AuthorityId> for Module<T> {
166187
fn is_member(authority_id: &T::AuthorityId) -> bool {
167188
Self::authorities()

0 commit comments

Comments
 (0)