Skip to content

Commit

Permalink
cosmos-sdk-rs: make Tx::find_by_hash use the /tx endpoint
Browse files Browse the repository at this point in the history
Notably this endpoint provides read-your-writes consistency with regard
to transactions, whereas `/tx_search` does not.

See also: tendermint/tendermint#6359
  • Loading branch information
tony-iqlusion committed Aug 6, 2021
1 parent ba012bd commit a1ae55a
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions cosmos-sdk-rs/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,13 @@ 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 raw_tx = rpc_client.tx(tx_hash).await?;

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())
}
Tx::from_bytes(raw_tx.as_bytes())
}
}

Expand Down

0 comments on commit a1ae55a

Please sign in to comment.