From 6315714d1277a4e59b3be1d1e35bbf0f631e1b15 Mon Sep 17 00:00:00 2001 From: Nando Vieira Date: Wed, 2 Oct 2024 16:13:46 -0700 Subject: [PATCH 1/4] Do not require source account when fetching an asset's contract id. --- FULL_HELP_DOCS.md | 8 +--- .../src/commands/contract/id/asset.rs | 2 +- cmd/soroban-cli/src/config/mod.rs | 47 ++++++++++++++++++- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/FULL_HELP_DOCS.md b/FULL_HELP_DOCS.md index be20ae24a..b8b03c580 100644 --- a/FULL_HELP_DOCS.md +++ b/FULL_HELP_DOCS.md @@ -111,7 +111,7 @@ Utilities to deploy a Stellar Asset Contract or get its id Get Id of builtin Soroban Asset Contract. Deprecated, use `stellar contract id asset` instead -**Usage:** `stellar contract asset id [OPTIONS] --asset --source-account ` +**Usage:** `stellar contract asset id [OPTIONS] --asset ` ###### **Options:** @@ -119,8 +119,6 @@ Get Id of builtin Soroban Asset Contract. Deprecated, use `stellar contract id a * `--rpc-url ` — RPC server endpoint * `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config -* `--source-account ` — Account that where transaction originates from. Alias `source`. Can be an identity (--source alice), a public key (--source GDKW...), a muxed account (--source MDA…), a secret key (--source SC36…), or a seed phrase (--source "kite urban…"). If `--build-only` or `--sim-only` flags were NOT provided, this key will also be used to sign the final transaction. In that case, trying to sign with public key will fail -* `--hd-path ` — If using a seed phrase, which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0` * `--global` — Use global config * `--config-dir ` — Location of config directory, default is "." @@ -444,7 +442,7 @@ Generate the contract id for a given contract or asset Deploy builtin Soroban Asset Contract -**Usage:** `stellar contract id asset [OPTIONS] --asset --source-account ` +**Usage:** `stellar contract id asset [OPTIONS] --asset ` ###### **Options:** @@ -452,8 +450,6 @@ Deploy builtin Soroban Asset Contract * `--rpc-url ` — RPC server endpoint * `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config -* `--source-account ` — Account that where transaction originates from. Alias `source`. Can be an identity (--source alice), a public key (--source GDKW...), a muxed account (--source MDA…), a secret key (--source SC36…), or a seed phrase (--source "kite urban…"). If `--build-only` or `--sim-only` flags were NOT provided, this key will also be used to sign the final transaction. In that case, trying to sign with public key will fail -* `--hd-path ` — If using a seed phrase, which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0` * `--global` — Use global config * `--config-dir ` — Location of config directory, default is "." diff --git a/cmd/soroban-cli/src/commands/contract/id/asset.rs b/cmd/soroban-cli/src/commands/contract/id/asset.rs index 63b3017a1..cdf826015 100644 --- a/cmd/soroban-cli/src/commands/contract/id/asset.rs +++ b/cmd/soroban-cli/src/commands/contract/id/asset.rs @@ -13,7 +13,7 @@ pub struct Cmd { pub asset: builder::Asset, #[command(flatten)] - pub config: config::Args, + pub config: config::ArgsLocatorAndNetwork, } #[derive(thiserror::Error, Debug)] pub enum Error { diff --git a/cmd/soroban-cli/src/config/mod.rs b/cmd/soroban-cli/src/config/mod.rs index 5b64a2697..6c8f23649 100644 --- a/cmd/soroban-cli/src/config/mod.rs +++ b/cmd/soroban-cli/src/config/mod.rs @@ -63,6 +63,16 @@ pub struct Args { pub locator: locator::Args, } +#[derive(Debug, clap::Args, Clone, Default)] +#[group(skip)] +pub struct ArgsLocatorAndNetwork { + #[command(flatten)] + pub network: network::Args, + + #[command(flatten)] + pub locator: locator::Args, +} + impl Args { // TODO: Replace PublicKey with MuxedAccount once https://github.com/stellar/rs-stellar-xdr/pull/396 is merged. pub fn source_account(&self) -> Result { @@ -111,7 +121,7 @@ impl Args { } pub fn get_network(&self) -> Result { - Ok(self.network.get(&self.locator)?) + HasNetwork::get_network(self) } pub async fn next_sequence_number(&self, account_str: &str) -> Result { @@ -129,3 +139,38 @@ impl Pwd for Args { #[derive(Default, Serialize, Deserialize)] pub struct Config {} + +trait HasNetwork { + fn network_args(&self) -> &network::Args; + fn locator_args(&self) -> &locator::Args; + + fn get_network(&self) -> Result { + Ok(self.network_args().get(self.locator_args())?) + } +} + +impl HasNetwork for Args { + fn network_args(&self) -> &network::Args { + &self.network + } + + fn locator_args(&self) -> &locator::Args { + &self.locator + } +} + +impl HasNetwork for ArgsLocatorAndNetwork { + fn network_args(&self) -> &network::Args { + &self.network + } + + fn locator_args(&self) -> &locator::Args { + &self.locator + } +} + +impl ArgsLocatorAndNetwork { + pub fn get_network(&self) -> Result { + HasNetwork::get_network(self) + } +} From fd4a7c9f283e732ce5333b6a2c57bb3ff2074592 Mon Sep 17 00:00:00 2001 From: Nando Vieira Date: Wed, 2 Oct 2024 16:30:27 -0700 Subject: [PATCH 2/4] Simplify the whole thing. --- cmd/soroban-cli/src/config/mod.rs | 47 ++++++------------------------- 1 file changed, 9 insertions(+), 38 deletions(-) diff --git a/cmd/soroban-cli/src/config/mod.rs b/cmd/soroban-cli/src/config/mod.rs index 6c8f23649..12f571a50 100644 --- a/cmd/soroban-cli/src/config/mod.rs +++ b/cmd/soroban-cli/src/config/mod.rs @@ -63,16 +63,6 @@ pub struct Args { pub locator: locator::Args, } -#[derive(Debug, clap::Args, Clone, Default)] -#[group(skip)] -pub struct ArgsLocatorAndNetwork { - #[command(flatten)] - pub network: network::Args, - - #[command(flatten)] - pub locator: locator::Args, -} - impl Args { // TODO: Replace PublicKey with MuxedAccount once https://github.com/stellar/rs-stellar-xdr/pull/396 is merged. pub fn source_account(&self) -> Result { @@ -121,7 +111,7 @@ impl Args { } pub fn get_network(&self) -> Result { - HasNetwork::get_network(self) + Ok(self.network.get(&self.locator)?) } pub async fn next_sequence_number(&self, account_str: &str) -> Result { @@ -140,37 +130,18 @@ impl Pwd for Args { #[derive(Default, Serialize, Deserialize)] pub struct Config {} -trait HasNetwork { - fn network_args(&self) -> &network::Args; - fn locator_args(&self) -> &locator::Args; - - fn get_network(&self) -> Result { - Ok(self.network_args().get(self.locator_args())?) - } -} - -impl HasNetwork for Args { - fn network_args(&self) -> &network::Args { - &self.network - } - - fn locator_args(&self) -> &locator::Args { - &self.locator - } -} - -impl HasNetwork for ArgsLocatorAndNetwork { - fn network_args(&self) -> &network::Args { - &self.network - } +#[derive(Debug, clap::Args, Clone, Default)] +#[group(skip)] +pub struct ArgsLocatorAndNetwork { + #[command(flatten)] + pub network: network::Args, - fn locator_args(&self) -> &locator::Args { - &self.locator - } + #[command(flatten)] + pub locator: locator::Args, } impl ArgsLocatorAndNetwork { pub fn get_network(&self) -> Result { - HasNetwork::get_network(self) + Ok(self.network.get(&self.locator)?) } } From b2c9dbf777d94d83add0816d49d84f980950b370 Mon Sep 17 00:00:00 2001 From: Nando Vieira Date: Wed, 2 Oct 2024 16:46:14 -0700 Subject: [PATCH 3/4] Fix integration test. --- cmd/crates/soroban-test/tests/it/integration/cookbook.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmd/crates/soroban-test/tests/it/integration/cookbook.rs b/cmd/crates/soroban-test/tests/it/integration/cookbook.rs index 4c0ad5a63..82b9c5f43 100644 --- a/cmd/crates/soroban-test/tests/it/integration/cookbook.rs +++ b/cmd/crates/soroban-test/tests/it/integration/cookbook.rs @@ -236,8 +236,6 @@ mod tests { .arg("asset") .arg("--asset") .arg("native") - .arg("--source-account") - .arg(source) .assert() .stdout_as_str(); let contract_id = deploy_hello(&sandbox).await; From ddc0bc3b397e44d41668c38d4676a0b299b15107 Mon Sep 17 00:00:00 2001 From: Nando Vieira Date: Wed, 2 Oct 2024 17:08:22 -0700 Subject: [PATCH 4/4] Update cookbook. --- cookbook/deploy-stellar-asset-contract.mdx | 1 - cookbook/payments-and-assets.mdx | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/cookbook/deploy-stellar-asset-contract.mdx b/cookbook/deploy-stellar-asset-contract.mdx index 7233acc60..8fca51c48 100644 --- a/cookbook/deploy-stellar-asset-contract.mdx +++ b/cookbook/deploy-stellar-asset-contract.mdx @@ -42,7 +42,6 @@ For any asset, the contract address can be fetched with: ```bash stellar contract id asset \ - --source S... \ --network testnet \ --asset native ``` diff --git a/cookbook/payments-and-assets.mdx b/cookbook/payments-and-assets.mdx index 9849bf3d9..e3be8dafc 100644 --- a/cookbook/payments-and-assets.mdx +++ b/cookbook/payments-and-assets.mdx @@ -35,7 +35,7 @@ stellar keys fund bob 3. Obtain the stellar asset contract ID: ```bash -stellar contract id asset --asset native --source-account alice +stellar contract id asset --asset native ``` 4. Get Bob's public key: