Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cosmos-sdk-rs: make Tx::find_by_hash use the /tx endpoint #116

Merged
merged 2 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cosmrs/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub async fn poll_for_first_block(rpc_client: &rpc::HttpClient) {
}

/// Wait for a transaction with the given hash to appear in the blockchain
pub async fn poll_for_tx(rpc_client: &rpc::HttpClient, tx_hash: &tx::Hash) -> Tx {
pub async fn poll_for_tx(rpc_client: &rpc::HttpClient, tx_hash: tx::Hash) -> Tx {
let attempts = 5;

for _ in 0..attempts {
Expand Down
16 changes: 3 additions & 13 deletions cosmrs/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,12 @@ impl Tx {
/// Use RPC to find a transaction by its hash.
#[cfg(feature = "rpc")]
#[cfg_attr(docsrs, doc(cfg(feature = "rpc")))]
pub async fn find_by_hash<C>(rpc_client: &C, tx_hash: &Hash) -> Result<Tx>
pub async fn find_by_hash<C>(rpc_client: &C, tx_hash: Hash) -> Result<Tx>
where
C: rpc::Client + Send + Sync,
{
let query = rpc::query::Query::from(rpc::query::EventType::Tx)
.and_eq("tx.hash", tx_hash.to_string());

let response = rpc_client
.tx_search(query, false, 1, 1, rpc::Order::Ascending)
.await?;

if response.total_count == 1 {
Tx::from_bytes(response.txs[0].tx.as_bytes())
} else {
Err(Error::TxNotFound { hash: *tx_hash }.into())
}
let response = rpc_client.tx(tx_hash, false).await?;
Tx::from_bytes(response.tx.as_bytes())
}
}

Expand Down
2 changes: 1 addition & 1 deletion cosmrs/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn msg_send() {
panic!("deliver_tx failed: {:?}", tx_commit_response.deliver_tx);
}

let tx = dev::poll_for_tx(&rpc_client, &tx_commit_response.hash).await;
let tx = dev::poll_for_tx(&rpc_client, tx_commit_response.hash).await;
assert_eq!(&tx_body, &tx.body);
assert_eq!(&auth_info, &tx.auth_info);
})
Expand Down