Skip to content

Commit fa1018a

Browse files
authored
feat: http headers for Tendermint RPC client (#644)
* add rpc_header * use tm HttpClient over reqwest * use CanQueryAbci * use prost::Message derive * fix string type in proto message * avoid unwrap * use struct for header name and value * fix compile
1 parent 0352fec commit fa1018a

File tree

19 files changed

+117
-292
lines changed

19 files changed

+117
-292
lines changed

Cargo.lock

Lines changed: 16 additions & 201 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ num-bigint = { version = "0.4" }
9191
num-rational = { version = "0.4.1" }
9292
prost = { version = "0.13.3" }
9393
prost-types = { version = "0.13.3" }
94-
reqwest = { version = "0.12.9", features = [ "json" ] }
94+
reqwest = { version = "0.11.27", features = [ "json" ] }
9595
ripemd = { version = "0.1.3" }
9696
serde = { version = "1.0.214" }
9797
serde_derive = { version = "1.0.104" }

crates/cli/cli/src/commands/query/channel/ends.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ impl CommandRunner<HermesApp> for QueryChannelEnds {
9797
let channel_end_path = format!("channelEnds/ports/{port_id}/channels/{channel_id}");
9898

9999
let channel_end_bytes: Vec<u8> = chain
100-
.query_abci(IBC_QUERY_PATH, channel_end_path.as_bytes(), &query_height)
100+
.query_abci(
101+
IBC_QUERY_PATH,
102+
channel_end_path.as_bytes(),
103+
Some(&query_height),
104+
)
101105
.await?
102106
.ok_or_else(|| {
103107
HermesApp::raise_error(format!("channel not found: {channel_id}/{port_id}"))
@@ -135,7 +139,11 @@ impl CommandRunner<HermesApp> for QueryChannelEnds {
135139
let client_state_path = format!("clients/{client_id}/clientState");
136140

137141
let client_state_bytes = chain
138-
.query_abci(IBC_QUERY_PATH, client_state_path.as_bytes(), &query_height)
142+
.query_abci(
143+
IBC_QUERY_PATH,
144+
client_state_path.as_bytes(),
145+
Some(&query_height),
146+
)
139147
.await?
140148
.ok_or_else(|| {
141149
HermesApp::raise_error(format!("client state not found: {client_id}"))

crates/cosmos/cosmos-chain-components/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ hermes-cosmos-encoding-components = { workspace = true }
1919
hermes-comet-light-client-components = { workspace = true }
2020
hermes-comet-light-client-context = { workspace = true }
2121

22-
ibc = { workspace = true }
23-
ibc-proto = { workspace = true, features = [ "client", "transport" ] }
22+
ibc = { workspace = true, features = [ "serde" ] }
23+
ibc-proto = { workspace = true, features = [ "serde", "client", "transport" ] }
2424
ibc-client-tendermint = { workspace = true }
2525
tendermint = { workspace = true, features = [ "secp256k1" ] }
2626
tendermint-light-client = { workspace = true }

crates/cosmos/cosmos-chain-components/src/impls/queries/abci.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,17 @@ where
4141
chain: &Chain,
4242
path: &str,
4343
data: &[u8],
44-
height: &Height,
44+
height: Option<&Height>,
4545
) -> Result<Option<Vec<u8>>, Chain::Error> {
46-
let tm_height =
47-
TendermintHeight::try_from(height.revision_height()).map_err(Chain::raise_error)?;
46+
let tm_height = height
47+
.map(|height| {
48+
TendermintHeight::try_from(height.revision_height()).map_err(Chain::raise_error)
49+
})
50+
.transpose()?;
4851

4952
let response = chain
5053
.rpc_client()
51-
.abci_query(Some(path.to_owned()), data, Some(tm_height), false)
54+
.abci_query(Some(path.to_owned()), data, tm_height, false)
5255
.await
5356
.map_err(Chain::raise_error)?;
5457

@@ -119,7 +122,7 @@ where
119122
chain: &Chain,
120123
path: &str,
121124
data: &[u8],
122-
height: &Chain::Height,
125+
height: Option<&Chain::Height>,
123126
) -> Result<Option<Vec<u8>>, Chain::Error> {
124127
chain
125128
.perform_with_retry("query_abci", 5, async || {

crates/cosmos/cosmos-chain-components/src/impls/queries/chain_id.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ where
4545
let channel_end_path = format!("channelEnds/ports/{port_id}/channels/{channel_id}");
4646

4747
let channel_end_bytes = chain
48-
.query_abci(IBC_QUERY_PATH, channel_end_path.as_bytes(), &latest_height)
48+
.query_abci(
49+
IBC_QUERY_PATH,
50+
channel_end_path.as_bytes(),
51+
Some(&latest_height),
52+
)
4953
.await?
5054
.ok_or_else(|| {
5155
Chain::raise_error(format!("channel not found: {channel_id}/{port_id}"))
@@ -71,7 +75,11 @@ where
7175
let connection_path = format!("connections/{connection_id}");
7276

7377
let connnection_end_bytes = chain
74-
.query_abci(IBC_QUERY_PATH, connection_path.as_bytes(), &latest_height)
78+
.query_abci(
79+
IBC_QUERY_PATH,
80+
connection_path.as_bytes(),
81+
Some(&latest_height),
82+
)
7583
.await?
7684
.ok_or_else(|| Chain::raise_error(format!("connection not found: {connection_id}")))?;
7785

crates/cosmos/cosmos-chain-components/src/impls/queries/channel_end.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ where
3333
let channel_end_path = format!("channelEnds/ports/{port_id}/channels/{channel_id}");
3434

3535
let channel_end_bytes = chain
36-
.query_abci(IBC_QUERY_PATH, channel_end_path.as_bytes(), height)
36+
.query_abci(IBC_QUERY_PATH, channel_end_path.as_bytes(), Some(height))
3737
.await?
3838
.ok_or_else(|| {
3939
Chain::raise_error(format!("channel not found: {channel_id}/{port_id}"))

crates/cosmos/cosmos-chain-components/src/impls/queries/client_state.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ where
4141
let client_state_path = format!("clients/{client_id}/clientState");
4242

4343
let client_state_bytes = chain
44-
.query_abci(IBC_QUERY_PATH, client_state_path.as_bytes(), height)
44+
.query_abci(IBC_QUERY_PATH, client_state_path.as_bytes(), Some(height))
4545
.await?
4646
.ok_or_else(|| Chain::raise_error(format!("client state not found: {client_id}")))?;
4747

@@ -108,7 +108,11 @@ where
108108
let data = prost::Message::encode_to_vec(&request);
109109

110110
let response = chain
111-
.query_abci("/ibc.core.client.v1.Query/ClientStates", &data, height)
111+
.query_abci(
112+
"/ibc.core.client.v1.Query/ClientStates",
113+
&data,
114+
Some(height),
115+
)
112116
.await?
113117
.ok_or_else(|| Chain::raise_error("failed to query for client states"))?;
114118

crates/cosmos/cosmos-chain-components/src/impls/queries/connection_end.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ where
3333
let connection_path = format!("connections/{connection_id}");
3434

3535
let connnection_end_bytes = chain
36-
.query_abci(IBC_QUERY_PATH, connection_path.as_bytes(), height)
36+
.query_abci(IBC_QUERY_PATH, connection_path.as_bytes(), Some(height))
3737
.await?
3838
.ok_or_else(|| {
3939
Chain::raise_error(format!("connection end not found: {connection_id}"))

crates/cosmos/cosmos-chain-components/src/impls/queries/consensus_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ where
4141
.query_abci(
4242
IBC_QUERY_PATH,
4343
consensus_state_path.as_bytes(),
44-
query_height,
44+
Some(query_height),
4545
)
4646
.await?
4747
.ok_or_else(|| Chain::raise_error(format!("consensus state not found: {client_id}")))?;

0 commit comments

Comments
 (0)