Skip to content

Commit

Permalink
Add fetch-transaction to sui-tool (MystenLabs#3717)
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfind authored Aug 2, 2022
1 parent 9aff02f commit 5a6df05
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
22 changes: 22 additions & 0 deletions crates/sui-tool/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ pub enum ToolCommand {
#[clap(long = "no-header", help = "don't show header in concise output")]
no_header: bool,
},
#[clap(name = "fetch-transaction")]
FetchTransaction {
#[clap(long = "genesis")]
genesis: PathBuf,

#[clap(long, help = "The object ID to fetch")]
digest: TransactionDigest,
},
/// Tool to read validator & gateway db.
#[clap(name = "db-tool")]
DbTool {
Expand Down Expand Up @@ -423,6 +431,20 @@ impl ToolCommand {
println!("{}", VerboseObjectOutput(output));
}
}
ToolCommand::FetchTransaction { genesis, digest } => {
let clients = make_clients(genesis)?;

let responses = join_all(clients.iter().map(|(name, client)| async {
let result = client
.handle_transaction_info_request(TransactionInfoRequest {
transaction_digest: digest,
})
.await;
(*name, result)
}))
.await;
println!("{:#?}", responses);
}
ToolCommand::DbTool { db_path, cmd } => {
let path = PathBuf::from(db_path);
match cmd {
Expand Down
12 changes: 11 additions & 1 deletion crates/sui-types/src/base_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,11 +935,21 @@ impl FromStr for SuiAddress {
}
}

impl std::str::FromStr for ObjectID {
impl FromStr for ObjectID {
type Err = ObjectIDParseError;

fn from_str(s: &str) -> Result<Self, ObjectIDParseError> {
// Try to match both the literal (0xABC..) and the normal (ABC)
Self::from_hex(s).or_else(|_| Self::from_hex_literal(s))
}
}

impl FromStr for TransactionDigest {
type Err = base64ct::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut result = [0u8; TRANSACTION_DIGEST_LENGTH];
base64ct::Base64::decode(s, &mut result)?;
Ok(TransactionDigest(result))
}
}

0 comments on commit 5a6df05

Please sign in to comment.