upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/main_gui.cpp
diff options
context:
space:
mode:
authorbitflash <dev@bitflash.network>2026-08-18 14:44:11 -0300
committerbitflash <dev@bitflash.network>2026-08-18 14:44:11 -0300
commit84a60275569dca5d1fb12db38ce184caf7487ed6 (patch)
tree23e39a26b340324a7a33a115aded3b70b5332816 /src/main_gui.cpp
parent440d7f393d74f309d29e1d10ba1f11c41c869226 (diff)
wallet: one-shot storage commands honour -walletbackend=sqlite
-walletstorageaudit, -walletstoragecheck and -backupwallet all read wallet.dat regardless of the selected backend. Under -walletbackend=sqlite that is wrong, and for backup it is dangerous: it silently backs up the stale plaintext wallet.dat instead of the live wallet.sqlite. - ScanWalletRecords() routes to the active SQLite store instead of a Berkeley DB cursor (it returned an error under the runtime before). This is the single choke point audit and check scan through. - WalletSQLiteRuntimeOpenReadOnly() opens wallet.sqlite for scanning without loading or validating records, so the pre-load diagnostics can inspect a wallet the loader would refuse. main_gui opens it for audit/check when the SQLite backend is selected (and rejects an unknown backend value there too). - BackupWallet() copies wallet.sqlite (checkpoint, then the temp/old/rename dance; a checkpointed SQLite file is self-contained, no lsn_reset). wallet-sqlite-encrypt self-test proves routing on a datadir where the SQLite wallet is encrypted and wallet.dat beside it is still plaintext: audit with the flag reports the encrypted seed, without it reports the plaintext one; the SQLite backup carries no plaintext key and loadchecks as a standalone wallet.
Diffstat (limited to 'src/main_gui.cpp')
-rw-r--r--src/main_gui.cpp50
1 files changed, 44 insertions, 6 deletions
diff --git a/src/main_gui.cpp b/src/main_gui.cpp
index 4be4995..af6053f 100644
--- a/src/main_gui.cpp
+++ b/src/main_gui.cpp
@@ -524,19 +524,57 @@ int main(int argc, char* argv[])
524 // explain wallet.dat states that the normal wallet loader may refuse. 524 // explain wallet.dat states that the normal wallet loader may refuse.
525 string strWalletStorageAuditJson = 525 string strWalletStorageAuditJson =
526 argval2(argc, argv, "/walletstorageauditjson", "-walletstorageauditjson"); 526 argval2(argc, argv, "/walletstorageauditjson", "-walletstorageauditjson");
527 if (arg(argc,argv,"/walletstorageaudit") || 527 bool fDiagWantsAudit = arg(argc,argv,"/walletstorageaudit") ||
528 arg(argc,argv,"-walletstorageaudit") || 528 arg(argc,argv,"-walletstorageaudit") ||
529 !strWalletStorageAuditJson.empty()) 529 !strWalletStorageAuditJson.empty();
530 bool fDiagWantsCheck = arg(argc,argv,"/walletstoragecheck") ||
531 arg(argc,argv,"-walletstoragecheck");
532
533 // These diagnostics normally read wallet.dat. Under -walletbackend=sqlite
534 // the live wallet is wallet.sqlite, so open it read-only as the active
535 // store and let the same scan walk the right file. This runs before the
536 // normal backend resolution further down, so validate the value here too.
537 string strDiagBackend = argval2(argc, argv, "/walletbackend", "-walletbackend");
538 if ((fDiagWantsAudit || fDiagWantsCheck) && !strDiagBackend.empty() &&
539 strDiagBackend != "sqlite" && strDiagBackend != "bdb")
540 {
541 AttachTerminal();
542 fprintf(stderr, "Unknown wallet backend '%s'. Use -walletbackend=sqlite "
543 "or -walletbackend=bdb.\n", strDiagBackend.c_str());
544 return 1;
545 }
546 bool fDiagSQLite = (strDiagBackend == "sqlite") &&
547 (fDiagWantsAudit || fDiagWantsCheck);
548 if (fDiagSQLite)
549 {
550 AttachTerminal();
551 string strSQLitePath = GetAppDir() + "/wallet.sqlite";
552 string strOpenErr;
553 if (!WalletSQLiteRuntimeOpenReadOnly(strSQLitePath, strOpenErr))
554 {
555 fprintf(stderr, "Cannot open the SQLite wallet for diagnostics: %s\n",
556 strOpenErr.c_str());
557 return 1;
558 }
559 }
560
561 if (fDiagWantsAudit)
530 { 562 {
531 int nRet = CmdWalletStorageAudit(strWalletStorageAuditJson); 563 int nRet = CmdWalletStorageAudit(strWalletStorageAuditJson);
532 DBFlush(true); 564 if (fDiagSQLite)
565 WalletSQLiteRuntimeClose();
566 else
567 DBFlush(true);
533 return nRet; 568 return nRet;
534 } 569 }
535 570
536 if (arg(argc,argv,"/walletstoragecheck") || arg(argc,argv,"-walletstoragecheck")) 571 if (fDiagWantsCheck)
537 { 572 {
538 int nRet = CmdWalletStorageCheck(); 573 int nRet = CmdWalletStorageCheck();
539 DBFlush(true); 574 if (fDiagSQLite)
575 WalletSQLiteRuntimeClose();
576 else
577 DBFlush(true);
540 return nRet; 578 return nRet;
541 } 579 }
542 580