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 ec87a5a
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions cosmos-sdk-rs/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,15 @@ 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)
let raw_tx = rpc_client
.tx(tx_hash)
.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 ec87a5a

Please sign in to comment.