add serai rpc methods

This commit is contained in:
akildemir
2024-10-26 14:25:54 +03:00
parent f3d20e60b3
commit 21589936a9
12 changed files with 398 additions and 40 deletions

View File

@@ -27,6 +27,7 @@ scale-info = { version = "2", default-features = false, features = ["derive"] }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-io = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-api = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-application-crypto = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-session = { git = "https://github.com/serai-dex/substrate", default-features = false }
@@ -52,6 +53,7 @@ std = [
"sp-core/std",
"sp-io/std",
"sp-std/std",
"sp-api/std",
"sp-application-crypto/std",
"sp-runtime/std",
"sp-session/std",

View File

@@ -943,6 +943,14 @@ pub mod pallet {
false
}
}
/// Returns the external network key for a given external network
pub fn external_network_key(network: ExternalNetworkId) -> Option<Vec<u8>> {
let current_session = Self::session(NetworkId::from(network))?;
let keys = Keys::<T>::get(ExternalValidatorSet { network, session: current_session })?;
Some(keys.1.into_inner())
}
}
#[pallet::call]
@@ -1295,4 +1303,17 @@ pub mod pallet {
}
}
sp_api::decl_runtime_apis! {
#[api_version(1)]
pub trait ValidatorSetsApi {
/// Returns the validator set for a given network.
fn validators(network_id: NetworkId) -> Vec<PublicKey>;
/// Returns the external network key for a given external network.
fn external_network_key(
network: ExternalNetworkId,
) -> Option<Vec<u8>>;
}
}
pub use pallet::*;