Skip to content

Commit

Permalink
Print old contract when overriding existing alias. (#1841)
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando authored Jan 21, 2025
1 parent ed692a0 commit d2fc781
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
6 changes: 4 additions & 2 deletions cmd/soroban-cli/src/commands/contract/asset.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::commands::global;

use super::{deploy, id};

#[derive(Debug, clap::Subcommand)]
Expand All @@ -17,10 +19,10 @@ pub enum Error {
}

impl Cmd {
pub async fn run(&self) -> Result<(), Error> {
pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
match &self {
Cmd::Id(id) => id.run()?,
Cmd::Deploy(asset) => asset.run().await?,
Cmd::Deploy(asset) => asset.run(global_args).await?,
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum Error {
impl Cmd {
pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
match &self {
Cmd::Asset(asset) => asset.run().await?,
Cmd::Asset(asset) => asset.run(global_args).await?,
Cmd::Wasm(wasm) => wasm.run(global_args).await?,
}
Ok(())
Expand Down
14 changes: 13 additions & 1 deletion cmd/soroban-cli/src/commands/contract/deploy/asset.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::config::locator;
use crate::print::Print;
use crate::xdr::{
Asset, ContractDataDurability, ContractExecutable, ContractIdPreimage, CreateContractArgs,
Error as XdrError, Hash, HostFunction, InvokeHostFunctionOp, LedgerKey::ContractData,
Expand Down Expand Up @@ -73,14 +74,25 @@ pub struct Cmd {
}

impl Cmd {
pub async fn run(&self) -> Result<(), Error> {
pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
let res = self.run_against_rpc_server(None, None).await?.to_envelope();
match res {
TxnEnvelopeResult::TxnEnvelope(tx) => println!("{}", tx.to_xdr_base64(Limits::none())?),
TxnEnvelopeResult::Res(contract) => {
let network = self.config.get_network()?;

if let Some(alias) = self.alias.clone() {
if let Some(existing_contract) = self
.config
.locator
.get_contract_id(&alias, &network.network_passphrase)?
{
let print = Print::new(global_args.quiet);
print.warnln(format!(
"Overwriting existing contract id: {existing_contract}"
));
};

self.config.locator.save_contract_id(
&network.network_passphrase,
&contract,
Expand Down
11 changes: 11 additions & 0 deletions cmd/soroban-cli/src/commands/contract/deploy/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ impl Cmd {
let network = self.config.get_network()?;

if let Some(alias) = self.alias.clone() {
if let Some(existing_contract) = self
.config
.locator
.get_contract_id(&alias, &network.network_passphrase)?
{
let print = Print::new(global_args.quiet);
print.warnln(format!(
"Overwriting existing contract id: {existing_contract}"
));
};

self.config.locator.save_contract_id(
&network.network_passphrase,
&contract,
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub enum Error {
impl Cmd {
pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
match &self {
Cmd::Asset(asset) => asset.run().await?,
Cmd::Asset(asset) => asset.run(global_args).await?,
Cmd::Bindings(bindings) => bindings.run().await?,
Cmd::Build(build) => build.run(global_args)?,
Cmd::Extend(extend) => extend.run().await?,
Expand Down

0 comments on commit d2fc781

Please sign in to comment.