ibc_grpc_server/
lib.rs

1pub mod error;
2mod service;
3pub mod types;
4
5use ibc::core::ics02_client::{client_state::ClientState, consensus_state::ConsensusState};
6use ibc::core::ics03_connection::connection::ConnectionEnd;
7use ibc::core::ics04_channel::channel::ChannelEnd;
8use ibc::core::ics04_channel::commitment::{AcknowledgementCommitment, PacketCommitment};
9use ibc::core::ics24_host::identifier::ConnectionId;
10use ibc::core::ics24_host::path::{
11    AcksPath, ChannelEndsPath, ClientConnectionsPath, ClientConsensusStatePath, ClientStatePath,
12    CommitmentsPath, ConnectionsPath, ReceiptsPath,
13};
14
15use crate::error::ServerError;
16use crate::service::IbcGrpcService;
17use crate::types::{Path, StoreHeight};
18
19pub type Result<T> = std::result::Result<T, ServerError>;
20
21pub async fn run_ibc_grpc<Store>(store: Store, addr: String)
22where
23    Store: IbcStore + 'static,
24{
25    log::info!("ibc start");
26    IbcGrpcService::new(store, addr).run().await;
27}
28
29pub trait IbcStore: Sync + Send {
30    fn get_client_state(
31        &self,
32        height: StoreHeight,
33        path: &ClientStatePath,
34    ) -> Result<Option<Box<dyn ClientState>>>;
35
36    fn get_consensus_state(
37        &self,
38        height: StoreHeight,
39        path: &ClientConsensusStatePath,
40    ) -> Result<Option<Box<dyn ConsensusState>>>;
41
42    fn get_connection_end(
43        &self,
44        height: StoreHeight,
45        path: &ConnectionsPath,
46    ) -> Result<Option<ConnectionEnd>>;
47
48    fn get_connection_ids(
49        &self,
50        height: StoreHeight,
51        path: &ClientConnectionsPath,
52    ) -> Result<Vec<ConnectionId>>;
53
54    fn get_acknowledgement_commitment(
55        &self,
56        height: StoreHeight,
57        path: &AcksPath,
58    ) -> Result<Option<AcknowledgementCommitment>>;
59
60    fn get_channel_end(
61        &self,
62        height: StoreHeight,
63        path: &ChannelEndsPath,
64    ) -> Result<Option<ChannelEnd>>;
65
66    fn get_opt(&self, height: StoreHeight, path: &ReceiptsPath) -> Result<Option<()>>;
67
68    fn get_packet_commitment(
69        &self,
70        height: StoreHeight,
71        path: &CommitmentsPath,
72    ) -> Result<Option<PacketCommitment>>;
73
74    fn get_paths_by_prefix(&self, key_prefix: &Path) -> Result<Vec<Path>>;
75
76    fn current_height(&self) -> u64;
77}