diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c3da43..8a32082 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Add interactive stake allow [#98] +- Add optional `WALLET_MAX_ADDR` compile time env [#210] ### Fixed @@ -434,6 +435,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Implementation of `Store` trait from `wallet-core` - Implementation of `State` and `Prover` traits from `wallet-core` +[#210]: https://github.com/dusk-network/wallet-cli/issues/210 [#98]: https://github.com/dusk-network/wallet-cli/issues/98 [#179]: https://github.com/dusk-network/wallet-cli/issues/179 [#204]: https://github.com/dusk-network/wallet-cli/issues/204 diff --git a/Cargo.toml b/Cargo.toml index 3298be4..57772b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,6 +65,8 @@ tracing-subscriber = { version = "0.3.0", features = [ rkyv = { version = "=0.7.39", default-features = false } +konst = "0.3" + [dev-dependencies] tempfile = "3.2" diff --git a/src/bin/command.rs b/src/bin/command.rs index 18bcb1f..4fa946d 100644 --- a/src/bin/command.rs +++ b/src/bin/command.rs @@ -212,7 +212,7 @@ impl Command { if new { if wallet.addresses().len() >= MAX_ADDRESSES { println!( - "Cannot create more addresses, this wallet only supports upto 256 addresses. You have {} addresses already.", wallet.addresses().len() + "Cannot create more addresses, this wallet only supports up to {MAX_ADDRESSES} addresses. You have {} addresses already.", wallet.addresses().len() ); std::process::exit(0); } diff --git a/src/bin/interactive.rs b/src/bin/interactive.rs index bd7bfd8..3fd5842 100644 --- a/src/bin/interactive.rs +++ b/src/bin/interactive.rs @@ -32,7 +32,7 @@ pub(crate) async fn run_loop( AddrSelect::NewAddress => { if wallet.addresses().len() >= MAX_ADDRESSES { println!( - "Cannot create more addresses, this wallet only supports up to 256 addresses" + "Cannot create more addresses, this wallet only supports up to {MAX_ADDRESSES} addresses" ); std::process::exit(0); } @@ -151,7 +151,7 @@ fn menu_addr(wallet: &Wallet) -> anyhow::Result { // show warning early on at 250 addresses if wallet.addresses().len() >= MAX_ADDRESSES - 5 { action_menu = action_menu.separator().separator_msg(format!( - "\x1b[93m{}\x1b[0m This wallet only supports up to 256 addresses, you have {} addresses ", + "\x1b[93m{}\x1b[0m This wallet only supports up to {MAX_ADDRESSES} addresses, you have {} addresses ", "Warning:", wallet.addresses().len() )); diff --git a/src/lib.rs b/src/lib.rs index c20bd76..89de44f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,4 +42,20 @@ pub const MIN_CONVERTIBLE: Dusk = Dusk::new(1); /// The length of an epoch in blocks pub const EPOCH: u64 = 2160; /// Max addresses the wallet can store -pub const MAX_ADDRESSES: usize = 255; +pub const MAX_ADDRESSES: usize = get_max_addresses(); + +const DEFAULT_MAX_ADDRESSES: usize = 255; + +const fn get_max_addresses() -> usize { + match option_env!("WALLET_MAX_ADDR") { + Some(v) => match konst::primitive::parse_usize(v) { + Ok(e) if e > DEFAULT_MAX_ADDRESSES => { + panic!("WALLET_MAX_ADDR must be lower or equal to 255") + } + Ok(e) if e > 5 => e, + Ok(_) => panic!("WALLET_MAX_ADDR must be greater than 5"), + Err(_) => panic!("Invalid WALLET_MAX_ADDR"), + }, + None => DEFAULT_MAX_ADDRESSES, + } +}