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/util.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/util.h') diff --git a/src/util.h b/src/util.h index 25ef118..d95d3ae 100644 --- a/src/util.h +++ b/src/util.h @@ -293,6 +293,33 @@ void PrintHex(const T pbegin, const T pend, const char* pszFormat="%s", bool fSp // Forward declaration -- defined in main.cpp string GetAppDir(); +// Give a command-line operation somewhere to print. +// +// The Windows binary is linked -mwindows and starts with no console, so stdout +// goes nowhere even when it was launched from a terminal. Commands that report +// to the person who typed them -- the self-tests, the wallet phrase commands -- +// call this first. +// +// Only when there is nowhere for stdout to go already: if the caller redirected +// it to a file or a pipe, that handle is inherited and works, and reopening it +// on CONOUT$ would take the output away from the file and put it on the screen. +inline void AttachTerminal() +{ +#ifdef _WIN32 + HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); + if (hOut != NULL && hOut != INVALID_HANDLE_VALUE) + return; + if (AttachConsole(ATTACH_PARENT_PROCESS)) + { + // Return values ignored on purpose: if the reopen fails there is + // nowhere left to report it, and the exit status still carries the + // result. + freopen("CONOUT$", "w", stdout); + freopen("CONOUT$", "w", stderr); + } +#endif +} + inline int OutputDebugStringF(const char* pszFormat, ...) BF_FORMAT(1, 2); inline int OutputDebugStringF(const char* pszFormat, ...) -- cgit v1.2.3