diff --git a/cmd/soroban-cli/src/commands/contract/asset.rs b/cmd/soroban-cli/src/commands/contract/asset.rs index edf077a7c..ce10602c7 100644 --- a/cmd/soroban-cli/src/commands/contract/asset.rs +++ b/cmd/soroban-cli/src/commands/contract/asset.rs @@ -1,3 +1,5 @@ +use crate::commands::global; + use super::{deploy, id}; #[derive(Debug, clap::Subcommand)] @@ -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(()) } diff --git a/cmd/soroban-cli/src/commands/contract/deploy.rs b/cmd/soroban-cli/src/commands/contract/deploy.rs index 3e6dcf3ea..2d67a2161 100644 --- a/cmd/soroban-cli/src/commands/contract/deploy.rs +++ b/cmd/soroban-cli/src/commands/contract/deploy.rs @@ -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(()) diff --git a/cmd/soroban-cli/src/commands/contract/deploy/asset.rs b/cmd/soroban-cli/src/commands/contract/deploy/asset.rs index 8c4419277..c8133b5f5 100644 --- a/cmd/soroban-cli/src/commands/contract/deploy/asset.rs +++ b/cmd/soroban-cli/src/commands/contract/deploy/asset.rs @@ -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, @@ -73,7 +74,7 @@ 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())?), @@ -81,6 +82,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, diff --git a/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs b/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs index 9bd8fed68..14db36e00 100644 --- a/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs +++ b/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs @@ -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, diff --git a/cmd/soroban-cli/src/commands/contract/mod.rs b/cmd/soroban-cli/src/commands/contract/mod.rs index 42792a70d..40b8dcd4b 100644 --- a/cmd/soroban-cli/src/commands/contract/mod.rs +++ b/cmd/soroban-cli/src/commands/contract/mod.rs @@ -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?, diff --git a/cmd/soroban-cli/src/utils/contract-template/src/lib.rs b/cmd/soroban-cli/src/utils/contract-template/src/lib.rs index 0b701fd82..f8120043a 100644 --- a/cmd/soroban-cli/src/utils/contract-template/src/lib.rs +++ b/cmd/soroban-cli/src/utils/contract-template/src/lib.rs @@ -4,6 +4,15 @@ use soroban_sdk::{contract, contractimpl, vec, Env, String, Vec}; #[contract] pub struct Contract; +// This is a sample contract. Replace this placeholder with your own contract logic. +// A corresponding test example is available in `test.rs`. +// +// For comprehensive examples, visit . +// The repository includes use cases for the Stellar ecosystem, such as data storage on +// the blockchain, token swaps, liquidity pools, and more. +// +// Refer to the official documentation: +// . #[contractimpl] impl Contract { pub fn hello(env: Env, to: String) -> Vec { diff --git a/cookbook/contract-lifecycle.mdx b/cookbook/contract-lifecycle.mdx index 2be63c23f..a1eb0414b 100644 --- a/cookbook/contract-lifecycle.mdx +++ b/cookbook/contract-lifecycle.mdx @@ -2,6 +2,7 @@ title: Contract Lifecycle hide_table_of_contents: true description: Manage the lifecycle of a Stellar smart contract using the CLI +custom_edit_url: https://github.com/stellar/stellar-cli/edit/main/cookbook/contract-lifecycle.mdx --- To manage the lifecycle of a Stellar smart contract using the CLI, follow these steps: diff --git a/cookbook/deploy-contract.mdx b/cookbook/deploy-contract.mdx index ec0accf7b..f8666a409 100644 --- a/cookbook/deploy-contract.mdx +++ b/cookbook/deploy-contract.mdx @@ -2,6 +2,7 @@ title: Deploy a contract from installed Wasm bytecode hide_table_of_contents: true description: Deploy an instance of a compiled contract that is already installed on the network +custom_edit_url: https://github.com/stellar/stellar-cli/edit/main/cookbook/deploy-contract.mdx --- To deploy an instance of a compiled smart contract that has already been installed onto the Stellar network, use the `stellar contract deploy` command: diff --git a/cookbook/deploy-stellar-asset-contract.mdx b/cookbook/deploy-stellar-asset-contract.mdx index 8fca51c48..c6645f9a6 100644 --- a/cookbook/deploy-stellar-asset-contract.mdx +++ b/cookbook/deploy-stellar-asset-contract.mdx @@ -2,6 +2,7 @@ title: Deploy the Stellar Asset Contract for a Stellar asset hide_table_of_contents: true description: Deploy an SAC for a Stellar asset so that it can interact with smart contracts +custom_edit_url: https://github.com/stellar/stellar-cli/edit/main/cookbook/deploy-stellar-asset-contract.mdx --- The Stellar CLI can deploy a [Stellar Asset Contract] for a Stellar asset so that any Stellar smart contract can interact with the asset. diff --git a/cookbook/extend-contract-instance.mdx b/cookbook/extend-contract-instance.mdx index 3c456a39a..37a182976 100644 --- a/cookbook/extend-contract-instance.mdx +++ b/cookbook/extend-contract-instance.mdx @@ -2,6 +2,7 @@ title: Extend a deployed contract instance's TTL hide_table_of_contents: true description: Use the CLI to extend the time to live (TTL) of a contract instance +custom_edit_url: https://github.com/stellar/stellar-cli/edit/main/cookbook/extend-contract-instance.mdx --- You can use the Stellar CLI to extend the TTL of a contract instance like so: diff --git a/cookbook/extend-contract-storage.mdx b/cookbook/extend-contract-storage.mdx index 21ce9c186..28b2b6d40 100644 --- a/cookbook/extend-contract-storage.mdx +++ b/cookbook/extend-contract-storage.mdx @@ -2,6 +2,7 @@ title: Extend a deployed contract's storage entry TTL hide_table_of_contents: true description: Use the CLI to extend the time to live (TTL) of a contract's persistent storage entry +custom_edit_url: https://github.com/stellar/stellar-cli/edit/main/cookbook/extend-contract-storage.mdx --- You can use the Stellar CLI to extend the TTL of a contract's persistent storage entry. For a storage entry that uses a simple `Symbol` as its storage key, you can run a command like so: diff --git a/cookbook/extend-contract-wasm.mdx b/cookbook/extend-contract-wasm.mdx index 9c4763b92..7e92e7663 100644 --- a/cookbook/extend-contract-wasm.mdx +++ b/cookbook/extend-contract-wasm.mdx @@ -2,6 +2,7 @@ title: Extend a deployed contract's Wasm code TTL hide_table_of_contents: true description: Use Stellar CLI to extend contract's Wasm bytecode TTL, with or without local binary +custom_edit_url: https://github.com/stellar/stellar-cli/edit/main/cookbook/extend-contract-wasm.mdx --- You can use the Stellar CLI to extend the TTL of a contract's Wasm bytecode. This can be done in two forms: if you do or do not have the compiled contract locally. If you do have the compiled binary on your local machine: diff --git a/cookbook/install-deploy.mdx b/cookbook/install-deploy.mdx index 3eb84b357..444e5c4e6 100644 --- a/cookbook/install-deploy.mdx +++ b/cookbook/install-deploy.mdx @@ -2,6 +2,7 @@ title: Install and deploy a smart contract hide_table_of_contents: true description: Combine the install and deploy commands in the Stellar CLI to accomplish both tasks +custom_edit_url: https://github.com/stellar/stellar-cli/edit/main/cookbook/install-deploy.mdx --- You can combine the `install` and `deploy` commands of the Stellar CLI to accomplish both tasks: diff --git a/cookbook/install-wasm.mdx b/cookbook/install-wasm.mdx index 96a4913ef..ec2a66fee 100644 --- a/cookbook/install-wasm.mdx +++ b/cookbook/install-wasm.mdx @@ -2,6 +2,7 @@ title: Install Wasm bytecode hide_table_of_contents: true description: Use the Stellar CLI to install a compiled smart contract on the ledger +custom_edit_url: https://github.com/stellar/stellar-cli/edit/main/cookbook/install-wasm.mdx --- To use the Stellar CLI to install a compiled smart contract on the ledger, use the `stellar contract install` command: diff --git a/cookbook/payments-and-assets.mdx b/cookbook/payments-and-assets.mdx index a198973e1..014fa8fab 100644 --- a/cookbook/payments-and-assets.mdx +++ b/cookbook/payments-and-assets.mdx @@ -2,6 +2,7 @@ title: Payments and Assets hide_table_of_contents: true description: Send XLM, stellar classic, or a soroban asset using the Stellar CLI +custom_edit_url: https://github.com/stellar/stellar-cli/edit/main/cookbook/payments-and-assets.mdx --- To send payments and work with assets using the Stellar CLI, follow these steps: diff --git a/cookbook/restore-contract-instance.mdx b/cookbook/restore-contract-instance.mdx index 488760ba4..28b3fd64a 100644 --- a/cookbook/restore-contract-instance.mdx +++ b/cookbook/restore-contract-instance.mdx @@ -2,6 +2,7 @@ title: Restore an archived contract using the Stellar CLI hide_table_of_contents: true description: Restore an archived contract instance using the Stellar CLI +custom_edit_url: https://github.com/stellar/stellar-cli/edit/main/cookbook/restore-contract-instance.mdx --- If your contract instance has been archived, it can easily be restored using the Stellar CLI. diff --git a/cookbook/restore-contract-storage.mdx b/cookbook/restore-contract-storage.mdx index 48fd86b9d..7b2f58df8 100644 --- a/cookbook/restore-contract-storage.mdx +++ b/cookbook/restore-contract-storage.mdx @@ -2,6 +2,7 @@ title: Restore archived contract data using the Stellar CLI hide_table_of_contents: true description: Restore archived contract storage entries using Stellar CLI +custom_edit_url: https://github.com/stellar/stellar-cli/edit/main/cookbook/restore-contract-storage.mdx --- If a contract's persistent storage entry has been archived, you can restore it using the Stellar CLI. For a storage entry that uses a simple `Symbol` as its storage key, you can run a command like so: diff --git a/cookbook/tx-new.mdx b/cookbook/tx-new.mdx index 481d13d59..3a413d1ef 100644 --- a/cookbook/tx-new.mdx +++ b/cookbook/tx-new.mdx @@ -2,6 +2,7 @@ title: `tx` Commands hide_table_of_contents: true description: Create stellar transactions using the Stellar CLI +custom_edit_url: https://github.com/stellar/stellar-cli/edit/main/cookbook/tx-new.mdx --- So far the examples of the CLI interacting with the blockchain have been through the `contract` command. Uploading contracts, deploying contracts, and invoking them. diff --git a/cookbook/tx-op-add.mdx b/cookbook/tx-op-add.mdx index 562fdca0d..d18bc7768 100644 --- a/cookbook/tx-op-add.mdx +++ b/cookbook/tx-op-add.mdx @@ -2,6 +2,7 @@ title: `tx op add` hide_table_of_contents: true description: Create stellar transactions using the Stellar CLI +custom_edit_url: https://github.com/stellar/stellar-cli/edit/main/cookbook/tx-op-add.mdx --- As see before you can use pipes to pass a transaction envolope between commands. Before we have only been looking at transactions with one operation, @@ -48,4 +49,4 @@ stellar tx new set-trustline-flags --fee 1000 --build-only --source issuer --ass | stellar tx op add set-trustline-flags --asset $ASSET --trustor distributor --clear-authorize \ | stellar tx sign --sign-with-key issuer \ | stellar tx send -``` \ No newline at end of file +``` diff --git a/cookbook/tx-sign.mdx b/cookbook/tx-sign.mdx index 9aa2a9cab..2779231a7 100644 --- a/cookbook/tx-sign.mdx +++ b/cookbook/tx-sign.mdx @@ -2,6 +2,7 @@ title: `tx sign` and `tx send` hide_table_of_contents: true description: Create stellar transactions using the Stellar CLI +custom_edit_url: https://github.com/stellar/stellar-cli/edit/main/cookbook/tx-sign.mdx --- The previous examples of using `tx new` showed how to create transactions. However, these transactions were immediately ready to be signed and submitted to the network. @@ -69,4 +70,4 @@ stellar tx new create-account \ --build-only \ | stellar tx sign --sign-with-key alice \ | stellar tx send -``` \ No newline at end of file +```