@@ -4,6 +4,7 @@ use ::xcm::{
44 v4:: { Asset , AssetId , Location } ,
55 VersionedAssetId , VersionedLocation , VersionedXcm ,
66} ;
7+ use cumulus_pallet_parachain_system:: RelayChainState ;
78use cumulus_primitives_aura:: Slot ;
89use cumulus_primitives_core:: CollationInfo ;
910use frame_support:: {
@@ -15,6 +16,11 @@ use frame_support::{
1516 } ,
1617 weights:: Weight ,
1718} ;
19+ use ismp:: {
20+ consensus:: { ConsensusClientId , StateMachineHeight , StateMachineId } ,
21+ host:: StateMachine ,
22+ router:: { Request , Response } ,
23+ } ;
1824use kilt_runtime_api_did:: RawDidLinkedInfo ;
1925use kilt_support:: traits:: ItemFilter ;
2026use pallet_asset_switch:: xcm:: AccountId32ToAccountId32JunctionConverter ;
@@ -49,7 +55,7 @@ use runtime_common::{
4955 AccountId , AuthorityId , Balance , BlockNumber , DidIdentifier , Hash , Nonce ,
5056} ;
5157use sp_api:: impl_runtime_apis;
52- use sp_core:: OpaqueMetadata ;
58+ use sp_core:: { OpaqueMetadata , H256 } ;
5359use sp_inherents:: { CheckInherentsResult , InherentData } ;
5460use sp_metadata_ir:: RuntimeApiMetadataIR ;
5561use sp_runtime:: {
@@ -63,8 +69,9 @@ use crate::{
6369 kilt:: { DipProofError , DipProofRequest , NativeAndForeignAssets } ,
6470 parachain:: ConsensusHook ,
6571 xcm:: UniversalLocation ,
66- AssetSwitchPool1 , Block , BondedCurrencies , BondedFungibles , Executive , InherentDataExt , ParachainStaking ,
67- ParachainSystem , Runtime , RuntimeCall , RuntimeGenesisConfig , SessionKeys , TransactionPayment , Web3Name , VERSION ,
72+ AssetSwitchPool1 , Block , BondedCurrencies , BondedFungibles , Executive , InherentDataExt , IsmpParachain ,
73+ ParachainStaking , ParachainSystem , Runtime , RuntimeCall , RuntimeGenesisConfig , SessionKeys , TransactionPayment ,
74+ Web3Name , VERSION ,
6875} ;
6976
7077// This is necessary since by default `RUNTIME_API_VERSIONS` generated by
@@ -617,6 +624,60 @@ impl_runtime_apis! {
617624 }
618625 }
619626
627+ impl pallet_ismp_runtime_api:: IsmpRuntimeApi <Block , <Block as BlockT >:: Hash > for Runtime {
628+ fn host_state_machine( ) -> StateMachine {
629+ <Runtime as pallet_ismp:: Config >:: HostStateMachine :: get( )
630+ }
631+
632+ fn challenge_period( state_machine_id: StateMachineId ) -> Option <u64 > {
633+ pallet_ismp:: Pallet :: <Runtime >:: challenge_period( state_machine_id)
634+ }
635+
636+ /// Fetch all ISMP events in the block, should only be called from runtime-api.
637+ fn block_events( ) -> Vec <:: ismp:: events:: Event > {
638+ pallet_ismp:: Pallet :: <Runtime >:: block_events( )
639+ }
640+
641+ /// Fetch all ISMP events and their extrinsic metadata, should only be called from runtime-api.
642+ fn block_events_with_metadata( ) -> Vec <( :: ismp:: events:: Event , Option <u32 >) > {
643+ pallet_ismp:: Pallet :: <Runtime >:: block_events_with_metadata( )
644+ }
645+
646+ /// Return the scale encoded consensus state
647+ fn consensus_state( id: ConsensusClientId ) -> Option <Vec <u8 >> {
648+ pallet_ismp:: Pallet :: <Runtime >:: consensus_states( id)
649+ }
650+
651+ /// Return the timestamp this client was last updated in seconds
652+ fn state_machine_update_time( height: StateMachineHeight ) -> Option <u64 > {
653+ pallet_ismp:: Pallet :: <Runtime >:: state_machine_update_time( height)
654+ }
655+
656+ /// Return the latest height of the state machine
657+ fn latest_state_machine_height( id: StateMachineId ) -> Option <u64 > {
658+ pallet_ismp:: Pallet :: <Runtime >:: latest_state_machine_height( id)
659+ }
660+
661+ /// Get actual requests
662+ fn requests( commitments: Vec <H256 >) -> Vec <Request > {
663+ pallet_ismp:: Pallet :: <Runtime >:: requests( commitments)
664+ }
665+
666+ /// Get actual requests
667+ fn responses( commitments: Vec <H256 >) -> Vec <Response > {
668+ pallet_ismp:: Pallet :: <Runtime >:: responses( commitments)
669+ }
670+ }
671+
672+ impl ismp_parachain_runtime_api:: IsmpParachainApi <Block > for Runtime {
673+ fn para_ids( ) -> Vec <u32 > {
674+ IsmpParachain :: para_ids( )
675+ }
676+
677+ fn current_relay_chain_state( ) -> RelayChainState {
678+ IsmpParachain :: current_relay_chain_state( )
679+ }
680+ }
620681
621682 #[ cfg( feature = "runtime-benchmarks" ) ]
622683 impl frame_benchmarking:: Benchmark <Block > for Runtime {
0 commit comments