Skip to content

Commit

Permalink
[cli] Get explorer links from node URL
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario committed Nov 5, 2024
1 parent fab5b45 commit 685a2c6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions crates/aptos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
All notable changes to the Aptos CLI will be captured in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and the format set out by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased
- Determine network from URL to make explorer links better for legacy users

## [4.3.0] - 2024/10/30
- Allow for setting large-packages module for chunking publish mode with `--large-packages-module-address`
Expand Down
28 changes: 23 additions & 5 deletions crates/aptos/src/common/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1863,11 +1863,29 @@ impl TransactionOptions {
.await
.map_err(|err| CliError::ApiError(err.to_string()))?;
let transaction_hash = transaction.clone().committed_hash();
let network = self
.profile_options
.profile()
.ok()
.and_then(|profile| profile.network);
let network = self.profile_options.profile().ok().and_then(|profile| {
if let Some(network) = profile.network {
Some(network)
} else {
// Approximate network from URL
match profile.rest_url {
None => None,
Some(url) => {
if url.contains("mainnet") {
Some(Network::Mainnet)
} else if url.contains("testnet") {
Some(Network::Testnet)
} else if url.contains("devnet") {
Some(Network::Devnet)
} else if url.contains("localhost") || url.contains("127.0.0.1") {
Some(Network::Local)
} else {
None
}
},
}
}
});
eprintln!(
"Transaction submitted: {}",
explorer_transaction_link(transaction_hash, network)
Expand Down

0 comments on commit 685a2c6

Please sign in to comment.