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:
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