Skip to content

Commit c1e9ed6

Browse files
committed
Add ibc_query_client_connections RPC
1 parent 3fc6cf6 commit c1e9ed6

File tree

7 files changed

+54
-3
lines changed

7 files changed

+54
-3
lines changed

core/src/ibc/connection_03/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ pub fn client_connections_path(client_id: &str) -> String {
2727

2828
pub use manager::Manager;
2929
pub use types::ConnectionEnd;
30+
pub use types::ConnectionIdentifiersInClient;
3031
pub use types::ConnectionState;

core/src/ibc/connection_03/types.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ impl ConnectionIdentifiersInClient {
6666
pub fn add(&mut self, identifier: Identifier) {
6767
self.0.push(identifier);
6868
}
69+
70+
pub fn into_vec(self) -> Vec<Identifier> {
71+
self.0
72+
}
6973
}
7074

7175
#[cfg(test)]

core/src/ibc/querier/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ impl DebugName for ibc::client_02::types::ConsensusState {
4545
}
4646
}
4747

48+
impl DebugName for ibc::connection_03::types::ConnectionIdentifiersInClient {
49+
fn debug_name() -> &'static str {
50+
"ConnectionIdentifiersInClient"
51+
}
52+
}
53+
4854
/// Queries the path and returns the result in decoded struct
4955
pub fn query<T>(ctx: &dyn ibc::Context, path: &CommitmentPath) -> Option<T>
5056
where
@@ -89,3 +95,9 @@ pub fn path_connection_end(id: IdentifierSlice) -> CommitmentPath {
8995
raw: ibc::connection_03::path(id),
9096
}
9197
}
98+
99+
pub fn path_connection_identifiers(client_id: IdentifierSlice) -> CommitmentPath {
100+
CommitmentPath {
101+
raw: ibc::connection_03::client_connections_path(client_id),
102+
}
103+
}

rpc/src/v1/impls/ibc.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
use super::super::errors;
1818
use super::super::traits::IBC;
19-
use super::super::types::{ClientState, ConnectionEnd, ConsensusState, IBCQuery};
19+
use super::super::types::{ClientState, ConnectionEnd, ConnectionIdentifiersInClient, ConsensusState, IBCQuery};
2020
use ccore::ibc;
2121
use ccore::ibc::querier;
2222
use ccore::{BlockChainClient, BlockId, StateInfo};
@@ -151,4 +151,29 @@ where
151151
};
152152
Ok(Some(response))
153153
}
154+
155+
fn query_client_connections(
156+
&self,
157+
client_identifier: String,
158+
block_number: Option<u64>,
159+
) -> Result<Option<IBCQuery<ConnectionIdentifiersInClient>>> {
160+
let block_id = block_number.map(BlockId::Number).unwrap_or(BlockId::Latest);
161+
let mut state = self.client.state_at(block_id).ok_or_else(errors::state_not_exist)?;
162+
let block_number = match self.client.block_number(&block_id) {
163+
None => return Ok(None),
164+
Some(block_number) => block_number,
165+
};
166+
167+
let context = ibc::context::TopLevelContext::new(&mut state, block_number);
168+
let path = querier::path_connection_identifiers(&client_identifier);
169+
let connections_in_client: Option<ibc::connection_03::ConnectionIdentifiersInClient> =
170+
querier::query(&context, &path);
171+
172+
let response = IBCQuery {
173+
number: block_number,
174+
data: connections_in_client.map(|from_core| from_core.into_vec()),
175+
proof: querier::make_proof(&context, &path),
176+
};
177+
Ok(Some(response))
178+
}
154179
}

rpc/src/v1/traits/ibc.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

1717
use super::super::types::IBCQuery;
18-
use super::super::types::{ClientState, ConnectionEnd, ConsensusState};
18+
use super::super::types::{ClientState, ConnectionEnd, ConnectionIdentifiersInClient, ConsensusState};
1919
use jsonrpc_core::Result;
2020
use primitives::Bytes;
2121

@@ -46,4 +46,11 @@ pub trait IBC {
4646
identifier: String,
4747
block_number: Option<u64>,
4848
) -> Result<Option<IBCQuery<ConnectionEnd>>>;
49+
50+
#[rpc(name = "ibc_query_client_connections")]
51+
fn query_client_connections(
52+
&self,
53+
client_identifier: String,
54+
block_number: Option<u64>,
55+
) -> Result<Option<IBCQuery<ConnectionIdentifiersInClient>>>;
4956
}

rpc/src/v1/types/ibc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,5 @@ impl ConnectionEnd {
113113
}
114114
}
115115
}
116+
117+
pub type ConnectionIdentifiersInClient = Vec<String>;

rpc/src/v1/types/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ mod work;
2525
pub use self::action::{Action, ActionWithTracker};
2626
pub use self::block::Block;
2727
pub use self::block::BlockNumberAndHash;
28-
pub use self::ibc::{ClientState, ConnectionEnd, ConsensusState, IBCQuery};
28+
pub use self::ibc::{ClientState, ConnectionEnd, ConnectionIdentifiersInClient, ConsensusState, IBCQuery};
2929
pub use self::mem_pool::MemPoolMinFees;
3030
pub use self::transaction::{PendingTransactions, Transaction};
3131
pub use self::unsigned_transaction::UnsignedTransaction;

0 commit comments

Comments
 (0)