Skip to content

Commit

Permalink
Do not require source account when fetching an asset's contract id.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed Oct 2, 2024
1 parent bb9c712 commit 6315714
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
8 changes: 2 additions & 6 deletions FULL_HELP_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,14 @@ 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 <ASSET> --source-account <SOURCE_ACCOUNT>`
**Usage:** `stellar contract asset id [OPTIONS] --asset <ASSET>`

###### **Options:**

* `--asset <ASSET>` — ID of the Stellar classic asset to wrap, e.g. "USDC:G...5"
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
* `--network <NETWORK>` — Name of network to use from config
* `--source-account <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 <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 <CONFIG_DIR>` — Location of config directory, default is "."

Expand Down Expand Up @@ -444,16 +442,14 @@ Generate the contract id for a given contract or asset

Deploy builtin Soroban Asset Contract

**Usage:** `stellar contract id asset [OPTIONS] --asset <ASSET> --source-account <SOURCE_ACCOUNT>`
**Usage:** `stellar contract id asset [OPTIONS] --asset <ASSET>`

###### **Options:**

* `--asset <ASSET>` — ID of the Stellar classic asset to wrap, e.g. "USDC:G...5"
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
* `--network <NETWORK>` — Name of network to use from config
* `--source-account <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 <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 <CONFIG_DIR>` — Location of config directory, default is "."

Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/id/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
47 changes: 46 additions & 1 deletion cmd/soroban-cli/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<xdr::MuxedAccount, Error> {
Expand Down Expand Up @@ -111,7 +121,7 @@ impl Args {
}

pub fn get_network(&self) -> Result<Network, Error> {
Ok(self.network.get(&self.locator)?)
HasNetwork::get_network(self)
}

pub async fn next_sequence_number(&self, account_str: &str) -> Result<SequenceNumber, Error> {
Expand All @@ -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<Network, Error> {
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<Network, Error> {
HasNetwork::get_network(self)
}
}

0 comments on commit 6315714

Please sign in to comment.