upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/walletcmd.h
diff options
context:
space:
mode:
authorBitflash <btf01@proton.me>2026-08-01 17:57:07 -0300
committerGitHub <noreply@github.com>2026-08-01 17:57:07 -0300
commit7de7ef89d3365f8f9c2eb2b6ed0193c3033e221c (patch)
treedba509ae6b245be76b88ad0ae467aeb997a85b4d /src/walletcmd.h
parentce59d8c72c667ce638bd12f37db26d8b3408a5d2 (diff)
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.
Diffstat (limited to 'src/walletcmd.h')
-rw-r--r--src/walletcmd.h43
1 files changed, 43 insertions, 0 deletions
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 @@
1// Copyright (c) 2026 Bitflash developers
2// Distributed under the MIT/X11 software license.
3//
4// Recovery-phrase commands. Both run against a loaded wallet and then exit;
5// neither starts the node.
6
7#ifndef BITFLASH_WALLETCMD_H
8#define BITFLASH_WALLETCMD_H
9
10#include <string>
11
12// Create a phrase for a wallet that does not have one, install the seed, and
13// show the words once. Refuses if a phrase already exists. Returns 0 on success.
14int CmdNewPhrase();
15
16// Install the seed a phrase describes, derive forward looking for used
17// addresses, and rescan the chain so their coins appear. Returns 0 on success.
18int CmdRestorePhrase(const std::string& strMnemonic, int nMinDepth = 0);
19
20// Called once per batch with how many addresses have been derived so far and
21// how many transactions the wallet now holds.
22typedef void (*RestoreProgressFn)(void* pArg, int nDerived, int nRecovered);
23
24// The restore itself, shared by the command and the GUI so the two cannot
25// drift apart. Returns false without touching the wallet if the chain is not
26// loaded or the phrase is not valid.
27bool RestoreFromPhrase(const std::string& strMnemonic,
28 int nMinDepth,
29 RestoreProgressFn fnProgress,
30 void* pArg,
31 std::string& strErrorRet,
32 int& nRecoveredRet,
33 int& nDerivedRet);
34
35// Take the next address from the key pool and print it. With a recovery phrase
36// installed the address is derived, so the phrase can bring back whatever is
37// paid to it.
38int CmdNewAddress();
39
40// Diagnostic: print the first nCount addresses this wallet's phrase derives.
41int CmdShowDerived(int nCount);
42
43#endif