Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #211 from dusk-network/max_addresses
Browse files Browse the repository at this point in the history
Allow to specify different MAX_ADDRESSES
  • Loading branch information
herr-seppia authored Oct 11, 2023
2 parents 1e84969 + ba95706 commit 40b1e84
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion src/bin/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/bin/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -151,7 +151,7 @@ fn menu_addr(wallet: &Wallet<WalletFile>) -> anyhow::Result<AddrSelect> {
// 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()
));
Expand Down
18 changes: 17 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

0 comments on commit 40b1e84

Please sign in to comment.