mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 04:01:10 +00:00
Implement sessions.
This commit is contained in:
@@ -1,35 +1,26 @@
|
||||
use runtime_support::Vec;
|
||||
use keyedvec::KeyedVec;
|
||||
use storage::Storage;
|
||||
use primitives::{AccountID, SessionKey, BlockNumber};
|
||||
use runtime::{system, staking};
|
||||
use storagevec::StorageVec;
|
||||
use primitives::SessionKey;
|
||||
|
||||
pub fn set_authority(index: u32, authority: AccountID) {
|
||||
authority.store(&index.to_keyed_vec(b"con\0aut\0"));
|
||||
}
|
||||
|
||||
fn authority(index: u32) -> AccountID {
|
||||
Storage::into(&index.to_keyed_vec(b"con\0aut\0"))
|
||||
}
|
||||
|
||||
pub fn set_authority_count(count: u32) {
|
||||
(count..authority_count()).for_each(|i| set_authority(i, SessionKey::default()));
|
||||
count.store(b"con\0aut\0len");
|
||||
}
|
||||
|
||||
fn authority_count() -> u32 {
|
||||
Storage::into(b"con\0aut\0len")
|
||||
struct AuthorityStorageVec {}
|
||||
impl StorageVec for AuthorityStorageVec {
|
||||
type Item = SessionKey;
|
||||
const PREFIX: &'static[u8] = b"con\0aut\0";
|
||||
}
|
||||
|
||||
/// Get the current set of authorities. These are the session keys.
|
||||
pub fn authorities() -> Vec<AccountID> {
|
||||
(0..authority_count()).into_iter().map(authority).collect()
|
||||
pub fn authorities() -> Vec<SessionKey> {
|
||||
AuthorityStorageVec::items()
|
||||
}
|
||||
|
||||
/// Set the current set of authorities' session keys.
|
||||
///
|
||||
/// Called by `next_session` only.
|
||||
pub fn set_authorities(authorities: &[AccountID]) {
|
||||
set_authority_count(authorities.len() as u32);
|
||||
authorities.iter().enumerate().for_each(|(v, &i)| set_authority(v as u32, i));
|
||||
pub fn set_authorities(authorities: &[SessionKey]) {
|
||||
AuthorityStorageVec::set_items(authorities);
|
||||
}
|
||||
|
||||
/// Set a single authority by index.
|
||||
pub fn set_authority(index: u32, key: &SessionKey) {
|
||||
AuthorityStorageVec::set_item(index, key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user