Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print old contract when overriding existing alias. #1841

Merged
merged 3 commits into from
Jan 21, 2025
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
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
Loading