Add method to fetch a block's events to the RPC

This commit is contained in:
Luke Parker
2025-11-13 04:50:54 -05:00
parent 367a5769e8
commit 509bd58f4e
10 changed files with 324 additions and 70 deletions

View File

@@ -4,10 +4,13 @@
extern crate alloc;
use alloc::vec::Vec;
use serai_abi::primitives::{
crypto::{Public, SignedEmbeddedEllipticCurveKeys},
network_id::NetworkId,
balance::Balance,
use serai_abi::{
primitives::{
crypto::{Public, SignedEmbeddedEllipticCurveKeys},
network_id::NetworkId,
balance::Balance,
},
Event,
};
#[cfg(feature = "std")]
@@ -30,6 +33,7 @@ sp_api::decl_runtime_apis! {
fn build(genesis: GenesisConfig);
}
pub trait SeraiApi {
fn events() -> Vec<Vec<u8>>;
fn validators(network_id: NetworkId) -> Vec<Public>;
}
}
@@ -169,6 +173,9 @@ mod apis {
}
impl crate::SeraiApi<Block> for Runtime {
fn events() -> Vec<Vec<u8>> {
unimplemented!("runtime is only implemented when WASM")
}
fn validators(
network: serai_abi::primitives::network_id::NetworkId
) -> Vec<serai_abi::primitives::crypto::Public> {

View File

@@ -505,6 +505,9 @@ sp_api::impl_runtime_apis! {
}
impl crate::SeraiApi<Block> for Runtime {
fn events() -> Vec<Vec<u8>> {
Core::events()
}
fn validators(network: NetworkId) -> Vec<serai_abi::primitives::crypto::Public> {
// Returning the latest-decided, not latest and active, means the active set
// may fail to peer find if there isn't sufficient overlap. If a large amount reboot,