Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/muxed_keys
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Nov 29, 2024
2 parents d8eb111 + 390c220 commit cca279c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
4 changes: 2 additions & 2 deletions FULL_HELP_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,7 @@ Creates and funds a new account with the specified starting balance
* `--destination <DESTINATION>` — Account Id to create, e.g. `GBX...`
* `--starting-balance <STARTING_BALANCE>` — Initial balance in stroops of the account, default 1 XLM

Default value: `10000000`
Default value: `10_000_000`



Expand Down Expand Up @@ -1723,7 +1723,7 @@ Sends an amount in a specific asset to a destination account
* `--asset <ASSET>` — Asset to send, default native, e.i. XLM

Default value: `native`
* `--amount <AMOUNT>` — Amount of the aforementioned asset to send
* `--amount <AMOUNT>` — Amount of the aforementioned asset to send. e.g. `10_000_000` (1 XLM)



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ async fn payment() {
"--destination",
test1.as_str(),
"--amount",
ONE_XLM.to_string().as_str(),
"10_000_000",
])
.assert()
.success();
Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-cli/src/commands/tx/new/create_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pub struct Cmd {
#[arg(long)]
pub destination: address::Address,
/// Initial balance in stroops of the account, default 1 XLM
#[arg(long, default_value = "10000000")]
pub starting_balance: i64,
#[arg(long, default_value = "10_000_000")]
pub starting_balance: builder::Amount,
}

impl TryFrom<&Cmd> for xdr::OperationBody {
Expand Down
8 changes: 4 additions & 4 deletions cmd/soroban-cli/src/commands/tx/new/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ pub struct Cmd {
/// Asset to send, default native, e.i. XLM
#[arg(long, default_value = "native")]
pub asset: builder::Asset,
/// Amount of the aforementioned asset to send.
/// Amount of the aforementioned asset to send. e.g. `10_000_000` (1 XLM)
#[arg(long)]
pub amount: i64,
pub amount: builder::Amount,
}

impl TryFrom<&Cmd> for xdr::OperationBody {
Expand All @@ -24,7 +24,7 @@ impl TryFrom<&Cmd> for xdr::OperationBody {
Ok(xdr::OperationBody::Payment(xdr::PaymentOp {
destination: cmd.tx.reslove_muxed_address(&cmd.destination)?,
asset: cmd.asset.clone().into(),
amount: cmd.amount,
}))
amount: cmd.amount.into(),
})
}
}
2 changes: 2 additions & 0 deletions cmd/soroban-cli/src/tx/builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pub mod amount;
pub mod asset;
pub mod transaction;

pub use amount::Amount;
pub use asset::Asset;
pub use transaction::TxExt;

Expand Down
35 changes: 35 additions & 0 deletions cmd/soroban-cli/src/tx/builder/amount.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use std::str::FromStr;

#[derive(Clone, Debug, Copy)]
pub struct Amount(i64);

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("cannot start or end with `_`: {0}")]
CannotStartOrEndWithUnderscore(String),
#[error(transparent)]
IntParse(#[from] std::num::ParseIntError),
}

impl FromStr for Amount {
type Err = Error;

fn from_str(value: &str) -> Result<Self, Self::Err> {
if value.starts_with('_') || value.ends_with('_') {
return Err(Error::CannotStartOrEndWithUnderscore(value.to_string()));
}
Ok(Self(value.replace('_', "").parse::<i64>()?))
}
}

impl From<Amount> for i64 {
fn from(builder: Amount) -> Self {
builder.0
}
}

impl From<&Amount> for i64 {
fn from(builder: &Amount) -> Self {
(*builder).into()
}
}

0 comments on commit cca279c

Please sign in to comment.