Skip to content

Commit

Permalink
feat: add Address type and clean up errors
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Sep 23, 2024
1 parent 6978b2c commit 628ca62
Show file tree
Hide file tree
Showing 18 changed files with 200 additions and 216 deletions.
16 changes: 12 additions & 4 deletions FULL_HELP_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,8 @@ Transfers the XLM balance of an account to another account and removes the sourc
* `--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 "."
* `--account <ACCOUNT>` — Account to merge with
* `--with-source-account <WITH_SOURCE_ACCOUNT>` — e.g. `GA3D5...` or `MA3D5...`
* `--account <ACCOUNT>` — Account to merge with, e.g. `GBX...`



Expand All @@ -1394,6 +1395,7 @@ Bumps forward the sequence number of the source account to the given sequence nu
* `--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 "."
* `--with-source-account <WITH_SOURCE_ACCOUNT>` — e.g. `GA3D5...` or `MA3D5...`
* `--bump-to <BUMP_TO>` — Sequence number to bump to


Expand All @@ -1420,6 +1422,7 @@ Creates, updates, or deletes a trustline Learn more about trustlines: [Trustline
* `--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 "."
* `--with-source-account <WITH_SOURCE_ACCOUNT>` — e.g. `GA3D5...` or `MA3D5...`
* `--line <LINE>`
* `--limit <LIMIT>` — Limit for the trust line

Expand Down Expand Up @@ -1447,8 +1450,9 @@ Creates and funds a new account with the specified starting balance Threshold: M
* `--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 "."
* `--destination <DESTINATION>` — Account to create
* `--starting-balance <STARTING_BALANCE>` — Initial balance of the account, default 1 XLM
* `--with-source-account <WITH_SOURCE_ACCOUNT>` — e.g. `GA3D5...` or `MA3D5...`
* `--destination <DESTINATION>` — Account Id to create, e.g. `GBX...`
* `--starting-balance <STARTING_BALANCE>` — Initial balance in stroops of the account, default 1 XLM



Expand All @@ -1474,6 +1478,7 @@ Sets, modifies, or deletes a data entry (name/value pair) that is attached to an
* `--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 "."
* `--with-source-account <WITH_SOURCE_ACCOUNT>` — e.g. `GA3D5...` or `MA3D5...`
* `--data-name <DATA_NAME>` — Line to change, either 4 or 12 alphanumeric characters, or "native" if not specified
* `--data-value <DATA_VALUE>` — Up to 64 bytes long hex string If not present then the existing Name will be deleted. If present then this value will be set in the `DataEntry`

Expand Down Expand Up @@ -1501,7 +1506,8 @@ Sends an amount in a specific asset to a destination account Threshold: Medium
* `--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 "."
* `--destination <DESTINATION>` — Account to send to
* `--with-source-account <WITH_SOURCE_ACCOUNT>` — e.g. `GA3D5...` or `MA3D5...`
* `--destination <DESTINATION>` — Account to send to, e.g. `GBX...`
* `--asset <ASSET>` — Asset to send, default native, e.i. XLM

Default value: `native`
Expand Down Expand Up @@ -1531,6 +1537,7 @@ Set option for an account such as flags, inflation destination, signers, home do
* `--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 "."
* `--with-source-account <WITH_SOURCE_ACCOUNT>` — e.g. `GA3D5...` or `MA3D5...`
* `--inflation-dest <INFLATION_DEST>` — Account of the inflation destination
* `--master-weight <MASTER_WEIGHT>` — A number from 0-255 (inclusive) representing the weight of the master key. If the weight of the master key is updated to 0, it is effectively disabled
* `--low-threshold <LOW_THRESHOLD>` — A number from 0-255 (inclusive) representing the threshold this account sets on all operations it performs that have [a low threshold](../../encyclopedia/security/signatures-multisig.mdx)
Expand Down Expand Up @@ -1572,6 +1579,7 @@ Allows issuing account to configure authorization and trustline flags to an asse
* `--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 "."
* `--with-source-account <WITH_SOURCE_ACCOUNT>` — e.g. `GA3D5...` or `MA3D5...`
* `--trustor <TRUSTOR>` — Account to set trustline flags for
* `--asset <ASSET>` — Asset to set trustline flags for
* `--set-authorize` — Signifies complete authorization allowing an account to transact freely with the asset to make and receive payments and place orders
Expand Down
15 changes: 9 additions & 6 deletions cmd/soroban-cli/src/commands/tx/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ use soroban_rpc::GetTransactionResponse;

use crate::{
commands::{global, txn_result::TxnResult},
config::{self, data, network, secret},
config::{self, address, data, network, secret},
fee,
rpc::{self, Client},
tx::builder,
xdr,
};

#[derive(Debug, clap::Args, Clone)]
Expand All @@ -16,6 +15,14 @@ pub struct Args {
pub fee: fee::Args,
#[clap(flatten)]
pub config: config::Args,
//// The source account for the operation, Public key or Muxxed Account
/// e.g. `GA3D5...` or `MA3D5...`
#[arg(
long,
visible_alias = "with_source",
env = "STELLAR_WITH_SOURCE_ACCOUNT"
)]
pub with_source_account: Option<address::Address>,
}

#[derive(thiserror::Error, Debug)]
Expand All @@ -27,15 +34,11 @@ pub enum Error {
#[error(transparent)]
Network(#[from] network::Error),
#[error(transparent)]
Strkey(#[from] stellar_strkey::DecodeError),
#[error(transparent)]
Secret(#[from] secret::Error),
#[error(transparent)]
Tx(#[from] builder::Error),
#[error(transparent)]
Data(#[from] data::Error),
#[error(transparent)]
Xdr(#[from] xdr::Error),
}

impl Args {
Expand Down
36 changes: 11 additions & 25 deletions cmd/soroban-cli/src/commands/tx/new/account_merge.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::{fmt::Debug, str::FromStr};

use clap::{command, Parser};

use soroban_sdk::xdr::{self, Limits, WriteXdr};
Expand All @@ -10,43 +8,30 @@ use crate::{
txn_result::{TxnEnvelopeResult, TxnResult},
NetworkRunnable,
},
config::{self, data, network, secret},
config::{self, address},
rpc,
tx::builder,
tx::builder::ops,
};

#[derive(Parser, Debug, Clone)]
#[group(skip)]
pub struct Cmd {
#[command(flatten)]
pub tx: tx::args::Args,
/// Account to merge with
/// Account to merge with, e.g. `GBX...`
#[arg(long)]
pub account: String,
pub account: address::Address,
}

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Rpc(#[from] rpc::Error),
#[error(transparent)]
Network(#[from] network::Error),
#[error(transparent)]
Strkey(#[from] stellar_strkey::DecodeError),
#[error(transparent)]
Secret(#[from] secret::Error),
#[error(transparent)]
Config(#[from] config::Error),
#[error(transparent)]
Tx(#[from] tx::args::Error),
#[error(transparent)]
TxBuilder(#[from] builder::Error),
#[error(transparent)]
Data(#[from] data::Error),

#[error(transparent)]
Xdr(#[from] xdr::Error),
#[error(transparent)]
Asset(#[from] builder::asset::Error),
Address(#[from] address::Error),
}

impl Cmd {
Expand All @@ -61,6 +46,10 @@ impl Cmd {
};
Ok(())
}

pub fn op(&self) -> ops::AccountMerge {
ops::AccountMerge::new(self.account)
}
}

#[async_trait::async_trait]
Expand All @@ -74,13 +63,10 @@ impl NetworkRunnable for Cmd {
_: Option<&config::Args>,
) -> Result<TxnResult<rpc::GetTransactionResponse>, Error> {
let tx_build = self.tx.tx_builder().await?;
let account = stellar_strkey::ed25519::PublicKey::from_str(&self.account)?;
let op = builder::ops::AccountMerge::new(account);

Ok(self
.tx
.handle_tx(
tx_build.add_operation_builder(op, None),
tx_build.add_operation_builder(self.op(), self.tx.with_source_account),
&args.cloned().unwrap_or_default(),
)
.await?)
Expand Down
23 changes: 6 additions & 17 deletions cmd/soroban-cli/src/commands/tx/new/bump_sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
txn_result::{TxnEnvelopeResult, TxnResult},
NetworkRunnable,
},
config::{self, data, network, secret},
config::{self},
rpc,
tx::builder,
};
Expand All @@ -25,23 +25,9 @@ pub struct Cmd {

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Rpc(#[from] rpc::Error),
#[error(transparent)]
Network(#[from] network::Error),
#[error(transparent)]
Strkey(#[from] stellar_strkey::DecodeError),
#[error(transparent)]
Secret(#[from] secret::Error),
#[error(transparent)]
Config(#[from] config::Error),
#[error(transparent)]
Tx(#[from] tx::args::Error),
#[error(transparent)]
TxBuilder(#[from] builder::Error),
#[error(transparent)]
Data(#[from] data::Error),
#[error(transparent)]
Xdr(#[from] xdr::Error),
#[error(transparent)]
AssetCode(#[from] builder::asset_code::Error),
Expand All @@ -59,6 +45,10 @@ impl Cmd {
};
Ok(())
}

pub fn op(&self) -> builder::ops::BumpSequence {
builder::ops::BumpSequence::new(self.bump_to)
}
}

#[async_trait::async_trait]
Expand All @@ -72,12 +62,11 @@ impl NetworkRunnable for Cmd {
_: Option<&config::Args>,
) -> Result<TxnResult<rpc::GetTransactionResponse>, Error> {
let tx_build = self.tx.tx_builder().await?;
let op = builder::ops::BumpSequence::new(self.bump_to);

Ok(self
.tx
.handle_tx(
tx_build.add_operation_builder(op, None),
tx_build.add_operation_builder(self.op(), self.tx.with_source_account),
&args.cloned().unwrap_or_default(),
)
.await?)
Expand Down
36 changes: 11 additions & 25 deletions cmd/soroban-cli/src/commands/tx/new/change_trust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
txn_result::{TxnEnvelopeResult, TxnResult},
NetworkRunnable,
},
config::{self, data, network, secret},
config::{self},
rpc,
tx::builder,
};
Expand All @@ -27,26 +27,10 @@ pub struct Cmd {

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Rpc(#[from] rpc::Error),
#[error(transparent)]
Network(#[from] network::Error),
#[error(transparent)]
Strkey(#[from] stellar_strkey::DecodeError),
#[error(transparent)]
Secret(#[from] secret::Error),
#[error(transparent)]
Config(#[from] config::Error),
#[error(transparent)]
Tx(#[from] tx::args::Error),
#[error(transparent)]
TxBuilder(#[from] builder::Error),
#[error(transparent)]
Data(#[from] data::Error),
#[error(transparent)]
Xdr(#[from] xdr::Error),
#[error(transparent)]
AssetCode(#[from] builder::asset_code::Error),
}

impl Cmd {
Expand All @@ -61,6 +45,15 @@ impl Cmd {
};
Ok(())
}

pub fn op(&self) -> builder::ops::ChangeTrust {
let line = match self.line.0.clone() {
xdr::Asset::CreditAlphanum4(asset) => xdr::ChangeTrustAsset::CreditAlphanum4(asset),
xdr::Asset::CreditAlphanum12(asset) => xdr::ChangeTrustAsset::CreditAlphanum12(asset),
xdr::Asset::Native => xdr::ChangeTrustAsset::Native,
};
builder::ops::ChangeTrust::new(line, self.limit)
}
}

#[async_trait::async_trait]
Expand All @@ -74,18 +67,11 @@ impl NetworkRunnable for Cmd {
_: Option<&config::Args>,
) -> Result<TxnResult<rpc::GetTransactionResponse>, Error> {
let tx_build = self.tx.tx_builder().await?;
// TODO add Pool Share
let line = match self.line.0.clone() {
xdr::Asset::CreditAlphanum4(asset) => xdr::ChangeTrustAsset::CreditAlphanum4(asset),
xdr::Asset::CreditAlphanum12(asset) => xdr::ChangeTrustAsset::CreditAlphanum12(asset),
xdr::Asset::Native => xdr::ChangeTrustAsset::Native,
};
let op = builder::ops::ChangeTrust::new(line, self.limit);

Ok(self
.tx
.handle_tx(
tx_build.add_operation_builder(op, None),
tx_build.add_operation_builder(self.op(), self.tx.with_source_account),
&args.cloned().unwrap_or_default(),
)
.await?)
Expand Down
Loading

0 comments on commit 628ca62

Please sign in to comment.