upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/selftest.cpp
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/selftest.cpp
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/selftest.cpp')
-rw-r--r--src/selftest.cpp30
1 files changed, 3 insertions, 27 deletions
diff --git a/src/selftest.cpp b/src/selftest.cpp
index 6792ae7..b733c60 100644
--- a/src/selftest.cpp
+++ b/src/selftest.cpp
@@ -286,33 +286,9 @@ static int RunWalletKeyPoolSelfTest()
286 return nFail == 0 ? 0 : 1; 286 return nFail == 0 ? 0 : 1;
287} 287}
288 288
289// A -mwindows binary starts with no console attached, so stdout goes nowhere 289// AttachTerminal() moved to util.h: the wallet phrase commands need it too,
290// even when it was launched from a terminal. Borrow the caller's console for 290// and two copies of a console-attach that must get its one condition right is
291// the duration of the self-test. Nothing to do on Linux, where stdout is 291// one copy too many.
292// already connected.
293static void AttachTerminal()
294{
295#ifdef _WIN32
296 // Only when there is nowhere for stdout to go. If the caller redirected it
297 // to a file or a pipe -- which is what `make tests > log` and any CI does --
298 // that handle is inherited and already works, and reopening it on CONOUT$
299 // would take the output away from the file and put it on the screen. That
300 // was the first version of this fix, and it broke the one case that
301 // mattered.
302 HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
303 if (hOut != NULL && hOut != INVALID_HANDLE_VALUE)
304 return;
305
306 if (AttachConsole(ATTACH_PARENT_PROCESS))
307 {
308 // Return values ignored on purpose: if the reopen fails there is
309 // nowhere left to report it, and the exit status still carries the
310 // result.
311 freopen("CONOUT$", "w", stdout);
312 freopen("CONOUT$", "w", stderr);
313 }
314#endif
315}
316 292
317static int RunWalletHDSelfTest() 293static int RunWalletHDSelfTest()
318{ 294{