MCPcopy Create free account
hub / github.com/ElementsProject/elements / LoadWallet

Method LoadWallet

src/wallet/walletdb.cpp:839–1037  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

837}
838
839DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
840{
841 CWalletScanState wss;
842 bool fNoncriticalErrors = false;
843 bool rescan_required = false;
844 DBErrors result = DBErrors::LOAD_OK;
845
846 LOCK(pwallet->cs_wallet);
847 try {
848 int nMinVersion = 0;
849 if (m_batch->Read(DBKeys::MINVERSION, nMinVersion)) {
850 if (nMinVersion > FEATURE_LATEST)
851 return DBErrors::TOO_NEW;
852 pwallet->LoadMinVersion(nMinVersion);
853 }
854
855 // Load wallet flags, so they are known when processing other records.
856 // The FLAGS key is absent during wallet creation.
857 uint64_t flags;
858 if (m_batch->Read(DBKeys::FLAGS, flags)) {
859 if (!pwallet->LoadWalletFlags(flags)) {
860 pwallet->WalletLogPrintf("Error reading wallet database: Unknown non-tolerable wallet flags found\n");
861 return DBErrors::CORRUPT;
862 }
863 }
864
865#ifndef ENABLE_EXTERNAL_SIGNER
866 if (pwallet->IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) {
867 pwallet->WalletLogPrintf("Error: External signer wallet being loaded without external signer support compiled\n");
868 return DBErrors::EXTERNAL_SIGNER_SUPPORT_REQUIRED;
869 }
870#endif
871
872 // Get cursor
873 if (!m_batch->StartCursor())
874 {
875 pwallet->WalletLogPrintf("Error getting wallet database cursor\n");
876 return DBErrors::CORRUPT;
877 }
878
879 while (true)
880 {
881 // Read next record
882 CDataStream ssKey(SER_DISK, CLIENT_VERSION);
883 CDataStream ssValue(SER_DISK, CLIENT_VERSION);
884 bool complete;
885 bool ret = m_batch->ReadAtCursor(ssKey, ssValue, complete);
886 if (complete) {
887 break;
888 }
889 else if (!ret)
890 {
891 m_batch->CloseCursor();
892 pwallet->WalletLogPrintf("Error reading next record from wallet database\n");
893 return DBErrors::CORRUPT;
894 }
895
896 // Try to be tolerant of single corrupt records:

Callers

nothing calls this directly

Calls 15

ReadKeyValueFunction · 0.85
LoadWalletFlagsMethod · 0.80
IsWalletFlagSetMethod · 0.80
GetScriptPubKeyManMethod · 0.80
SetCacheMethod · 0.80
AddCryptedKeyMethod · 0.80
MakeNewKeyMethod · 0.80
SetMasterBlindingKeyMethod · 0.80
IsLegacyMethod · 0.80
UpdateTimeFirstKeyMethod · 0.80

Tested by

no test coverage detected