Skip to content

Commit

Permalink
Add warning on no fund flag (#1637)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifropc authored Oct 10, 2024
1 parent 440b75d commit 09a63ab
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
3 changes: 3 additions & 0 deletions FULL_HELP_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,9 @@ Generate a new identity with a seed phrase, currently 12 words
* `--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
* `--fund` — Fund generated key pair

Default value: `false`



Expand Down
16 changes: 15 additions & 1 deletion cmd/soroban-cli/src/commands/keys/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::super::config::{
locator, network,
secret::{self, Secret},
};
use crate::{commands::global, print::Print};

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand All @@ -17,6 +18,7 @@ pub enum Error {

#[derive(Debug, clap::Parser, Clone)]
#[group(skip)]
#[allow(clippy::struct_excessive_bools)]
pub struct Cmd {
/// Name of identity
pub name: String,
Expand Down Expand Up @@ -46,10 +48,22 @@ pub struct Cmd {

#[command(flatten)]
pub network: network::Args,

/// Fund generated key pair
#[arg(long, default_value = "false")]
pub fund: bool,
}

impl Cmd {
pub async fn run(&self) -> Result<(), Error> {
pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
if !self.fund {
Print::new(global_args.quiet).warnln(
"Behavior of `generate` will change in the \
future, and it will no longer fund by default. If you want to fund please \
provide `--fund` flag. If you don't need to fund your keys in the future, ignore this \
warning. It can be suppressed with -q flag.",
);
}
let seed_phrase = if self.default_seed {
Secret::test_seed_phrase()
} else {
Expand Down
5 changes: 3 additions & 2 deletions cmd/soroban-cli/src/commands/keys/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::commands::global;
use clap::Parser;

pub mod add;
Expand Down Expand Up @@ -48,12 +49,12 @@ 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::Add(cmd) => cmd.run()?,
Cmd::Address(cmd) => cmd.run()?,
Cmd::Fund(cmd) => cmd.run().await?,
Cmd::Generate(cmd) => cmd.run().await?,
Cmd::Generate(cmd) => cmd.run(global_args).await?,
Cmd::Ls(cmd) => cmd.run()?,
Cmd::Rm(cmd) => cmd.run()?,
Cmd::Show(cmd) => cmd.run()?,
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl Root {
Cmd::Network(network) => network.run(&self.global_args).await?,
Cmd::Snapshot(snapshot) => snapshot.run(&self.global_args).await?,
Cmd::Version(version) => version.run(),
Cmd::Keys(id) => id.run().await?,
Cmd::Keys(id) => id.run(&self.global_args).await?,
Cmd::Tx(tx) => tx.run(&self.global_args).await?,
Cmd::Cache(data) => data.run()?,
};
Expand Down
2 changes: 1 addition & 1 deletion cookbook/contract-lifecycle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ To manage the lifecycle of a Stellar smart contract using the CLI, follow these
1. Create an identity for Alice:

```bash
stellar keys generate alice
stellar keys generate alice -q
```

2. Fund the identity:
Expand Down
4 changes: 2 additions & 2 deletions cookbook/payments-and-assets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ By setting the `STELLAR_NETWORK` environment variable, we will not have to set t
2. Fund the accounts:

```bash
stellar keys generate alice
stellar keys generate alice -q
```

```bash
stellar keys generate bob
stellar keys generate bob -q
```

```bash
Expand Down

0 comments on commit 09a63ab

Please sign in to comment.