Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion neptune-core-cli/src/command/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ pub(crate) enum WalletCommand {
/// Get next unused generation receiving address
NextReceivingAddress,

/// Get the nth generation receiving address.
/// Get the nth address of the specified type
///
/// Ignoring the ones that have been generated in the past; re-generate them
/// if necessary. Do not increment any counters or modify state in any way.
NthReceivingAddress {
index: usize,

key_type: KeyType,

#[clap(long, default_value_t)]
network: Network,
},
Expand Down
26 changes: 18 additions & 8 deletions neptune-core-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,20 @@ async fn main() -> Result<()> {
print_seed_phrase_dialog(wallet_secret.secret_key());
return Ok(());
}
Command::Wallet(WalletCommand::NthReceivingAddress { network, index }) => {
return print_nth_receiving_address(*network, args.data_dir.clone(), *index);
Command::Wallet(WalletCommand::NthReceivingAddress {
network,
key_type,
index,
}) => {
return print_nth_receiving_address(*network, args.data_dir.clone(), *key_type, *index);
}
Command::Wallet(WalletCommand::PremineReceivingAddress { network }) => {
return print_nth_receiving_address(*network, args.data_dir.clone(), 0);
return print_nth_receiving_address(
*network,
args.data_dir.clone(),
KeyType::Generation,
0,
);
}
Command::Wallet(WalletCommand::ShamirCombine { t, network }) => {
let wallet_dir =
Expand Down Expand Up @@ -1197,23 +1206,24 @@ fn get_wallet_entropy(network: Network, data_dir: Option<PathBuf>) -> Result<Wal
fn print_nth_receiving_address(
network: Network,
data_dir: Option<PathBuf>,
key_type: KeyType,
index: usize,
) -> Result<()> {
let wallet_entropy = get_wallet_entropy(network, data_dir)?;

let nth_spending_key = wallet_entropy.nth_generation_spending_key(index as u64);
let nth_receiving_address = nth_spending_key.to_address();
let nth_address_as_string = match nth_receiving_address.to_bech32m(network) {
let key = wallet_entropy.nth_spending_key(key_type, index as u64);
let address = key.to_address();
let address = match address.to_bech32m(network) {
Ok(s) => s,
Err(e) => {
eprintln!(
"Could not export address as bech32m; got error:{e}\nRaw address:\n{nth_receiving_address:?}"
"Could not export address as bech32m; got error:{e}\nRaw address:\n{address:?}"
);
return Ok(());
}
};

println!("{nth_address_as_string}");
println!("{address}");
Ok(())
}

Expand Down
Loading