Skip to content
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
23 changes: 23 additions & 0 deletions packages/cosmos-bin/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ pub(crate) enum Subcommand {
#[clap(long)]
page: Option<u64>,
},
/// List transactions against a given contract
ListContractTxs {
contract: Address,
/// Maximum number of transactions to return
#[clap(long)]
limit: Option<u64>,
/// Page
#[clap(long)]
page: Option<u64>,
},
/// Perform a query for transactions
QueryTxs {
query: String,
Expand Down Expand Up @@ -235,6 +245,19 @@ pub(crate) async fn go(Opt { sub }: Opt, opt: crate::cli::Opt) -> Result<()> {
println!("{txhash}");
}
}
Subcommand::ListContractTxs {
contract,
limit,
page,
} => {
let cosmos = opt.network_opt.build().await?;
for txhash in cosmos
.list_contract_transactions(contract, limit, page)
.await?
{
println!("{txhash}");
}
}
Subcommand::QueryTxs {
query,
limit,
Expand Down
30 changes: 30 additions & 0 deletions packages/cosmos/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,36 @@ impl Cosmos {
})
}

/// Get a list of txhashes for transactions against the given contract.
pub async fn list_contract_transactions(
&self,
address: Address,
limit: Option<u64>,
page: Option<u64>,
) -> Result<Vec<String>, QueryError> {
// The pagination field within this struct is
// deprecated. https://docs.rs/cosmos-sdk-proto/0.21.1/cosmos_sdk_proto/cosmos/tx/v1beta1/struct.GetTxsEventRequest.html#structfield.pagination
#[allow(deprecated)]
let req = GetTxsEventRequest {
events: vec![],
pagination: None,
order_by: OrderBy::Asc as i32,
page: page.unwrap_or(1),
limit: limit.unwrap_or(10),
query: format!("execute._contract_address='{address}'"),
};
self.perform_query(req, Action::ListTransactionsFor(address))
.run()
.await
.map(|x| {
x.into_inner()
.tx_responses
.into_iter()
.map(|x| x.txhash)
.collect()
})
}

/// Get transactions meeting the given query.
pub async fn query_transactions(
&self,
Expand Down
Loading