]) -> Option<&AuthorityId
> {
if authorities.is_empty() {
return None
}
let idx = *slot % (authorities.len() as u64);
assert!(
idx <= usize::MAX as u64,
"It is impossible to have a vector with length beyond the address space; qed",
);
let current_author = authorities.get(idx as usize).expect(
"authorities not empty; index constrained to list length;this is a valid index; qed",
);
Some(current_author)
}
/// Attempt to claim a slot using a keystore.
///
/// This returns `None` if the slot author is not locally controlled, and `Some` if it is,
/// with the public key of the slot author.
pub async fn claim_slot ],
keystore: &KeystorePtr,
) -> Option (slot, authorities);
expected_author.and_then(|p| {
if keystore.has_keys(&[(p.to_raw_vec(), sp_application_crypto::key_types::AURA)]) {
Some(p.clone())
} else {
None
}
})
}
/// Produce the pre-runtime digest containing the slot info.
///
/// This is intended to be put into the block header prior to runtime execution,
/// so the runtime can read the slot in this way.
pub fn pre_digest ],
) -> Result<(B::Header, Slot, DigestItem), SealVerificationError (slot, authorities).ok_or(SealVerificationError::SlotAuthorNotFound)?;
let pre_hash = header.hash();
if P::verify(&sig, pre_hash.as_ref(), expected_author) {
Ok((header, slot, seal))
} else {
Err(SealVerificationError::BadSignature)
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use sp_keyring::sr25519::Keyring;
#[test]
fn authorities_call_works() {
let client = substrate_test_runtime_client::new();
assert_eq!(client.chain_info().best_number, 0);
assert_eq!(
fetch_authorities_with_compatibility_mode(
&client,
client.chain_info().best_hash,
1,
&CompatibilityMode::None
)
.unwrap(),
vec![
Keyring::Alice.public().into(),
Keyring::Bob.public().into(),
Keyring::Charlie.public().into()
]
);
assert_eq!(
fetch_authorities(&client, client.chain_info().best_hash).unwrap(),
vec![
Keyring::Alice.public().into(),
Keyring::Bob.public().into(),
Keyring::Charlie.public().into()
]
);
}
}