mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Expand validator sets API with the rest of the events and some getters
We could've added a storage API, and fetched fields that way, except we want the storage to be opaque. That meant we needed to add the RPC routes to the node, which also simplifies other people writing RPC code and fetching these fields. Then the node could've used the storage API, except a lot of the storage in validator-sets is marked opaque and to only be read via functions, so extending the runtime made the most sense.
This commit is contained in:
@@ -9,7 +9,7 @@ use serai_abi::{
|
||||
primitives::{
|
||||
network_id::{ExternalNetworkId, NetworkId},
|
||||
balance::{Amount, ExternalBalance},
|
||||
validator_sets::ValidatorSet,
|
||||
validator_sets::{Session, ExternalValidatorSet, ValidatorSet},
|
||||
address::SeraiAddress,
|
||||
},
|
||||
SubstrateHeader as Header, SubstrateBlock,
|
||||
@@ -522,6 +522,21 @@ sp_api::impl_runtime_apis! {
|
||||
.map(|validator| validator.0.into())
|
||||
.collect()
|
||||
}
|
||||
fn current_session(network: NetworkId) -> Option<Session> {
|
||||
ValidatorSets::current_session(network)
|
||||
}
|
||||
fn current_stake(network: NetworkId) -> Option<Amount> {
|
||||
ValidatorSets::stake_for_current_validator_set(network)
|
||||
}
|
||||
fn keys(set: ExternalValidatorSet) -> Option<serai_abi::primitives::crypto::KeyPair> {
|
||||
ValidatorSets::oraclization_key(set)
|
||||
.and_then(|oraclization_key| {
|
||||
ValidatorSets::external_key(set)
|
||||
.map(|external_key| {
|
||||
serai_abi::primitives::crypto::KeyPair(oraclization_key.into(), external_key)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user