From f479d9111fa10721d0fe901484d802a432623a6f Mon Sep 17 00:00:00 2001 From: Michel van Kessel Date: Sun, 20 Dec 2020 21:59:13 +0100 Subject: [PATCH] update wallet section --- src/ui_interface.h | 5 + src/wallet/db.cpp | 48 ++- src/wallet/db.h | 14 +- src/wallet/rpcdump.cpp | 63 ++- src/wallet/rpcwallet.cpp | 412 +++++++++++++++---- src/wallet/wallet.cpp | 848 +++++++++++++++++++-------------------- src/wallet/wallet.h | 60 +-- src/wallet/walletdb.cpp | 47 ++- src/wallet/walletdb.h | 11 +- 9 files changed, 880 insertions(+), 628 deletions(-) diff --git a/src/ui_interface.h b/src/ui_interface.h index d8401d1e4..850b6bb5d 100644 --- a/src/ui_interface.h +++ b/src/ui_interface.h @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -105,6 +106,10 @@ public: /** Banlist did change. */ boost::signals2::signal BannedListChanged; + + /** Update the staked stats in the wallet header */ + + boost::signals2::signal SetStaked; }; /** Show warning message **/ diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp index 236c1d324..99eb71c2e 100644 --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -3,13 +3,15 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "db.h" +#include -#include "addrman.h" -#include "hash.h" -#include "protocol.h" -#include "util.h" -#include "utilstrencodings.h" +#include +#include +#include +#include +#include +#include +#include #include @@ -63,7 +65,7 @@ CDBEnv::~CDBEnv() { EnvShutdown(); delete dbenv; - dbenv = NULL; + dbenv = nullptr; } void CDBEnv::Close() @@ -154,10 +156,11 @@ CDBEnv::VerifyResult CDBEnv::Verify(const std::string& strFile, bool (*recoverFu assert(mapFileUseCount.count(strFile) == 0); Db db(dbenv, 0); - int result = db.verify(strFile.c_str(), NULL, NULL, 0); + int result = db.verify(strFile.c_str(), nullptr, nullptr, 0); + if (result == 0) return VERIFY_OK; - else if (recoverFunc == NULL) + else if (recoverFunc == nullptr) return RECOVER_FAIL; // Try to recover: @@ -182,7 +185,7 @@ bool CDBEnv::Salvage(const std::string& strFile, bool fAggressive, std::vectorlsn_reset(strFile.c_str(), 0); } - -CDB::CDB(const std::string& strFilename, const char* pszMode, bool fFlushOnCloseIn) : pdb(NULL), activeTxn(NULL) +CDB::CDB(const std::string& strFilename, const char* pszMode, bool fFlushOnCloseIn) : pdb(nullptr), activeTxn(nullptr) { int ret; fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w')); @@ -248,7 +250,7 @@ CDB::CDB(const std::string& strFilename, const char* pszMode, bool fFlushOnClose if (strFilename.empty()) return; - bool fCreate = strchr(pszMode, 'c') != NULL; + bool fCreate = strchr(pszMode, 'c') != nullptr; unsigned int nFlags = DB_THREAD; if (fCreate) nFlags |= DB_CREATE; @@ -261,7 +263,7 @@ CDB::CDB(const std::string& strFilename, const char* pszMode, bool fFlushOnClose strFile = strFilename; ++bitdb.mapFileUseCount[strFile]; pdb = bitdb.mapDb[strFile]; - if (pdb == NULL) { + if (pdb == nullptr) { pdb = new Db(bitdb.dbenv, 0); bool fMockDb = bitdb.IsMock(); @@ -281,7 +283,7 @@ CDB::CDB(const std::string& strFilename, const char* pszMode, bool fFlushOnClose if (ret != 0) { delete pdb; - pdb = NULL; + pdb = nullptr; --bitdb.mapFileUseCount[strFile]; strFile = ""; throw runtime_error(strprintf("CDB: Error %d, can't open database %s", ret, strFilename)); @@ -318,8 +320,8 @@ void CDB::Close() return; if (activeTxn) activeTxn->abort(); - activeTxn = NULL; - pdb = NULL; + activeTxn = nullptr; + pdb = nullptr; if (fFlushOnClose) Flush(); @@ -334,12 +336,12 @@ void CDBEnv::CloseDb(const string& strFile) { { LOCK(cs_db); - if (mapDb[strFile] != NULL) { + if (mapDb[strFile] != nullptr) { // Close the database handle Db* pdb = mapDb[strFile]; pdb->close(0); delete pdb; - mapDb[strFile] = NULL; + mapDb[strFile] = nullptr; } } } @@ -349,7 +351,7 @@ bool CDBEnv::RemoveDb(const string& strFile) this->CloseDb(strFile); LOCK(cs_db); - int rc = dbenv->dbremove(NULL, strFile.c_str(), NULL, DB_AUTO_COMMIT); + int rc = dbenv->dbremove(NULL, strFile.c_str(), nullptr, DB_AUTO_COMMIT); return (rc == 0); } @@ -420,10 +422,10 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip) } if (fSuccess) { Db dbA(bitdb.dbenv, 0); - if (dbA.remove(strFile.c_str(), NULL, 0)) + if (dbA.remove(strFile.c_str(), nullptr, 0)) fSuccess = false; Db dbB(bitdb.dbenv, 0); - if (dbB.rename(strFileRes.c_str(), NULL, strFile.c_str(), 0)) + if (dbB.rename(strFileRes.c_str(), nullptr, strFile.c_str(), 0)) fSuccess = false; } if (!fSuccess) @@ -431,8 +433,10 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip) return fSuccess; } } + MilliSleep(100); } + return false; } diff --git a/src/wallet/db.h b/src/wallet/db.h index 01b8c71a0..3a887ad4f 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -6,11 +6,11 @@ #ifndef BITCOIN_WALLET_DB_H #define BITCOIN_WALLET_DB_H -#include "clientversion.h" -#include "serialize.h" -#include "streams.h" -#include "sync.h" -#include "version.h" +#include +#include +#include +#include +#include #include #include @@ -100,7 +100,7 @@ protected: bool fReadOnly; bool fFlushOnClose; - explicit CDB(const std::string& strFilename, const char* pszMode = "r+", bool fFlushOnCloseIn=true); + explicit CDB(const std::string& strFilename, const char* pszMode = "r+", bool fFlushOnCloseIn = true); ~CDB() { Close(); } public: @@ -306,7 +306,7 @@ public: return Write(std::string("version"), nVersion); } - bool static Rewrite(const std::string& strFile, const char* pszSkip = NULL); + bool static Rewrite(const std::string& strFile, const char* pszSkip = nullptr); }; #endif // BITCOIN_WALLET_DB_H diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index b0691bd4a..db184c540 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -2,20 +2,20 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "base58.h" -#include "chain.h" -#include "dstencode.h" -#include "rpc/server.h" -#include "init.h" -#include "main.h" -#include "script/script.h" -#include "script/standard.h" -#include "sync.h" -#include "util.h" -#include "utiltime.h" -#include "wallet.h" -#include "merkleblock.h" -#include "core_io.h" +#include +#include +#include +#include +#include +#include +#include