Merge #13774: Return void instead of bool for functions that cannot fail
d78a8dc3e8
Return void instead of bool for functions that cannot fail (practicalswift)
Pull request description:
Return `void` instead of `bool` for functions that cannot fail:
* `CBlockTreeDB::ReadReindexing(...)`
* `CChainState::ResetBlockFailureFlags(...)`
* `CTxMemPool::addUnchecked(...)`
* `CWallet::CommitTransaction(...)`
* `CWallet::LoadDestData(...)`
* `CWallet::LoadKeyMetadata(...)`
* `CWallet::LoadScriptMetadata(...)`
* `CWallet::LoadToWallet(...)`
* `CWallet::SetHDChain(...)`
* `CWallet::SetHDSeed(...)`
* `PendingWalletTx::commit(...)`
* `RemoveLocal(...)`
* `SetMinVersion(...)`
* `StartHTTPServer(...)`
* `StartRPC(...)`
* `TorControlConnection::Disconnect(...)`
Some of the functions can fail by throwing.
Found by manually inspecting the following candidate functions:
```
$ git grep -E '(^((static|virtual|inline|friend)[^a-z])*[^a-z]*bool [^=]*\(|return true|return false)' -- "*.cpp" "*.h"
```
Tree-SHA512: c0014e045362dbcd1a0cc8f69844e7b8cbae4f538e7632028daeca3a797ac11d8d3d86ebc480bedcb8626df3e96779d592747d52a12556fc49921b114fa0ccc6
This commit is contained in:
commit
ad51e1372b
17 changed files with 41 additions and 74 deletions
|
@ -423,7 +423,7 @@ std::thread threadHTTP;
|
||||||
std::future<bool> threadResult;
|
std::future<bool> threadResult;
|
||||||
static std::vector<std::thread> g_thread_http_workers;
|
static std::vector<std::thread> g_thread_http_workers;
|
||||||
|
|
||||||
bool StartHTTPServer()
|
void StartHTTPServer()
|
||||||
{
|
{
|
||||||
LogPrint(BCLog::HTTP, "Starting HTTP server\n");
|
LogPrint(BCLog::HTTP, "Starting HTTP server\n");
|
||||||
int rpcThreads = std::max((long)gArgs.GetArg("-rpcthreads", DEFAULT_HTTP_THREADS), 1L);
|
int rpcThreads = std::max((long)gArgs.GetArg("-rpcthreads", DEFAULT_HTTP_THREADS), 1L);
|
||||||
|
@ -435,7 +435,6 @@ bool StartHTTPServer()
|
||||||
for (int i = 0; i < rpcThreads; i++) {
|
for (int i = 0; i < rpcThreads; i++) {
|
||||||
g_thread_http_workers.emplace_back(HTTPWorkQueueRun, workQueue);
|
g_thread_http_workers.emplace_back(HTTPWorkQueueRun, workQueue);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterruptHTTPServer()
|
void InterruptHTTPServer()
|
||||||
|
|
|
@ -26,7 +26,7 @@ bool InitHTTPServer();
|
||||||
* This is separate from InitHTTPServer to give users race-condition-free time
|
* This is separate from InitHTTPServer to give users race-condition-free time
|
||||||
* to register their handlers between InitHTTPServer and StartHTTPServer.
|
* to register their handlers between InitHTTPServer and StartHTTPServer.
|
||||||
*/
|
*/
|
||||||
bool StartHTTPServer();
|
void StartHTTPServer();
|
||||||
/** Interrupt HTTP server threads */
|
/** Interrupt HTTP server threads */
|
||||||
void InterruptHTTPServer();
|
void InterruptHTTPServer();
|
||||||
/** Stop HTTP server */
|
/** Stop HTTP server */
|
||||||
|
|
|
@ -731,14 +731,12 @@ static bool AppInitServers()
|
||||||
RPCServer::OnStopped(&OnRPCStopped);
|
RPCServer::OnStopped(&OnRPCStopped);
|
||||||
if (!InitHTTPServer())
|
if (!InitHTTPServer())
|
||||||
return false;
|
return false;
|
||||||
if (!StartRPC())
|
StartRPC();
|
||||||
return false;
|
|
||||||
if (!StartHTTPRPC())
|
if (!StartHTTPRPC())
|
||||||
return false;
|
return false;
|
||||||
if (gArgs.GetBoolArg("-rest", DEFAULT_REST_ENABLE) && !StartREST())
|
if (gArgs.GetBoolArg("-rest", DEFAULT_REST_ENABLE) && !StartREST())
|
||||||
return false;
|
return false;
|
||||||
if (!StartHTTPServer())
|
StartHTTPServer();
|
||||||
return false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -235,12 +235,11 @@ bool AddLocal(const CNetAddr &addr, int nScore)
|
||||||
return AddLocal(CService(addr, GetListenPort()), nScore);
|
return AddLocal(CService(addr, GetListenPort()), nScore);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RemoveLocal(const CService& addr)
|
void RemoveLocal(const CService& addr)
|
||||||
{
|
{
|
||||||
LOCK(cs_mapLocalHost);
|
LOCK(cs_mapLocalHost);
|
||||||
LogPrintf("RemoveLocal(%s)\n", addr.ToString());
|
LogPrintf("RemoveLocal(%s)\n", addr.ToString());
|
||||||
mapLocalHost.erase(addr);
|
mapLocalHost.erase(addr);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Make a particular network entirely off-limits (no automatic connects to it) */
|
/** Make a particular network entirely off-limits (no automatic connects to it) */
|
||||||
|
|
|
@ -505,7 +505,7 @@ bool IsLimited(enum Network net);
|
||||||
bool IsLimited(const CNetAddr& addr);
|
bool IsLimited(const CNetAddr& addr);
|
||||||
bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
|
bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
|
||||||
bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
|
bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
|
||||||
bool RemoveLocal(const CService& addr);
|
void RemoveLocal(const CService& addr);
|
||||||
bool SeenLocal(const CService& addr);
|
bool SeenLocal(const CService& addr);
|
||||||
bool IsLocal(const CService& addr);
|
bool IsLocal(const CService& addr);
|
||||||
bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr);
|
bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr);
|
||||||
|
|
|
@ -301,12 +301,11 @@ bool CRPCTable::appendCommand(const std::string& name, const CRPCCommand* pcmd)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StartRPC()
|
void StartRPC()
|
||||||
{
|
{
|
||||||
LogPrint(BCLog::RPC, "Starting RPC\n");
|
LogPrint(BCLog::RPC, "Starting RPC\n");
|
||||||
fRPCRunning = true;
|
fRPCRunning = true;
|
||||||
g_rpcSignals.Started();
|
g_rpcSignals.Started();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterruptRPC()
|
void InterruptRPC()
|
||||||
|
|
|
@ -198,7 +198,7 @@ extern CAmount AmountFromValue(const UniValue& value);
|
||||||
extern std::string HelpExampleCli(const std::string& methodname, const std::string& args);
|
extern std::string HelpExampleCli(const std::string& methodname, const std::string& args);
|
||||||
extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
|
extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
|
||||||
|
|
||||||
bool StartRPC();
|
void StartRPC();
|
||||||
void InterruptRPC();
|
void InterruptRPC();
|
||||||
void StopRPC();
|
void StopRPC();
|
||||||
std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq);
|
std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq);
|
||||||
|
|
|
@ -91,7 +91,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Disconnect from Tor control port.
|
* Disconnect from Tor control port.
|
||||||
*/
|
*/
|
||||||
bool Disconnect();
|
void Disconnect();
|
||||||
|
|
||||||
/** Send a command, register a handler for the reply.
|
/** Send a command, register a handler for the reply.
|
||||||
* A trailing CRLF is automatically added.
|
* A trailing CRLF is automatically added.
|
||||||
|
@ -223,12 +223,11 @@ bool TorControlConnection::Connect(const std::string &target, const ConnectionCB
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorControlConnection::Disconnect()
|
void TorControlConnection::Disconnect()
|
||||||
{
|
{
|
||||||
if (b_conn)
|
if (b_conn)
|
||||||
bufferevent_free(b_conn);
|
bufferevent_free(b_conn);
|
||||||
b_conn = nullptr;
|
b_conn = nullptr;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorControlConnection::Command(const std::string &cmd, const ReplyHandlerCB& reply_handler)
|
bool TorControlConnection::Command(const std::string &cmd, const ReplyHandlerCB& reply_handler)
|
||||||
|
|
|
@ -160,9 +160,8 @@ bool CBlockTreeDB::WriteReindexing(bool fReindexing) {
|
||||||
return Erase(DB_REINDEX_FLAG);
|
return Erase(DB_REINDEX_FLAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBlockTreeDB::ReadReindexing(bool &fReindexing) {
|
void CBlockTreeDB::ReadReindexing(bool &fReindexing) {
|
||||||
fReindexing = Exists(DB_REINDEX_FLAG);
|
fReindexing = Exists(DB_REINDEX_FLAG);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBlockTreeDB::ReadLastBlockFile(int &nFile) {
|
bool CBlockTreeDB::ReadLastBlockFile(int &nFile) {
|
||||||
|
|
|
@ -92,7 +92,7 @@ public:
|
||||||
bool ReadBlockFileInfo(int nFile, CBlockFileInfo &info);
|
bool ReadBlockFileInfo(int nFile, CBlockFileInfo &info);
|
||||||
bool ReadLastBlockFile(int &nFile);
|
bool ReadLastBlockFile(int &nFile);
|
||||||
bool WriteReindexing(bool fReindexing);
|
bool WriteReindexing(bool fReindexing);
|
||||||
bool ReadReindexing(bool &fReindexing);
|
void ReadReindexing(bool &fReindexing);
|
||||||
bool WriteFlag(const std::string &name, bool fValue);
|
bool WriteFlag(const std::string &name, bool fValue);
|
||||||
bool ReadFlag(const std::string &name, bool &fValue);
|
bool ReadFlag(const std::string &name, bool &fValue);
|
||||||
bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex);
|
bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex);
|
||||||
|
|
|
@ -357,7 +357,7 @@ void CTxMemPool::AddTransactionsUpdated(unsigned int n)
|
||||||
nTransactionsUpdated += n;
|
nTransactionsUpdated += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate)
|
void CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate)
|
||||||
{
|
{
|
||||||
NotifyEntryAdded(entry.GetSharedTx());
|
NotifyEntryAdded(entry.GetSharedTx());
|
||||||
// Add to memory pool without checking anything.
|
// Add to memory pool without checking anything.
|
||||||
|
@ -412,8 +412,6 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
|
||||||
|
|
||||||
vTxHashes.emplace_back(tx.GetWitnessHash(), newit);
|
vTxHashes.emplace_back(tx.GetWitnessHash(), newit);
|
||||||
newit->vTxHashesIdx = vTxHashes.size() - 1;
|
newit->vTxHashesIdx = vTxHashes.size() - 1;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
|
void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
|
||||||
|
@ -933,7 +931,7 @@ int CTxMemPool::Expire(int64_t time) {
|
||||||
return stage.size();
|
return stage.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CTxMemPool::addUnchecked(const uint256&hash, const CTxMemPoolEntry &entry, bool validFeeEstimate)
|
void CTxMemPool::addUnchecked(const uint256&hash, const CTxMemPoolEntry &entry, bool validFeeEstimate)
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
setEntries setAncestors;
|
setEntries setAncestors;
|
||||||
|
|
|
@ -539,8 +539,8 @@ public:
|
||||||
// Note that addUnchecked is ONLY called from ATMP outside of tests
|
// Note that addUnchecked is ONLY called from ATMP outside of tests
|
||||||
// and any other callers may break wallet's in-mempool tracking (due to
|
// and any other callers may break wallet's in-mempool tracking (due to
|
||||||
// lack of CValidationInterface::TransactionAddedToMempool callbacks).
|
// lack of CValidationInterface::TransactionAddedToMempool callbacks).
|
||||||
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool validFeeEstimate = true);
|
void addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool validFeeEstimate = true);
|
||||||
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate = true);
|
void addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate = true);
|
||||||
|
|
||||||
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN);
|
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN);
|
||||||
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags);
|
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags);
|
||||||
|
|
|
@ -178,7 +178,7 @@ public:
|
||||||
// Manual block validity manipulation:
|
// Manual block validity manipulation:
|
||||||
bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main);
|
bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main);
|
||||||
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
bool ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
bool ReplayBlocks(const CChainParams& params, CCoinsView* view);
|
bool ReplayBlocks(const CChainParams& params, CCoinsView* view);
|
||||||
bool RewindBlockIndex(const CChainParams& params);
|
bool RewindBlockIndex(const CChainParams& params);
|
||||||
|
@ -2882,7 +2882,7 @@ bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, C
|
||||||
return g_chainstate.InvalidateBlock(state, chainparams, pindex);
|
return g_chainstate.InvalidateBlock(state, chainparams, pindex);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
|
void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
|
||||||
AssertLockHeld(cs_main);
|
AssertLockHeld(cs_main);
|
||||||
|
|
||||||
int nHeight = pindex->nHeight;
|
int nHeight = pindex->nHeight;
|
||||||
|
@ -2914,9 +2914,9 @@ bool CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
|
||||||
}
|
}
|
||||||
pindex = pindex->pprev;
|
pindex = pindex->pprev;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
bool ResetBlockFailureFlags(CBlockIndex *pindex) {
|
|
||||||
|
void ResetBlockFailureFlags(CBlockIndex *pindex) {
|
||||||
return g_chainstate.ResetBlockFailureFlags(pindex);
|
return g_chainstate.ResetBlockFailureFlags(pindex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -449,7 +449,7 @@ bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIn
|
||||||
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
/** Remove invalidity status from a block and its descendants. */
|
/** Remove invalidity status from a block and its descendants. */
|
||||||
bool ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
/** The currently-connected chain of blocks (protected by cs_main). */
|
/** The currently-connected chain of blocks (protected by cs_main). */
|
||||||
extern CChain& chainActive;
|
extern CChain& chainActive;
|
||||||
|
|
|
@ -304,20 +304,18 @@ bool CWallet::AddCryptedKey(const CPubKey &vchPubKey,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata &meta)
|
void CWallet::LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata &meta)
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs_wallet); // mapKeyMetadata
|
AssertLockHeld(cs_wallet); // mapKeyMetadata
|
||||||
UpdateTimeFirstKey(meta.nCreateTime);
|
UpdateTimeFirstKey(meta.nCreateTime);
|
||||||
mapKeyMetadata[keyID] = meta;
|
mapKeyMetadata[keyID] = meta;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata &meta)
|
void CWallet::LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata &meta)
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs_wallet); // m_script_metadata
|
AssertLockHeld(cs_wallet); // m_script_metadata
|
||||||
UpdateTimeFirstKey(meta.nCreateTime);
|
UpdateTimeFirstKey(meta.nCreateTime);
|
||||||
m_script_metadata[script_id] = meta;
|
m_script_metadata[script_id] = meta;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret)
|
bool CWallet::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret)
|
||||||
|
@ -470,11 +468,11 @@ void CWallet::ChainStateFlushed(const CBlockLocator& loc)
|
||||||
batch.WriteBestBlock(loc);
|
batch.WriteBestBlock(loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in, bool fExplicit)
|
void CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in, bool fExplicit)
|
||||||
{
|
{
|
||||||
LOCK(cs_wallet); // nWalletVersion
|
LOCK(cs_wallet); // nWalletVersion
|
||||||
if (nWalletVersion >= nVersion)
|
if (nWalletVersion >= nVersion)
|
||||||
return true;
|
return;
|
||||||
|
|
||||||
// when doing an explicit upgrade, if we pass the max version permitted, upgrade all the way
|
// when doing an explicit upgrade, if we pass the max version permitted, upgrade all the way
|
||||||
if (fExplicit && nVersion > nWalletMaxVersion)
|
if (fExplicit && nVersion > nWalletMaxVersion)
|
||||||
|
@ -492,8 +490,6 @@ bool CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in,
|
||||||
if (!batch_in)
|
if (!batch_in)
|
||||||
delete batch;
|
delete batch;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::SetMaxVersion(int nVersion)
|
bool CWallet::SetMaxVersion(int nVersion)
|
||||||
|
@ -703,9 +699,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
||||||
|
|
||||||
// if we are using HD, replace the HD seed with a new one
|
// if we are using HD, replace the HD seed with a new one
|
||||||
if (IsHDEnabled()) {
|
if (IsHDEnabled()) {
|
||||||
if (!SetHDSeed(GenerateNewSeed())) {
|
SetHDSeed(GenerateNewSeed());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NewKeyPool();
|
NewKeyPool();
|
||||||
|
@ -1006,7 +1000,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::LoadToWallet(const CWalletTx& wtxIn)
|
void CWallet::LoadToWallet(const CWalletTx& wtxIn)
|
||||||
{
|
{
|
||||||
uint256 hash = wtxIn.GetHash();
|
uint256 hash = wtxIn.GetHash();
|
||||||
const auto& ins = mapWallet.emplace(hash, wtxIn);
|
const auto& ins = mapWallet.emplace(hash, wtxIn);
|
||||||
|
@ -1025,8 +1019,6 @@ bool CWallet::LoadToWallet(const CWalletTx& wtxIn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate)
|
bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate)
|
||||||
|
@ -1478,7 +1470,7 @@ CPubKey CWallet::DeriveNewSeed(const CKey& key)
|
||||||
return seed;
|
return seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::SetHDSeed(const CPubKey& seed)
|
void CWallet::SetHDSeed(const CPubKey& seed)
|
||||||
{
|
{
|
||||||
LOCK(cs_wallet);
|
LOCK(cs_wallet);
|
||||||
// store the keyid (hash160) together with
|
// store the keyid (hash160) together with
|
||||||
|
@ -1488,18 +1480,15 @@ bool CWallet::SetHDSeed(const CPubKey& seed)
|
||||||
newHdChain.nVersion = CanSupportFeature(FEATURE_HD_SPLIT) ? CHDChain::VERSION_HD_CHAIN_SPLIT : CHDChain::VERSION_HD_BASE;
|
newHdChain.nVersion = CanSupportFeature(FEATURE_HD_SPLIT) ? CHDChain::VERSION_HD_CHAIN_SPLIT : CHDChain::VERSION_HD_BASE;
|
||||||
newHdChain.seed_id = seed.GetID();
|
newHdChain.seed_id = seed.GetID();
|
||||||
SetHDChain(newHdChain, false);
|
SetHDChain(newHdChain, false);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::SetHDChain(const CHDChain& chain, bool memonly)
|
void CWallet::SetHDChain(const CHDChain& chain, bool memonly)
|
||||||
{
|
{
|
||||||
LOCK(cs_wallet);
|
LOCK(cs_wallet);
|
||||||
if (!memonly && !WalletBatch(*database).WriteHDChain(chain))
|
if (!memonly && !WalletBatch(*database).WriteHDChain(chain))
|
||||||
throw std::runtime_error(std::string(__func__) + ": writing chain failed");
|
throw std::runtime_error(std::string(__func__) + ": writing chain failed");
|
||||||
|
|
||||||
hdChain = chain;
|
hdChain = chain;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::IsHDEnabled() const
|
bool CWallet::IsHDEnabled() const
|
||||||
|
@ -3899,10 +3888,9 @@ bool CWallet::EraseDestData(const CTxDestination &dest, const std::string &key)
|
||||||
return WalletBatch(*database).EraseDestData(EncodeDestination(dest), key);
|
return WalletBatch(*database).EraseDestData(EncodeDestination(dest), key);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value)
|
void CWallet::LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value)
|
||||||
{
|
{
|
||||||
mapAddressBook[dest].destdata.insert(std::make_pair(key, value));
|
mapAddressBook[dest].destdata.insert(std::make_pair(key, value));
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const
|
bool CWallet::GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const
|
||||||
|
@ -4091,9 +4079,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(const std::string& name,
|
||||||
|
|
||||||
// generate a new master key
|
// generate a new master key
|
||||||
CPubKey masterPubKey = walletInstance->GenerateNewSeed();
|
CPubKey masterPubKey = walletInstance->GenerateNewSeed();
|
||||||
if (!walletInstance->SetHDSeed(masterPubKey)) {
|
walletInstance->SetHDSeed(masterPubKey);
|
||||||
throw std::runtime_error(std::string(__func__) + ": Storing master key failed");
|
|
||||||
}
|
|
||||||
hd_upgrade = true;
|
hd_upgrade = true;
|
||||||
}
|
}
|
||||||
// Upgrade to HD chain split if necessary
|
// Upgrade to HD chain split if necessary
|
||||||
|
@ -4130,9 +4116,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(const std::string& name,
|
||||||
} else {
|
} else {
|
||||||
// generate a new seed
|
// generate a new seed
|
||||||
CPubKey seed = walletInstance->GenerateNewSeed();
|
CPubKey seed = walletInstance->GenerateNewSeed();
|
||||||
if (!walletInstance->SetHDSeed(seed)) {
|
walletInstance->SetHDSeed(seed);
|
||||||
throw std::runtime_error(std::string(__func__) + ": Storing HD seed failed");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Top up the keypool
|
// Top up the keypool
|
||||||
|
|
|
@ -885,8 +885,8 @@ public:
|
||||||
//! Adds a key to the store, without saving it to disk (used by LoadWallet)
|
//! Adds a key to the store, without saving it to disk (used by LoadWallet)
|
||||||
bool LoadKey(const CKey& key, const CPubKey &pubkey) { return CCryptoKeyStore::AddKeyPubKey(key, pubkey); }
|
bool LoadKey(const CKey& key, const CPubKey &pubkey) { return CCryptoKeyStore::AddKeyPubKey(key, pubkey); }
|
||||||
//! Load metadata (used by LoadWallet)
|
//! Load metadata (used by LoadWallet)
|
||||||
bool LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata &metadata) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
void LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata &metadata) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
bool LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata &metadata) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
void LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata &metadata) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
|
|
||||||
bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; }
|
bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; }
|
||||||
void UpdateTimeFirstKey(int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
void UpdateTimeFirstKey(int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
|
@ -903,7 +903,7 @@ public:
|
||||||
//! Erases a destination data tuple in the store and on disk
|
//! Erases a destination data tuple in the store and on disk
|
||||||
bool EraseDestData(const CTxDestination &dest, const std::string &key);
|
bool EraseDestData(const CTxDestination &dest, const std::string &key);
|
||||||
//! Adds a destination data tuple to the store, without saving it to disk
|
//! Adds a destination data tuple to the store, without saving it to disk
|
||||||
bool LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value);
|
void LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value);
|
||||||
//! Look up a destination data tuple in the store, return true if found false otherwise
|
//! Look up a destination data tuple in the store, return true if found false otherwise
|
||||||
bool GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const;
|
bool GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const;
|
||||||
//! Get all destination values matching a prefix.
|
//! Get all destination values matching a prefix.
|
||||||
|
@ -936,7 +936,7 @@ public:
|
||||||
|
|
||||||
void MarkDirty();
|
void MarkDirty();
|
||||||
bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose=true);
|
bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose=true);
|
||||||
bool LoadToWallet(const CWalletTx& wtxIn);
|
void LoadToWallet(const CWalletTx& wtxIn);
|
||||||
void TransactionAddedToMempool(const CTransactionRef& tx) override;
|
void TransactionAddedToMempool(const CTransactionRef& tx) override;
|
||||||
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex *pindex, const std::vector<CTransactionRef>& vtxConflicted) override;
|
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex *pindex, const std::vector<CTransactionRef>& vtxConflicted) override;
|
||||||
void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock) override;
|
void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock) override;
|
||||||
|
@ -1075,7 +1075,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
//! signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVersion if those are lower
|
//! signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVersion if those are lower
|
||||||
bool SetMinVersion(enum WalletFeature, WalletBatch* batch_in = nullptr, bool fExplicit = false);
|
void SetMinVersion(enum WalletFeature, WalletBatch* batch_in = nullptr, bool fExplicit = false);
|
||||||
|
|
||||||
//! change which version we're allowed to upgrade to (note that this does not immediately imply upgrading to that format)
|
//! change which version we're allowed to upgrade to (note that this does not immediately imply upgrading to that format)
|
||||||
bool SetMaxVersion(int nVersion);
|
bool SetMaxVersion(int nVersion);
|
||||||
|
@ -1146,7 +1146,7 @@ public:
|
||||||
bool BackupWallet(const std::string& strDest);
|
bool BackupWallet(const std::string& strDest);
|
||||||
|
|
||||||
/* Set the HD chain model (chain child index counters) */
|
/* Set the HD chain model (chain child index counters) */
|
||||||
bool SetHDChain(const CHDChain& chain, bool memonly);
|
void SetHDChain(const CHDChain& chain, bool memonly);
|
||||||
const CHDChain& GetHDChain() const { return hdChain; }
|
const CHDChain& GetHDChain() const { return hdChain; }
|
||||||
|
|
||||||
/* Returns true if HD is enabled */
|
/* Returns true if HD is enabled */
|
||||||
|
@ -1162,7 +1162,7 @@ public:
|
||||||
Sets the seed's version based on the current wallet version (so the
|
Sets the seed's version based on the current wallet version (so the
|
||||||
caller must ensure the current wallet version is correct before calling
|
caller must ensure the current wallet version is correct before calling
|
||||||
this function). */
|
this function). */
|
||||||
bool SetHDSeed(const CPubKey& key);
|
void SetHDSeed(const CPubKey& key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blocks until the wallet state is up-to-date to /at least/ the current
|
* Blocks until the wallet state is up-to-date to /at least/ the current
|
||||||
|
|
|
@ -495,21 +495,13 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
|
||||||
ssKey >> strAddress;
|
ssKey >> strAddress;
|
||||||
ssKey >> strKey;
|
ssKey >> strKey;
|
||||||
ssValue >> strValue;
|
ssValue >> strValue;
|
||||||
if (!pwallet->LoadDestData(DecodeDestination(strAddress), strKey, strValue))
|
pwallet->LoadDestData(DecodeDestination(strAddress), strKey, strValue);
|
||||||
{
|
|
||||||
strErr = "Error reading wallet database: LoadDestData failed";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (strType == "hdchain")
|
else if (strType == "hdchain")
|
||||||
{
|
{
|
||||||
CHDChain chain;
|
CHDChain chain;
|
||||||
ssValue >> chain;
|
ssValue >> chain;
|
||||||
if (!pwallet->SetHDChain(chain, true))
|
pwallet->SetHDChain(chain, true);
|
||||||
{
|
|
||||||
strErr = "Error reading wallet database: SetHDChain failed";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (strType == "flags") {
|
} else if (strType == "flags") {
|
||||||
uint64_t flags;
|
uint64_t flags;
|
||||||
ssValue >> flags;
|
ssValue >> flags;
|
||||||
|
|
Loading…
Reference in a new issue