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 16:14:19 -0300
committerbitflash <dev@bitflash.network>2026-08-18 16:14:19 -0300
commit3f94ec0649f935d00de49ad7b55026317dc64a27 (patch)
treee67ff06c8341889cf90cbbc3b835507a90510b64 /src/main_gui.cpp
parentf3fb7ce6759ac98a7cc39d586fc2824982c74acd (diff)
wallet: make SQLite the default backend for new wallets
A fresh install with no wallet.dat now starts on the SQLite backend and creates wallet.sqlite, instead of a Berkeley DB wallet.dat. The choice is recorded in a plain-text <datadir>/wallet-backend marker so it survives a restart without a command-line flag. Backend resolution when no -walletbackend is given: an existing wallet.sqlite (or a "sqlite" marker) stays on SQLite; an existing wallet.dat stays on Berkeley DB -- nothing is converted behind the user; a fresh datadir starts on SQLite. An explicit -walletbackend=bdb or a "bdb" marker forces Berkeley DB and overrides the default. Adds CreateNewSQLiteWallet() (WalletSQLiteRuntimeOpen gains fMustExist so the create path can make a new file) which mints the first default key straight into the SQLite store via the same FinishLoadedWallet() call the Berkeley DB create path uses, then cleans up on failure. Marker read/write helpers are plain text, hand-editable. New wallet-backend-default self-test proves the resolution in child processes (fresh->SQLite+marker, existing wallet.dat->BDB, "bdb" marker->BDB, explicit flag->wallet.dat). The three wallet.dat-specific suites now ask for -walletbackend=bdb explicitly, since a flagless fresh datadir is SQLite now. All wallet suites pass.
Diffstat (limited to 'src/main_gui.cpp')
-rw-r--r--src/main_gui.cpp80
1 files changed, 73 insertions, 7 deletions
diff --git a/src/main_gui.cpp b/src/main_gui.cpp
index af6053f..6cd8b75 100644
--- a/src/main_gui.cpp
+++ b/src/main_gui.cpp
@@ -743,14 +743,80 @@ int main(int argc, char* argv[])
743 DBFlush(true); 743 DBFlush(true);
744 return 0; 744 return 0;
745 } 745 }
746 else if (!LoadWallet()) 746 else if (strWalletBackend == "bdb")
747 { 747 {
748 // LoadWallet() explains itself into strWalletLoadError when it 748 // Explicit -walletbackend=bdb overrides the marker and the default:
749 // knows why -- an unsupported wallet format, for one, which is the 749 // force Berkeley DB (LoadWallet creates wallet.dat if none exists).
750 // case this whole path exists to make visible. 750 if (!LoadWallet())
751 FatalStartupError(fHeadlessStartup, "Cannot open wallet.dat.", 751 {
752 strWalletLoadError); 752 FatalStartupError(fHeadlessStartup, "Cannot open wallet.dat.",
753 return 1; 753 strWalletLoadError);
754 return 1;
755 }
756 }
757 else
758 {
759 // No explicit -walletbackend on the command line. Resolve it from
760 // the persistent marker, then defaults: an existing wallet.sqlite
761 // stays on SQLite, an existing wallet.dat stays on Berkeley DB (the
762 // GUI offers to convert), and a fresh install starts on SQLite --
763 // the new default. wallet.dat is never touched by any of this.
764 string strSQLitePath = GetAppDir() + "/wallet.sqlite";
765 bool fSQLiteExists = FileExists(strSQLitePath.c_str());
766 bool fWalletDatExists = FileExists((GetAppDir() + "/wallet.dat").c_str());
767 string strMarker = ReadWalletBackendMarker();
768
769 bool fUseSQLite = false;
770 bool fCreateSQLite = false;
771 if (strMarker == "sqlite")
772 {
773 if (fSQLiteExists) fUseSQLite = true;
774 else if (fWalletDatExists) fUseSQLite = false; // marker stale; real wallet is BDB
775 else { fUseSQLite = true; fCreateSQLite = true; }
776 }
777 else if (strMarker == "bdb")
778 {
779 fUseSQLite = false;
780 }
781 else // no marker recorded yet
782 {
783 if (fSQLiteExists && !fWalletDatExists) fUseSQLite = true;
784 else if (fWalletDatExists) fUseSQLite = false;
785 else { fUseSQLite = true; fCreateSQLite = true; }
786 }
787
788 if (fUseSQLite)
789 {
790 AttachTerminal();
791 bool fOk = fCreateSQLite
792 ? CreateNewSQLiteWallet(strSQLitePath)
793 : LoadWalletFromSQLiteRuntime(strSQLitePath);
794 if (!fOk)
795 {
796 FatalStartupError(fHeadlessStartup,
797 fCreateSQLite ? "Cannot create the SQLite wallet."
798 : "Cannot open the SQLite wallet.",
799 strWalletLoadError);
800 return 1;
801 }
802 // Record the choice so it is stable from here on.
803 if (ReadWalletBackendMarker() != "sqlite")
804 WriteWalletBackendMarker("sqlite");
805 fprintf(stderr, "Wallet backend: SQLite\n %s\n%s",
806 strSQLitePath.c_str(),
807 fCreateSQLite ? "A new wallet was created here.\n" : "");
808 fflush(stderr);
809 // Fall through and run the node; CWalletDB routes to this file.
810 }
811 else if (!LoadWallet())
812 {
813 // LoadWallet() explains itself into strWalletLoadError when it
814 // knows why -- an unsupported wallet format, for one, which is
815 // the case this whole path exists to make visible.
816 FatalStartupError(fHeadlessStartup, "Cannot open wallet.dat.",
817 strWalletLoadError);
818 return 1;
819 }
754 } 820 }
755 821
756 // After the block index, so there is a chain to compare the wallet 822 // After the block index, so there is a chain to compare the wallet