|
16 | 16 |
|
17 | 17 | use super::super::errors; |
18 | 18 | use super::super::traits::IBC; |
19 | | -use super::super::types::{ClientState, ConnectionEnd, ConsensusState, IBCQuery}; |
| 19 | +use super::super::types::{ClientState, ConnectionEnd, ConnectionIdentifiersInClient, ConsensusState, IBCQuery}; |
20 | 20 | use ccore::ibc; |
21 | 21 | use ccore::ibc::querier; |
22 | 22 | use ccore::{BlockChainClient, BlockId, StateInfo}; |
@@ -151,4 +151,29 @@ where |
151 | 151 | }; |
152 | 152 | Ok(Some(response)) |
153 | 153 | } |
| 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 | + } |
154 | 179 | } |
0 commit comments