Skip to content

Commit cbccc0c

Browse files
committed
use CLI index if it's higher than state directory
1 parent 50b33dc commit cbccc0c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ result*
44
*.skey
55
*.vkey
66
*.mnemonic
7+
challenges.json
8+
state*

src/main.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,13 @@ fn run_app(cli: Cli) -> Result<(), String> {
628628
current_challenge_id.clear();
629629

630630
fn next_wallet_deriv_index_for_challenge(base_dir: &Option<String>, data_dir: &DataDir, challenge_id: &str) -> Result<u32, String> {
631+
let initial_deriv_index = match data_dir {
632+
DataDir::Mnemonic(wallet) => wallet.deriv_index,
633+
// Handle other DataDir variants if necessary, or panic/return an error
634+
// for cases where deriv_index is not applicable/available.
635+
// For this specific logic, we assume it's only called with DataDir::Mnemonic.
636+
_ => return Err("next_wallet_deriv_index_for_challenge called with non-Mnemonic DataDir".to_string()),
637+
};
631638
Ok(if let Some(data_base_dir) = base_dir {
632639
let mut account_dir = data_dir.receipt_dir(data_base_dir, challenge_id)?;
633640
account_dir.pop();
@@ -657,10 +664,15 @@ fn run_app(cli: Cli) -> Result<(), String> {
657664
if let Some(highest_index_string) = indices.pop() {
658665
let highest_index = highest_index_string.parse::<u32>()
659666
.map_err(|e| format!("Wallet derivation index directory name is not a positive integer: {}", e))?;
660-
highest_index + 1
667+
if initial_deriv_index > highest_index {
668+
eprintln!("Using initial deriv_index {} which is higher than highest existing index {}", initial_deriv_index, highest_index);
669+
initial_deriv_index
670+
} else {
671+
highest_index + 1
672+
}
661673
} else {
662-
eprintln!("no highest index");
663-
0
674+
eprintln!("no highest index: using {}", initial_deriv_index);
675+
initial_deriv_index
664676
}
665677
} else {
666678
0

0 commit comments

Comments
 (0)