pallet_ismp_runtime_api/lib.rs
1// Copyright (c) 2025 Polytope Labs.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#![doc = include_str!("../README.md")]
17#![cfg_attr(not(feature = "std"), no_std)]
18#![allow(clippy::too_many_arguments)]
19#![deny(missing_docs)]
20
21extern crate alloc;
22
23use alloc::vec::Vec;
24use ismp::{
25 consensus::{ConsensusClientId, StateMachineHeight, StateMachineId},
26 host::StateMachine,
27 router::{Request, Response},
28};
29use polkadot_sdk::*;
30use primitive_types::H256;
31
32sp_api::decl_runtime_apis! {
33 /// Required runtime APIs needed for client subsystems like the RPC
34 pub trait IsmpRuntimeApi<Hash: codec::Codec> {
35 /// Should return the host's state machine identifier
36 fn host_state_machine() -> StateMachine;
37
38 /// Fetch all ISMP events
39 fn block_events() -> Vec<ismp::events::Event>;
40
41 /// Fetch all ISMP events and their extrinsic metadata
42 fn block_events_with_metadata() -> Vec<(ismp::events::Event, Option<u32>)>;
43
44 /// Return the scale encoded consensus state
45 fn consensus_state(id: ConsensusClientId) -> Option<Vec<u8>>;
46
47 /// Return the timestamp this client was last updated in seconds
48 fn state_machine_update_time(id: StateMachineHeight) -> Option<u64>;
49
50 /// Return the challenge period timestamp
51 fn challenge_period(id: StateMachineId) -> Option<u64>;
52
53 /// Return the latest height of the state machine
54 fn latest_state_machine_height(id: StateMachineId) -> Option<u64>;
55
56 /// Fetch the requests for the given commitments.
57 fn requests(request_commitments: Vec<H256>) -> Vec<Request>;
58
59 /// Fetch the responses for the given commitments.
60 fn responses(response_commitments: Vec<H256>) -> Vec<Response>;
61 }
62}