#![cfg_attr(not(feature = "std"), no_std)]
use sp_std::vec::Vec;
#[cfg(feature = "std")]
use sp_runtime::{generic::BlockId, traits::Block as BlockT};
#[cfg(feature = "std")]
use sp_api::ProvideRuntimeApi;
use sp_core::crypto::KeyTypeId;
sp_api::decl_runtime_apis! {
pub trait SessionKeys {
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8>;
fn decode_session_keys(encoded: Vec<u8>) -> Option<Vec<(Vec<u8>, KeyTypeId)>>;
}
}
#[cfg(feature = "std")]
pub fn generate_initial_session_keys<Block, T>(
client: std::sync::Arc<T>,
at: &BlockId<Block>,
seeds: Vec<String>,
) -> Result<(), sp_api::ApiErrorFor<T, Block>>
where
Block: BlockT,
T: ProvideRuntimeApi<Block>,
T::Api: SessionKeys<Block>,
{
let runtime_api = client.runtime_api();
for seed in seeds {
runtime_api.generate_session_keys(at, Some(seed.as_bytes().to_vec()))?;
}
Ok(())
}