From 7de7ef89d3365f8f9c2eb2b6ed0193c3033e221c Mon Sep 17 00:00:00 2001 From: Bitflash Date: Sat, 1 Aug 2026 17:57:07 -0300 Subject: wallet: create and restore a recovery phrase (#96) Adds -newphrase, -restorephrase, -restoredepth, -newaddress and -showderived, plus the window buttons that reach the same code. Restore derives forward in batches of 100 and rescans after each, stopping when a whole batch turns up nothing; the phrase is shown on the terminal only, never in debug.log. Proved end to end on a live wallet: paid a derived address, deleted wallet.dat, restored from the twelve words and recovered the coin. Coins on the pre-seed default address do not come back, and the command says so. --- src/walletcmd.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/walletcmd.h (limited to 'src/walletcmd.h') diff --git a/src/walletcmd.h b/src/walletcmd.h new file mode 100644 index 0000000..89834d8 --- /dev/null +++ b/src/walletcmd.h @@ -0,0 +1,43 @@ +// Copyright (c) 2026 Bitflash developers +// Distributed under the MIT/X11 software license. +// +// Recovery-phrase commands. Both run against a loaded wallet and then exit; +// neither starts the node. + +#ifndef BITFLASH_WALLETCMD_H +#define BITFLASH_WALLETCMD_H + +#include + +// Create a phrase for a wallet that does not have one, install the seed, and +// show the words once. Refuses if a phrase already exists. Returns 0 on success. +int CmdNewPhrase(); + +// Install the seed a phrase describes, derive forward looking for used +// addresses, and rescan the chain so their coins appear. Returns 0 on success. +int CmdRestorePhrase(const std::string& strMnemonic, int nMinDepth = 0); + +// Called once per batch with how many addresses have been derived so far and +// how many transactions the wallet now holds. +typedef void (*RestoreProgressFn)(void* pArg, int nDerived, int nRecovered); + +// The restore itself, shared by the command and the GUI so the two cannot +// drift apart. Returns false without touching the wallet if the chain is not +// loaded or the phrase is not valid. +bool RestoreFromPhrase(const std::string& strMnemonic, + int nMinDepth, + RestoreProgressFn fnProgress, + void* pArg, + std::string& strErrorRet, + int& nRecoveredRet, + int& nDerivedRet); + +// Take the next address from the key pool and print it. With a recovery phrase +// installed the address is derived, so the phrase can bring back whatever is +// paid to it. +int CmdNewAddress(); + +// Diagnostic: print the first nCount addresses this wallet's phrase derives. +int CmdShowDerived(int nCount); + +#endif -- cgit v1.2.3