Skip to content

Commit

Permalink
feat: add status command
Browse files Browse the repository at this point in the history
Aliases `tx-status` and `transaction-status` are also accepted. This
command uses the `starknet_getTransactionStatus` to instruct the
JSON-RPC node to query the sequencer for mempool transaction status.
  • Loading branch information
xJonathanLEI committed Feb 8, 2024
1 parent 3642be9 commit 348bc75
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ enum Subcommands {
#[clap(about = "Get all traces from a certain block")]
BlockTraces(BlockTraces),
#[clap(
alias = "transaction-receipt",
aliases = ["tx-status", "transaction-status"],
about = "Get transaction status by hash"
)]
Status(TransactionStatus),
#[clap(
aliases = ["tx-receipt", "transaction-receipt"],
about = "Get transaction receipt by hash"
)]
Receipt(TransactionReceipt),
Expand Down Expand Up @@ -179,6 +184,7 @@ async fn run_command(cli: Cli) -> Result<()> {
Subcommands::BlockTime(cmd) => cmd.run().await,
Subcommands::StateUpdate(cmd) => cmd.run().await,
Subcommands::BlockTraces(cmd) => cmd.run().await,
Subcommands::Status(cmd) => cmd.run().await,
Subcommands::Receipt(cmd) => cmd.run().await,
Subcommands::Trace(cmd) => cmd.run().await,
Subcommands::ChainId(cmd) => cmd.run().await,
Expand Down
3 changes: 3 additions & 0 deletions src/subcommands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,6 @@ pub use spec_version::SpecVersion;

mod block_traces;
pub use block_traces::BlockTraces;

mod transaction_status;
pub use transaction_status::TransactionStatus;
34 changes: 34 additions & 0 deletions src/subcommands/transaction_status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use anyhow::Result;
use clap::Parser;
use colored_json::{ColorMode, Output};
use starknet::{core::types::FieldElement, providers::Provider};

use crate::{verbosity::VerbosityArgs, ProviderArgs};

#[derive(Debug, Parser)]
pub struct TransactionStatus {
#[clap(flatten)]
provider: ProviderArgs,
#[clap(help = "Transaction hash")]
hash: String,
#[clap(flatten)]
verbosity: VerbosityArgs,
}

impl TransactionStatus {
pub async fn run(self) -> Result<()> {
self.verbosity.setup_logging();

let provider = self.provider.into_provider()?;
let transaction_hash = FieldElement::from_hex_be(&self.hash)?;

let status = provider.get_transaction_status(transaction_hash).await?;

let status_json = serde_json::to_value(status)?;
let status_json =
colored_json::to_colored_json(&status_json, ColorMode::Auto(Output::StdOut))?;
println!("{status_json}");

Ok(())
}
}

0 comments on commit 348bc75

Please sign in to comment.