substrate_api_client/api/runtime_api/
session_keys.rs1use super::{RuntimeApi, RuntimeApiClient};
15use crate::{api::Result, rpc::Request};
16use ac_primitives::config::Config;
17#[cfg(all(not(feature = "sync-api"), not(feature = "std")))]
18use alloc::boxed::Box;
19use alloc::{vec, vec::Vec};
20use codec::Encode;
21use sp_core::{crypto::KeyTypeId, Bytes};
22
23#[maybe_async::maybe_async(?Send)]
24pub trait SessionKeysApi: RuntimeApi {
25 type KeyTypeId;
26
27 #[allow(clippy::type_complexity)]
29 async fn decode_session_keys(
30 &self,
31 encoded: Bytes,
32 at_block: Option<Self::Hash>,
33 ) -> Result<Option<Vec<(Bytes, Self::KeyTypeId)>>>;
34
35 async fn generate_session_keys(
37 &self,
38 seed: Option<Bytes>,
39 at_block: Option<Self::Hash>,
40 ) -> Result<Bytes>;
41}
42
43#[maybe_async::maybe_async(?Send)]
44impl<T, Client> SessionKeysApi for RuntimeApiClient<T, Client>
45where
46 T: Config,
47 Client: Request,
48{
49 type KeyTypeId = KeyTypeId;
50
51 async fn decode_session_keys(
52 &self,
53 encoded: Bytes,
54 at_block: Option<Self::Hash>,
55 ) -> Result<Option<Vec<(Bytes, Self::KeyTypeId)>>> {
56 self.runtime_call("SessionKeys_decode_session_keys", vec![encoded.0], at_block)
57 .await
58 }
59
60 async fn generate_session_keys(
61 &self,
62 seed: Option<Bytes>,
63 at_block: Option<Self::Hash>,
64 ) -> Result<Bytes> {
65 self.runtime_call("SessionKeys_generate_session_keys", vec![seed.encode()], at_block)
66 .await
67 }
68}