mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
scripted-diff: Convert 11 enums into scoped enums (C++11) (merge #10742)
-BEGIN VERIFY SCRIPT- sed -i 's/enum DBErrors/enum class DBErrors/g' src/wallet/walletdb.h git grep -l DB_ | xargs sed -i 's/DB_\(LOAD_OK\|CORRUPT\|NONCRITICAL_ERROR\|TOO_NEW\|LOAD_FAIL\|NEED_REWRITE\)/DBErrors::\1/g' sed -i 's/^ DBErrors::/ /g' src/wallet/walletdb.h sed -i 's/enum VerifyResult/enum class VerifyResult/g' src/wallet/db.h sed -i 's/\(VERIFY_OK\|RECOVER_OK\|RECOVER_FAIL\)/VerifyResult::\1/g' src/wallet/db.cpp sed -i 's/enum ThresholdState/enum class ThresholdState/g' src/versionbits.h git grep -l THRESHOLD_ | xargs sed -i 's/THRESHOLD_\(DEFINED\|STARTED\|LOCKED_IN\|ACTIVE\|FAILED\)/ThresholdState::\1/g' sed -i 's/^ ThresholdState::/ /g' src/versionbits.h sed -i 's/enum SigVersion/enum class SigVersion/g' src/script/interpreter.h git grep -l SIGVERSION_ | xargs sed -i 's/SIGVERSION_\(BASE\|WITNESS_V0\)/SigVersion::\1/g' sed -i 's/^ SigVersion::/ /g' src/script/interpreter.h sed -i 's/enum RetFormat {/enum class RetFormat {/g' src/rest.cpp sed -i 's/RF_\(UNDEF\|BINARY\|HEX\|JSON\)/RetFormat::\1/g' src/rest.cpp sed -i 's/^ RetFormat::/ /g' src/rest.cpp sed -i 's/enum HelpMessageMode {/enum class HelpMessageMode {/g' src/init.h git grep -l HMM_ | xargs sed -i 's/HMM_BITCOIN/HelpMessageMode::BITCOIN/g' sed -i 's/^ HelpMessageMode::/ /g' src/init.h sed -i 's/enum FeeEstimateHorizon/enum class FeeEstimateHorizon/g' src/policy/fees.h sed -i 's/enum BlockSource {/enum class BlockSource {/g' src/qt/clientmodel.h git grep -l BLOCK_SOURCE_ | xargs sed -i 's/BLOCK_SOURCE_\(NONE\|REINDEX\|DISK\|NETWORK\)/BlockSource::\1/g' sed -i 's/^ BlockSource::/ /g' src/qt/clientmodel.h sed -i 's/enum FlushStateMode {/enum class FlushStateMode {/g' src/validation.cpp sed -i 's/FLUSH_STATE_\(NONE\|IF_NEEDED\|PERIODIC\|ALWAYS\)/FlushStateMode::\1/g' src/validation.cpp sed -i 's/^ FlushStateMode::/ /g' src/validation.cpp -END VERIFY SCRIPT- Signed-off-by: pasta <pasta@dashboost.org>
This commit is contained in:
parent
bb035972ee
commit
518ccbf986
@ -84,7 +84,7 @@ bool AppInit(int argc, char* argv[])
|
||||
strUsage += "\n" + _("Usage:") + "\n" +
|
||||
" dashd [options] " + strprintf(_("Start %s Daemon"), _(PACKAGE_NAME)) + "\n";
|
||||
|
||||
strUsage += "\n" + HelpMessage(HMM_BITCOIND);
|
||||
strUsage += "\n" + HelpMessage(HelpMessageMode::BITCOIND);
|
||||
}
|
||||
|
||||
fprintf(stdout, "%s", strUsage.c_str());
|
||||
|
@ -39,7 +39,7 @@ bool CheckCbTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidatio
|
||||
}
|
||||
|
||||
if (pindexPrev) {
|
||||
bool fDIP0008Active = VersionBitsState(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0008, versionbitscache) == THRESHOLD_ACTIVE;
|
||||
bool fDIP0008Active = VersionBitsState(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0008, versionbitscache) == ThresholdState::ACTIVE;
|
||||
if (fDIP0008Active && cbTx.nVersion < 2) {
|
||||
return state.DoS(100, false, REJECT_INVALID, "bad-cbtx-version");
|
||||
}
|
||||
|
@ -463,7 +463,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
strUsage += HelpMessageOpt("-blocksonly", strprintf(_("Whether to operate in a blocks only mode (default: %u)"), DEFAULT_BLOCKSONLY));
|
||||
strUsage +=HelpMessageOpt("-assumevalid=<hex>", strprintf(_("If this block is in the chain assume that it and its ancestors are valid and potentially skip their script verification (0 to verify all, default: %s, testnet: %s)"), defaultChainParams->GetConsensus().defaultAssumeValid.GetHex(), testnetChainParams->GetConsensus().defaultAssumeValid.GetHex()));
|
||||
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)"), BITCOIN_CONF_FILENAME));
|
||||
if (mode == HMM_BITCOIND)
|
||||
if (mode == HelpMessageMode::BITCOIND)
|
||||
{
|
||||
#if HAVE_DECL_DAEMON
|
||||
strUsage += HelpMessageOpt("-daemon", _("Run in the background as a daemon and accept commands"));
|
||||
|
@ -63,9 +63,9 @@ bool AppInitMain();
|
||||
void PrepareShutdown();
|
||||
|
||||
/** The help message mode determines what help message to show */
|
||||
enum HelpMessageMode {
|
||||
HMM_BITCOIND,
|
||||
HMM_BITCOIN_QT
|
||||
enum class HelpMessageMode {
|
||||
BITCOIND,
|
||||
BITCOIN_QT
|
||||
};
|
||||
|
||||
/** Help for options shared between UI and daemon (for -help) */
|
||||
|
@ -227,7 +227,7 @@ void CChainLocksHandler::CheckActiveState()
|
||||
bool fDIP0008Active;
|
||||
{
|
||||
LOCK(cs_main);
|
||||
fDIP0008Active = chainActive.Tip() && VersionBitsState(chainActive.Tip()->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0008, versionbitscache) == THRESHOLD_ACTIVE;
|
||||
fDIP0008Active = chainActive.Tip() && VersionBitsState(chainActive.Tip()->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0008, versionbitscache) == ThresholdState::ACTIVE;
|
||||
}
|
||||
|
||||
LOCK(cs);
|
||||
|
@ -1157,7 +1157,7 @@ void CInstantSendManager::NotifyChainLock(const CBlockIndex* pindexChainLock)
|
||||
void CInstantSendManager::UpdatedBlockTip(const CBlockIndex* pindexNew)
|
||||
{
|
||||
// TODO remove this after DIP8 has activated
|
||||
bool fDIP0008Active = VersionBitsState(pindexNew->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0008, versionbitscache) == THRESHOLD_ACTIVE;
|
||||
bool fDIP0008Active = VersionBitsState(pindexNew->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0008, versionbitscache) == ThresholdState::ACTIVE;
|
||||
|
||||
if (sporkManager.IsSporkActive(SPORK_19_CHAINLOCKS_ENABLED) && fDIP0008Active) {
|
||||
// Nothing to do here. We should keep all islocks and let chainlocks handle them.
|
||||
|
@ -140,7 +140,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
|
||||
nHeight = pindexPrev->nHeight + 1;
|
||||
|
||||
bool fDIP0003Active_context = nHeight >= chainparams.GetConsensus().DIP0003Height;
|
||||
bool fDIP0008Active_context = VersionBitsState(chainActive.Tip(), chainparams.GetConsensus(), Consensus::DEPLOYMENT_DIP0008, versionbitscache) == THRESHOLD_ACTIVE;
|
||||
bool fDIP0008Active_context = VersionBitsState(chainActive.Tip(), chainparams.GetConsensus(), Consensus::DEPLOYMENT_DIP0008, versionbitscache) == ThresholdState::ACTIVE;
|
||||
|
||||
pblock->nVersion = ComputeBlockVersion(pindexPrev, chainparams.GetConsensus(), chainparams.BIP9CheckMasternodesUpgraded());
|
||||
// -regtest only: allow overriding block.nVersion with
|
||||
|
@ -69,7 +69,7 @@ class TxConfirmStats;
|
||||
|
||||
/* Identifier for each of the 3 different TxConfirmStats which will track
|
||||
* history over different time horizons. */
|
||||
enum FeeEstimateHorizon {
|
||||
enum class FeeEstimateHorizon {
|
||||
SHORT_HALFLIFE = 0,
|
||||
MED_HALFLIFE = 1,
|
||||
LONG_HALFLIFE = 2
|
||||
|
@ -159,7 +159,7 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
|
||||
{
|
||||
std::vector<std::vector<unsigned char> > stack;
|
||||
// convert the scriptSig into a stack, so we can inspect the redeemScript
|
||||
if (!EvalScript(stack, tx.vin[i].scriptSig, SCRIPT_VERIFY_NONE, BaseSignatureChecker(), SIGVERSION_BASE))
|
||||
if (!EvalScript(stack, tx.vin[i].scriptSig, SCRIPT_VERIFY_NONE, BaseSignatureChecker(), SigVersion::BASE))
|
||||
return false;
|
||||
if (stack.empty())
|
||||
return false;
|
||||
|
@ -1045,7 +1045,7 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
|
||||
// Acquire current block source
|
||||
enum BlockSource blockSource = clientModel->getBlockSource();
|
||||
switch (blockSource) {
|
||||
case BLOCK_SOURCE_NETWORK:
|
||||
case BlockSource::NETWORK:
|
||||
if (header) {
|
||||
updateHeadersSyncProgressLabel();
|
||||
return;
|
||||
@ -1053,17 +1053,17 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
|
||||
progressBarLabel->setText(tr("Synchronizing with network..."));
|
||||
updateHeadersSyncProgressLabel();
|
||||
break;
|
||||
case BLOCK_SOURCE_DISK:
|
||||
case BlockSource::DISK:
|
||||
if (header) {
|
||||
progressBarLabel->setText(tr("Indexing blocks on disk..."));
|
||||
} else {
|
||||
progressBarLabel->setText(tr("Processing blocks on disk..."));
|
||||
}
|
||||
break;
|
||||
case BLOCK_SOURCE_REINDEX:
|
||||
case BlockSource::REINDEX:
|
||||
progressBarLabel->setText(tr("Reindexing blocks on disk..."));
|
||||
break;
|
||||
case BLOCK_SOURCE_NONE:
|
||||
case BlockSource::NONE:
|
||||
if (header) {
|
||||
return;
|
||||
}
|
||||
|
@ -214,13 +214,13 @@ bool ClientModel::inInitialBlockDownload() const
|
||||
enum BlockSource ClientModel::getBlockSource() const
|
||||
{
|
||||
if (fReindex)
|
||||
return BLOCK_SOURCE_REINDEX;
|
||||
return BlockSource::REINDEX;
|
||||
else if (fImporting)
|
||||
return BLOCK_SOURCE_DISK;
|
||||
return BlockSource::DISK;
|
||||
else if (getNumConnections() > 0)
|
||||
return BLOCK_SOURCE_NETWORK;
|
||||
return BlockSource::NETWORK;
|
||||
|
||||
return BLOCK_SOURCE_NONE;
|
||||
return BlockSource::NONE;
|
||||
}
|
||||
|
||||
void ClientModel::setNetworkActive(bool active)
|
||||
|
@ -24,11 +24,11 @@ QT_BEGIN_NAMESPACE
|
||||
class QTimer;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
enum BlockSource {
|
||||
BLOCK_SOURCE_NONE,
|
||||
BLOCK_SOURCE_REINDEX,
|
||||
BLOCK_SOURCE_DISK,
|
||||
BLOCK_SOURCE_NETWORK
|
||||
enum class BlockSource {
|
||||
NONE,
|
||||
REINDEX,
|
||||
DISK,
|
||||
NETWORK
|
||||
};
|
||||
|
||||
enum NumConnections {
|
||||
|
@ -80,7 +80,7 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, HelpMode helpMode) :
|
||||
cursor.insertText(header);
|
||||
cursor.insertBlock();
|
||||
|
||||
std::string strUsage = HelpMessage(HMM_BITCOIN_QT);
|
||||
std::string strUsage = HelpMessage(HelpMessageMode::BITCOIN_QT);
|
||||
const bool showDebug = gArgs.GetBoolArg("-help-debug", false);
|
||||
strUsage += HelpMessageGroup(tr("UI Options:").toStdString());
|
||||
if (showDebug) {
|
||||
|
54
src/rest.cpp
54
src/rest.cpp
@ -24,21 +24,21 @@
|
||||
|
||||
static const size_t MAX_GETUTXOS_OUTPOINTS = 15; //allow a max of 15 outpoints to be queried at once
|
||||
|
||||
enum RetFormat {
|
||||
RF_UNDEF,
|
||||
RF_BINARY,
|
||||
RF_HEX,
|
||||
RF_JSON,
|
||||
enum class RetFormat {
|
||||
UNDEF,
|
||||
BINARY,
|
||||
HEX,
|
||||
JSON,
|
||||
};
|
||||
|
||||
static const struct {
|
||||
enum RetFormat rf;
|
||||
const char* name;
|
||||
} rf_names[] = {
|
||||
{RF_UNDEF, ""},
|
||||
{RF_BINARY, "bin"},
|
||||
{RF_HEX, "hex"},
|
||||
{RF_JSON, "json"},
|
||||
{RetFormat::UNDEF, ""},
|
||||
{RetFormat::BINARY, "bin"},
|
||||
{RetFormat::HEX, "hex"},
|
||||
{RetFormat::JSON, "json"},
|
||||
};
|
||||
|
||||
struct CCoin {
|
||||
@ -163,20 +163,20 @@ static bool rest_headers(HTTPRequest* req,
|
||||
}
|
||||
|
||||
switch (rf) {
|
||||
case RF_BINARY: {
|
||||
case RetFormat::BINARY: {
|
||||
std::string binaryHeader = ssHeader.str();
|
||||
req->WriteHeader("Content-Type", "application/octet-stream");
|
||||
req->WriteReply(HTTP_OK, binaryHeader);
|
||||
return true;
|
||||
}
|
||||
|
||||
case RF_HEX: {
|
||||
case RetFormat::HEX: {
|
||||
std::string strHex = HexStr(ssHeader.begin(), ssHeader.end()) + "\n";
|
||||
req->WriteHeader("Content-Type", "text/plain");
|
||||
req->WriteReply(HTTP_OK, strHex);
|
||||
return true;
|
||||
}
|
||||
case RF_JSON: {
|
||||
case RetFormat::JSON: {
|
||||
UniValue jsonHeaders(UniValue::VARR);
|
||||
{
|
||||
LOCK(cs_main);
|
||||
@ -227,21 +227,21 @@ static bool rest_block(HTTPRequest* req,
|
||||
ssBlock << block;
|
||||
|
||||
switch (rf) {
|
||||
case RF_BINARY: {
|
||||
case RetFormat::BINARY: {
|
||||
std::string binaryBlock = ssBlock.str();
|
||||
req->WriteHeader("Content-Type", "application/octet-stream");
|
||||
req->WriteReply(HTTP_OK, binaryBlock);
|
||||
return true;
|
||||
}
|
||||
|
||||
case RF_HEX: {
|
||||
case RetFormat::HEX: {
|
||||
std::string strHex = HexStr(ssBlock.begin(), ssBlock.end()) + "\n";
|
||||
req->WriteHeader("Content-Type", "text/plain");
|
||||
req->WriteReply(HTTP_OK, strHex);
|
||||
return true;
|
||||
}
|
||||
|
||||
case RF_JSON: {
|
||||
case RetFormat::JSON: {
|
||||
UniValue objBlock;
|
||||
{
|
||||
LOCK(cs_main);
|
||||
@ -280,7 +280,7 @@ static bool rest_chaininfo(HTTPRequest* req, const std::string& strURIPart)
|
||||
const RetFormat rf = ParseDataFormat(param, strURIPart);
|
||||
|
||||
switch (rf) {
|
||||
case RF_JSON: {
|
||||
case RetFormat::JSON: {
|
||||
JSONRPCRequest jsonRequest;
|
||||
jsonRequest.params = UniValue(UniValue::VARR);
|
||||
UniValue chainInfoObject = getblockchaininfo(jsonRequest);
|
||||
@ -303,7 +303,7 @@ static bool rest_mempool_info(HTTPRequest* req, const std::string& strURIPart)
|
||||
const RetFormat rf = ParseDataFormat(param, strURIPart);
|
||||
|
||||
switch (rf) {
|
||||
case RF_JSON: {
|
||||
case RetFormat::JSON: {
|
||||
UniValue mempoolInfoObject = mempoolInfoToJSON();
|
||||
|
||||
std::string strJSON = mempoolInfoObject.write() + "\n";
|
||||
@ -325,7 +325,7 @@ static bool rest_mempool_contents(HTTPRequest* req, const std::string& strURIPar
|
||||
const RetFormat rf = ParseDataFormat(param, strURIPart);
|
||||
|
||||
switch (rf) {
|
||||
case RF_JSON: {
|
||||
case RetFormat::JSON: {
|
||||
UniValue mempoolObject = mempoolToJSON(true);
|
||||
|
||||
std::string strJSON = mempoolObject.write() + "\n";
|
||||
@ -359,21 +359,21 @@ static bool rest_tx(HTTPRequest* req, const std::string& strURIPart)
|
||||
ssTx << tx;
|
||||
|
||||
switch (rf) {
|
||||
case RF_BINARY: {
|
||||
case RetFormat::BINARY: {
|
||||
std::string binaryTx = ssTx.str();
|
||||
req->WriteHeader("Content-Type", "application/octet-stream");
|
||||
req->WriteReply(HTTP_OK, binaryTx);
|
||||
return true;
|
||||
}
|
||||
|
||||
case RF_HEX: {
|
||||
case RetFormat::HEX: {
|
||||
std::string strHex = HexStr(ssTx.begin(), ssTx.end()) + "\n";
|
||||
req->WriteHeader("Content-Type", "text/plain");
|
||||
req->WriteReply(HTTP_OK, strHex);
|
||||
return true;
|
||||
}
|
||||
|
||||
case RF_JSON: {
|
||||
case RetFormat::JSON: {
|
||||
UniValue objTx(UniValue::VOBJ);
|
||||
TxToUniv(*tx, hashBlock, objTx);
|
||||
std::string strJSON = objTx.write() + "\n";
|
||||
@ -440,13 +440,13 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
|
||||
}
|
||||
|
||||
switch (rf) {
|
||||
case RF_HEX: {
|
||||
case RetFormat::HEX: {
|
||||
// convert hex to bin, continue then with bin part
|
||||
std::vector<unsigned char> strRequestV = ParseHex(strRequestMutable);
|
||||
strRequestMutable.assign(strRequestV.begin(), strRequestV.end());
|
||||
}
|
||||
|
||||
case RF_BINARY: {
|
||||
case RetFormat::BINARY: {
|
||||
try {
|
||||
//deserialize only if user sent a request
|
||||
if (strRequestMutable.size() > 0)
|
||||
@ -466,7 +466,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
|
||||
break;
|
||||
}
|
||||
|
||||
case RF_JSON: {
|
||||
case RetFormat::JSON: {
|
||||
if (!fInputParsed)
|
||||
return RESTERR(req, HTTP_BAD_REQUEST, "Error: empty request");
|
||||
break;
|
||||
@ -513,7 +513,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
|
||||
}
|
||||
|
||||
switch (rf) {
|
||||
case RF_BINARY: {
|
||||
case RetFormat::BINARY: {
|
||||
// serialize data
|
||||
// use exact same output as mentioned in Bip64
|
||||
CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION);
|
||||
@ -525,7 +525,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
|
||||
return true;
|
||||
}
|
||||
|
||||
case RF_HEX: {
|
||||
case RetFormat::HEX: {
|
||||
CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ssGetUTXOResponse << chainActive.Height() << chainActive.Tip()->GetBlockHash() << bitmap << outs;
|
||||
std::string strHex = HexStr(ssGetUTXOResponse.begin(), ssGetUTXOResponse.end()) + "\n";
|
||||
@ -535,7 +535,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
|
||||
return true;
|
||||
}
|
||||
|
||||
case RF_JSON: {
|
||||
case RetFormat::JSON: {
|
||||
UniValue objGetUTXOResponse(UniValue::VOBJ);
|
||||
|
||||
// pack in some essentials
|
||||
|
@ -1370,20 +1370,20 @@ static UniValue BIP9SoftForkDesc(const Consensus::Params& consensusParams, Conse
|
||||
UniValue rv(UniValue::VOBJ);
|
||||
const ThresholdState thresholdState = VersionBitsTipState(consensusParams, id);
|
||||
switch (thresholdState) {
|
||||
case THRESHOLD_DEFINED: rv.push_back(Pair("status", "defined")); break;
|
||||
case THRESHOLD_STARTED: rv.push_back(Pair("status", "started")); break;
|
||||
case THRESHOLD_LOCKED_IN: rv.push_back(Pair("status", "locked_in")); break;
|
||||
case THRESHOLD_ACTIVE: rv.push_back(Pair("status", "active")); break;
|
||||
case THRESHOLD_FAILED: rv.push_back(Pair("status", "failed")); break;
|
||||
case ThresholdState::DEFINED: rv.push_back(Pair("status", "defined")); break;
|
||||
case ThresholdState::STARTED: rv.push_back(Pair("status", "started")); break;
|
||||
case ThresholdState::LOCKED_IN: rv.push_back(Pair("status", "locked_in")); break;
|
||||
case ThresholdState::ACTIVE: rv.push_back(Pair("status", "active")); break;
|
||||
case ThresholdState::FAILED: rv.push_back(Pair("status", "failed")); break;
|
||||
}
|
||||
if (THRESHOLD_STARTED == thresholdState)
|
||||
if (ThresholdState::STARTED == thresholdState)
|
||||
{
|
||||
rv.push_back(Pair("bit", consensusParams.vDeployments[id].bit));
|
||||
}
|
||||
rv.push_back(Pair("startTime", consensusParams.vDeployments[id].nStartTime));
|
||||
rv.push_back(Pair("timeout", consensusParams.vDeployments[id].nTimeout));
|
||||
rv.push_back(Pair("since", VersionBitsTipStateSinceHeight(consensusParams, id)));
|
||||
if (THRESHOLD_STARTED == thresholdState)
|
||||
if (ThresholdState::STARTED == thresholdState)
|
||||
{
|
||||
UniValue statsUV(UniValue::VOBJ);
|
||||
BIP9Stats statsStruct = VersionBitsTipStatistics(consensusParams, id);
|
||||
|
@ -609,15 +609,15 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
|
||||
Consensus::DeploymentPos pos = Consensus::DeploymentPos(j);
|
||||
ThresholdState state = VersionBitsState(pindexPrev, consensusParams, pos, versionbitscache);
|
||||
switch (state) {
|
||||
case THRESHOLD_DEFINED:
|
||||
case THRESHOLD_FAILED:
|
||||
case ThresholdState::DEFINED:
|
||||
case ThresholdState::FAILED:
|
||||
// Not exposed to GBT at all
|
||||
break;
|
||||
case THRESHOLD_LOCKED_IN:
|
||||
case ThresholdState::LOCKED_IN:
|
||||
// Ensure bit is set in block version
|
||||
pblock->nVersion |= VersionBitsMask(consensusParams, pos);
|
||||
// FALL THROUGH to get vbavailable set...
|
||||
case THRESHOLD_STARTED:
|
||||
case ThresholdState::STARTED:
|
||||
{
|
||||
const struct VBDeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
|
||||
vbavailable.push_back(Pair(gbt_vb_name(pos), consensusParams.vDeployments[pos].bit));
|
||||
@ -629,7 +629,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case THRESHOLD_ACTIVE:
|
||||
case ThresholdState::ACTIVE:
|
||||
{
|
||||
// Add to rules only
|
||||
const struct VBDeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
|
||||
|
@ -866,7 +866,7 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
|
||||
CScript scriptCode(pbegincodehash, pend);
|
||||
|
||||
// Drop the signature, since there's no way for a signature to sign itself
|
||||
if (sigversion == SIGVERSION_BASE) {
|
||||
if (sigversion == SigVersion::BASE) {
|
||||
scriptCode.FindAndDelete(CScript(vchSig));
|
||||
}
|
||||
|
||||
@ -930,7 +930,7 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
|
||||
for (int k = 0; k < nSigsCount; k++)
|
||||
{
|
||||
valtype& vchSig = stacktop(-isig-k);
|
||||
if (sigversion == SIGVERSION_BASE) {
|
||||
if (sigversion == SigVersion::BASE) {
|
||||
scriptCode.FindAndDelete(CScript(vchSig));
|
||||
}
|
||||
}
|
||||
@ -1293,12 +1293,12 @@ bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, unsigne
|
||||
}
|
||||
|
||||
std::vector<std::vector<unsigned char> > stack, stackCopy;
|
||||
if (!EvalScript(stack, scriptSig, flags, checker, SIGVERSION_BASE, serror))
|
||||
if (!EvalScript(stack, scriptSig, flags, checker, SigVersion::BASE, serror))
|
||||
// serror is set
|
||||
return false;
|
||||
if (flags & SCRIPT_VERIFY_P2SH)
|
||||
stackCopy = stack;
|
||||
if (!EvalScript(stack, scriptPubKey, flags, checker, SIGVERSION_BASE, serror))
|
||||
if (!EvalScript(stack, scriptPubKey, flags, checker, SigVersion::BASE, serror))
|
||||
// serror is set
|
||||
return false;
|
||||
if (stack.empty())
|
||||
@ -1325,7 +1325,7 @@ bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, unsigne
|
||||
CScript pubKey2(pubKeySerialized.begin(), pubKeySerialized.end());
|
||||
popstack(stack);
|
||||
|
||||
if (!EvalScript(stack, pubKey2, flags, checker, SIGVERSION_BASE, serror))
|
||||
if (!EvalScript(stack, pubKey2, flags, checker, SigVersion::BASE, serror))
|
||||
// serror is set
|
||||
return false;
|
||||
if (stack.empty())
|
||||
|
@ -106,9 +106,9 @@ struct PrecomputedTransactionData
|
||||
explicit PrecomputedTransactionData(const CTransaction& tx);
|
||||
};
|
||||
|
||||
enum SigVersion
|
||||
enum class SigVersion
|
||||
{
|
||||
SIGVERSION_BASE = 0,
|
||||
BASE = 0,
|
||||
};
|
||||
|
||||
uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CAmount& amount, SigVersion sigversion, const PrecomputedTransactionData* cache = nullptr);
|
||||
|
@ -127,7 +127,7 @@ bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& fromPu
|
||||
bool solved = true;
|
||||
std::vector<valtype> result;
|
||||
txnouttype whichType;
|
||||
solved = SignStep(creator, script, result, whichType, SIGVERSION_BASE);
|
||||
solved = SignStep(creator, script, result, whichType, SigVersion::BASE);
|
||||
bool P2SH = false;
|
||||
CScript subscript;
|
||||
|
||||
@ -137,7 +137,7 @@ bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& fromPu
|
||||
// the final scriptSig is the signatures from that
|
||||
// and then the serialized subscript:
|
||||
script = subscript = CScript(result[0].begin(), result[0].end());
|
||||
solved = solved && SignStep(creator, script, result, whichType, SIGVERSION_BASE) && whichType != TX_SCRIPTHASH;
|
||||
solved = solved && SignStep(creator, script, result, whichType, SigVersion::BASE) && whichType != TX_SCRIPTHASH;
|
||||
P2SH = true;
|
||||
}
|
||||
|
||||
@ -251,7 +251,7 @@ struct Stacks
|
||||
Stacks() {}
|
||||
explicit Stacks(const std::vector<valtype>& scriptSigStack_) : script(scriptSigStack_) {}
|
||||
explicit Stacks(const SignatureData& data) {
|
||||
EvalScript(script, data.scriptSig, SCRIPT_VERIFY_STRICTENC, BaseSignatureChecker(), SIGVERSION_BASE);
|
||||
EvalScript(script, data.scriptSig, SCRIPT_VERIFY_STRICTENC, BaseSignatureChecker(), SigVersion::BASE);
|
||||
}
|
||||
|
||||
SignatureData Output() const {
|
||||
@ -314,7 +314,7 @@ SignatureData CombineSignatures(const CScript& scriptPubKey, const BaseSignature
|
||||
std::vector<std::vector<unsigned char> > vSolutions;
|
||||
Solver(scriptPubKey, txType, vSolutions);
|
||||
|
||||
return CombineSignatures(scriptPubKey, checker, txType, vSolutions, Stacks(scriptSig1), Stacks(scriptSig2), SIGVERSION_BASE).Output();
|
||||
return CombineSignatures(scriptPubKey, checker, txType, vSolutions, Stacks(scriptSig1), Stacks(scriptSig2), SigVersion::BASE).Output();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
@ -21,7 +21,7 @@ BOOST_FIXTURE_TEST_SUITE(multisig_tests, BasicTestingSetup)
|
||||
CScript
|
||||
sign_multisig(CScript scriptPubKey, std::vector<CKey> keys, CTransaction transaction, int whichIn)
|
||||
{
|
||||
uint256 hash = SignatureHash(scriptPubKey, transaction, whichIn, SIGHASH_ALL, 0, SIGVERSION_BASE);
|
||||
uint256 hash = SignatureHash(scriptPubKey, transaction, whichIn, SIGHASH_ALL, 0, SigVersion::BASE);
|
||||
|
||||
CScript result;
|
||||
result << OP_0; // CHECKMULTISIG bug workaround
|
||||
|
@ -318,7 +318,7 @@ public:
|
||||
|
||||
TestBuilder& PushSig(const CKey& key, int nHashType = SIGHASH_ALL, unsigned int lenR = 32, unsigned int lenS = 32)
|
||||
{
|
||||
uint256 hash = SignatureHash(scriptPubKey, spendTx, 0, nHashType, 0, SIGVERSION_BASE);
|
||||
uint256 hash = SignatureHash(scriptPubKey, spendTx, 0, nHashType, 0, SigVersion::BASE);
|
||||
std::vector<unsigned char> vchSig, r, s;
|
||||
uint32_t iter = 0;
|
||||
do {
|
||||
@ -745,21 +745,21 @@ BOOST_AUTO_TEST_CASE(script_PushData)
|
||||
|
||||
ScriptError err;
|
||||
std::vector<std::vector<unsigned char> > directStack;
|
||||
BOOST_CHECK(EvalScript(directStack, CScript(&direct[0], &direct[sizeof(direct)]), SCRIPT_VERIFY_P2SH, BaseSignatureChecker(), SIGVERSION_BASE, &err));
|
||||
BOOST_CHECK(EvalScript(directStack, CScript(&direct[0], &direct[sizeof(direct)]), SCRIPT_VERIFY_P2SH, BaseSignatureChecker(), SigVersion::BASE, &err));
|
||||
BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_OK, ScriptErrorString(err));
|
||||
|
||||
std::vector<std::vector<unsigned char> > pushdata1Stack;
|
||||
BOOST_CHECK(EvalScript(pushdata1Stack, CScript(&pushdata1[0], &pushdata1[sizeof(pushdata1)]), SCRIPT_VERIFY_P2SH, BaseSignatureChecker(), SIGVERSION_BASE, &err));
|
||||
BOOST_CHECK(EvalScript(pushdata1Stack, CScript(&pushdata1[0], &pushdata1[sizeof(pushdata1)]), SCRIPT_VERIFY_P2SH, BaseSignatureChecker(), SigVersion::BASE, &err));
|
||||
BOOST_CHECK(pushdata1Stack == directStack);
|
||||
BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_OK, ScriptErrorString(err));
|
||||
|
||||
std::vector<std::vector<unsigned char> > pushdata2Stack;
|
||||
BOOST_CHECK(EvalScript(pushdata2Stack, CScript(&pushdata2[0], &pushdata2[sizeof(pushdata2)]), SCRIPT_VERIFY_P2SH, BaseSignatureChecker(), SIGVERSION_BASE, &err));
|
||||
BOOST_CHECK(EvalScript(pushdata2Stack, CScript(&pushdata2[0], &pushdata2[sizeof(pushdata2)]), SCRIPT_VERIFY_P2SH, BaseSignatureChecker(), SigVersion::BASE, &err));
|
||||
BOOST_CHECK(pushdata2Stack == directStack);
|
||||
BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_OK, ScriptErrorString(err));
|
||||
|
||||
std::vector<std::vector<unsigned char> > pushdata4Stack;
|
||||
BOOST_CHECK(EvalScript(pushdata4Stack, CScript(&pushdata4[0], &pushdata4[sizeof(pushdata4)]), SCRIPT_VERIFY_P2SH, BaseSignatureChecker(), SIGVERSION_BASE, &err));
|
||||
BOOST_CHECK(EvalScript(pushdata4Stack, CScript(&pushdata4[0], &pushdata4[sizeof(pushdata4)]), SCRIPT_VERIFY_P2SH, BaseSignatureChecker(), SigVersion::BASE, &err));
|
||||
BOOST_CHECK(pushdata4Stack == directStack);
|
||||
BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_OK, ScriptErrorString(err));
|
||||
}
|
||||
@ -767,7 +767,7 @@ BOOST_AUTO_TEST_CASE(script_PushData)
|
||||
CScript
|
||||
sign_multisig(CScript scriptPubKey, std::vector<CKey> keys, CTransaction transaction)
|
||||
{
|
||||
uint256 hash = SignatureHash(scriptPubKey, transaction, 0, SIGHASH_ALL, 0, SIGVERSION_BASE);
|
||||
uint256 hash = SignatureHash(scriptPubKey, transaction, 0, SIGHASH_ALL, 0, SigVersion::BASE);
|
||||
|
||||
CScript result;
|
||||
//
|
||||
@ -963,15 +963,15 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
|
||||
|
||||
// A couple of partially-signed versions:
|
||||
std::vector<unsigned char> sig1;
|
||||
uint256 hash1 = SignatureHash(scriptPubKey, txTo, 0, SIGHASH_ALL, 0, SIGVERSION_BASE);
|
||||
uint256 hash1 = SignatureHash(scriptPubKey, txTo, 0, SIGHASH_ALL, 0, SigVersion::BASE);
|
||||
BOOST_CHECK(keys[0].Sign(hash1, sig1));
|
||||
sig1.push_back(SIGHASH_ALL);
|
||||
std::vector<unsigned char> sig2;
|
||||
uint256 hash2 = SignatureHash(scriptPubKey, txTo, 0, SIGHASH_NONE, 0, SIGVERSION_BASE);
|
||||
uint256 hash2 = SignatureHash(scriptPubKey, txTo, 0, SIGHASH_NONE, 0, SigVersion::BASE);
|
||||
BOOST_CHECK(keys[1].Sign(hash2, sig2));
|
||||
sig2.push_back(SIGHASH_NONE);
|
||||
std::vector<unsigned char> sig3;
|
||||
uint256 hash3 = SignatureHash(scriptPubKey, txTo, 0, SIGHASH_SINGLE, 0, SIGVERSION_BASE);
|
||||
uint256 hash3 = SignatureHash(scriptPubKey, txTo, 0, SIGHASH_SINGLE, 0, SigVersion::BASE);
|
||||
BOOST_CHECK(keys[2].Sign(hash3, sig3));
|
||||
sig3.push_back(SIGHASH_SINGLE);
|
||||
|
||||
|
@ -138,7 +138,7 @@ BOOST_AUTO_TEST_CASE(sighash_test)
|
||||
|
||||
uint256 sh, sho;
|
||||
sho = SignatureHashOld(scriptCode, txTo, nIn, nHashType);
|
||||
sh = SignatureHash(scriptCode, txTo, nIn, nHashType, 0, SIGVERSION_BASE);
|
||||
sh = SignatureHash(scriptCode, txTo, nIn, nHashType, 0, SigVersion::BASE);
|
||||
#if defined(PRINT_SIGHASH_JSON)
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ss << txTo;
|
||||
@ -204,7 +204,7 @@ BOOST_AUTO_TEST_CASE(sighash_from_data)
|
||||
continue;
|
||||
}
|
||||
|
||||
sh = SignatureHash(scriptCode, *tx, nIn, nHashType, 0, SIGVERSION_BASE);
|
||||
sh = SignatureHash(scriptCode, *tx, nIn, nHashType, 0, SigVersion::BASE);
|
||||
BOOST_CHECK_MESSAGE(sh.GetHex() == sigHashHex, strTest);
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
|
||||
|
||||
// Sign:
|
||||
std::vector<unsigned char> vchSig;
|
||||
uint256 hash = SignatureHash(scriptPubKey, spends[i], 0, SIGHASH_ALL, 0, SIGVERSION_BASE);
|
||||
uint256 hash = SignatureHash(scriptPubKey, spends[i], 0, SIGHASH_ALL, 0, SigVersion::BASE);
|
||||
BOOST_CHECK(coinbaseKey.Sign(hash, vchSig));
|
||||
vchSig.push_back((unsigned char)SIGHASH_ALL);
|
||||
spends[i].vin[0].scriptSig << vchSig;
|
||||
@ -189,7 +189,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
|
||||
// Sign, with a non-DER signature
|
||||
{
|
||||
std::vector<unsigned char> vchSig;
|
||||
uint256 hash = SignatureHash(p2pk_scriptPubKey, spend_tx, 0, SIGHASH_ALL, 0, SIGVERSION_BASE);
|
||||
uint256 hash = SignatureHash(p2pk_scriptPubKey, spend_tx, 0, SIGHASH_ALL, 0, SigVersion::BASE);
|
||||
BOOST_CHECK(coinbaseKey.Sign(hash, vchSig));
|
||||
vchSig.push_back((unsigned char) 0); // padding byte makes this non-DER
|
||||
vchSig.push_back((unsigned char)SIGHASH_ALL);
|
||||
@ -262,7 +262,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
|
||||
|
||||
// Sign
|
||||
std::vector<unsigned char> vchSig;
|
||||
uint256 hash = SignatureHash(spend_tx.vout[2].scriptPubKey, invalid_with_cltv_tx, 0, SIGHASH_ALL, 0, SIGVERSION_BASE);
|
||||
uint256 hash = SignatureHash(spend_tx.vout[2].scriptPubKey, invalid_with_cltv_tx, 0, SIGHASH_ALL, 0, SigVersion::BASE);
|
||||
BOOST_CHECK(coinbaseKey.Sign(hash, vchSig));
|
||||
vchSig.push_back((unsigned char)SIGHASH_ALL);
|
||||
invalid_with_cltv_tx.vin[0].scriptSig = CScript() << vchSig << 101;
|
||||
@ -290,7 +290,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
|
||||
|
||||
// Sign
|
||||
std::vector<unsigned char> vchSig;
|
||||
uint256 hash = SignatureHash(spend_tx.vout[3].scriptPubKey, invalid_with_csv_tx, 0, SIGHASH_ALL, 0, SIGVERSION_BASE);
|
||||
uint256 hash = SignatureHash(spend_tx.vout[3].scriptPubKey, invalid_with_csv_tx, 0, SIGHASH_ALL, 0, SigVersion::BASE);
|
||||
BOOST_CHECK(coinbaseKey.Sign(hash, vchSig));
|
||||
vchSig.push_back((unsigned char)SIGHASH_ALL);
|
||||
invalid_with_csv_tx.vin[0].scriptSig = CScript() << vchSig << 101;
|
||||
|
@ -91,7 +91,7 @@ public:
|
||||
VersionBitsTester& TestDefined() {
|
||||
for (int i = 0; i < CHECKERS; i++) {
|
||||
if (InsecureRandBits(i) == 0) {
|
||||
BOOST_CHECK_MESSAGE(checker[i].GetStateFor(vpblock.empty() ? nullptr : vpblock.back()) == THRESHOLD_DEFINED, strprintf("Test %i for DEFINED", num));
|
||||
BOOST_CHECK_MESSAGE(checker[i].GetStateFor(vpblock.empty() ? nullptr : vpblock.back()) == ThresholdState::DEFINED, strprintf("Test %i for DEFINED", num));
|
||||
}
|
||||
}
|
||||
num++;
|
||||
@ -101,7 +101,7 @@ public:
|
||||
VersionBitsTester& TestStarted() {
|
||||
for (int i = 0; i < CHECKERS; i++) {
|
||||
if (InsecureRandBits(i) == 0) {
|
||||
BOOST_CHECK_MESSAGE(checker[i].GetStateFor(vpblock.empty() ? nullptr : vpblock.back()) == THRESHOLD_STARTED, strprintf("Test %i for STARTED", num));
|
||||
BOOST_CHECK_MESSAGE(checker[i].GetStateFor(vpblock.empty() ? nullptr : vpblock.back()) == ThresholdState::STARTED, strprintf("Test %i for STARTED", num));
|
||||
}
|
||||
}
|
||||
num++;
|
||||
@ -111,7 +111,7 @@ public:
|
||||
VersionBitsTester& TestLockedIn() {
|
||||
for (int i = 0; i < CHECKERS; i++) {
|
||||
if (InsecureRandBits(i) == 0) {
|
||||
BOOST_CHECK_MESSAGE(checker[i].GetStateFor(vpblock.empty() ? nullptr : vpblock.back()) == THRESHOLD_LOCKED_IN, strprintf("Test %i for LOCKED_IN", num));
|
||||
BOOST_CHECK_MESSAGE(checker[i].GetStateFor(vpblock.empty() ? nullptr : vpblock.back()) == ThresholdState::LOCKED_IN, strprintf("Test %i for LOCKED_IN", num));
|
||||
}
|
||||
}
|
||||
num++;
|
||||
@ -121,7 +121,7 @@ public:
|
||||
VersionBitsTester& TestActive() {
|
||||
for (int i = 0; i < CHECKERS; i++) {
|
||||
if (InsecureRandBits(i) == 0) {
|
||||
BOOST_CHECK_MESSAGE(checker[i].GetStateFor(vpblock.empty() ? nullptr : vpblock.back()) == THRESHOLD_ACTIVE, strprintf("Test %i for ACTIVE", num));
|
||||
BOOST_CHECK_MESSAGE(checker[i].GetStateFor(vpblock.empty() ? nullptr : vpblock.back()) == ThresholdState::ACTIVE, strprintf("Test %i for ACTIVE", num));
|
||||
}
|
||||
}
|
||||
num++;
|
||||
@ -131,7 +131,7 @@ public:
|
||||
VersionBitsTester& TestFailed() {
|
||||
for (int i = 0; i < CHECKERS; i++) {
|
||||
if (InsecureRandBits(i) == 0) {
|
||||
BOOST_CHECK_MESSAGE(checker[i].GetStateFor(vpblock.empty() ? nullptr : vpblock.back()) == THRESHOLD_FAILED, strprintf("Test %i for FAILED", num));
|
||||
BOOST_CHECK_MESSAGE(checker[i].GetStateFor(vpblock.empty() ? nullptr : vpblock.back()) == ThresholdState::FAILED, strprintf("Test %i for FAILED", num));
|
||||
}
|
||||
}
|
||||
num++;
|
||||
|
@ -300,11 +300,11 @@ std::unique_ptr<CCoinsViewDB> pcoinsdbview;
|
||||
std::unique_ptr<CCoinsViewCache> pcoinsTip;
|
||||
std::unique_ptr<CBlockTreeDB> pblocktree;
|
||||
|
||||
enum FlushStateMode {
|
||||
FLUSH_STATE_NONE,
|
||||
FLUSH_STATE_IF_NEEDED,
|
||||
FLUSH_STATE_PERIODIC,
|
||||
FLUSH_STATE_ALWAYS
|
||||
enum class FlushStateMode {
|
||||
NONE,
|
||||
IF_NEEDED,
|
||||
PERIODIC,
|
||||
ALWAYS
|
||||
};
|
||||
|
||||
// See definition for documentation
|
||||
@ -883,7 +883,7 @@ static bool AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPo
|
||||
}
|
||||
// After we've (potentially) uncached entries, ensure our coins cache is still within its size limits
|
||||
CValidationState stateDummy;
|
||||
FlushStateToDisk(chainparams, stateDummy, FLUSH_STATE_PERIODIC);
|
||||
FlushStateToDisk(chainparams, stateDummy, FlushStateMode::PERIODIC);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -1837,10 +1837,10 @@ int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Para
|
||||
Consensus::DeploymentPos pos = Consensus::DeploymentPos(i);
|
||||
ThresholdState state = VersionBitsState(pindexPrev, params, pos, versionbitscache);
|
||||
const struct VBDeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
|
||||
if (vbinfo.check_mn_protocol && state == THRESHOLD_STARTED && fCheckMasternodesUpgraded) {
|
||||
if (vbinfo.check_mn_protocol && state == ThresholdState::STARTED && fCheckMasternodesUpgraded) {
|
||||
// TODO implement new logic for MN upgrade checks (e.g. with LLMQ based feature/version voting)
|
||||
}
|
||||
if (state == THRESHOLD_LOCKED_IN || state == THRESHOLD_STARTED) {
|
||||
if (state == ThresholdState::LOCKED_IN || state == ThresholdState::STARTED) {
|
||||
nVersion |= VersionBitsMask(params, static_cast<Consensus::DeploymentPos>(i));
|
||||
}
|
||||
}
|
||||
@ -1905,12 +1905,12 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens
|
||||
}
|
||||
|
||||
// Start enforcing BIP68 (sequence locks) and BIP112 (CHECKSEQUENCEVERIFY) using versionbits logic.
|
||||
if (VersionBitsState(pindex->pprev, consensusparams, Consensus::DEPLOYMENT_CSV, versionbitscache) == THRESHOLD_ACTIVE) {
|
||||
if (VersionBitsState(pindex->pprev, consensusparams, Consensus::DEPLOYMENT_CSV, versionbitscache) == ThresholdState::ACTIVE) {
|
||||
flags |= SCRIPT_VERIFY_CHECKSEQUENCEVERIFY;
|
||||
}
|
||||
|
||||
// Start enforcing BIP147 (NULLDUMMY) rule using versionbits logic.
|
||||
if (VersionBitsState(pindex->pprev, consensusparams, Consensus::DEPLOYMENT_BIP147, versionbitscache) == THRESHOLD_ACTIVE) {
|
||||
if (VersionBitsState(pindex->pprev, consensusparams, Consensus::DEPLOYMENT_BIP147, versionbitscache) == ThresholdState::ACTIVE) {
|
||||
flags |= SCRIPT_VERIFY_NULLDUMMY;
|
||||
}
|
||||
|
||||
@ -2071,7 +2071,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||
|
||||
// Start enforcing BIP68 (sequence locks) and BIP112 (CHECKSEQUENCEVERIFY) using versionbits logic.
|
||||
int nLockTimeFlags = 0;
|
||||
if (VersionBitsState(pindex->pprev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_CSV, versionbitscache) == THRESHOLD_ACTIVE) {
|
||||
if (VersionBitsState(pindex->pprev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_CSV, versionbitscache) == ThresholdState::ACTIVE) {
|
||||
nLockTimeFlags |= LOCKTIME_VERIFY_SEQUENCE;
|
||||
}
|
||||
|
||||
@ -2412,15 +2412,15 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
|
||||
cacheSize += evoDb->GetMemoryUsage();
|
||||
int64_t nTotalSpace = nCoinCacheUsage + std::max<int64_t>(nMempoolSizeMax - nMempoolUsage, 0);
|
||||
// The cache is large and we're within 10% and 10 MiB of the limit, but we have time now (not in the middle of a block processing).
|
||||
bool fCacheLarge = mode == FLUSH_STATE_PERIODIC && cacheSize > std::max((9 * nTotalSpace) / 10, nTotalSpace - MAX_BLOCK_COINSDB_USAGE * 1024 * 1024);
|
||||
bool fCacheLarge = mode == FlushStateMode::PERIODIC && cacheSize > std::max((9 * nTotalSpace) / 10, nTotalSpace - MAX_BLOCK_COINSDB_USAGE * 1024 * 1024);
|
||||
// The cache is over the limit, we have to write now.
|
||||
bool fCacheCritical = mode == FLUSH_STATE_IF_NEEDED && cacheSize > nCoinCacheUsage;
|
||||
bool fCacheCritical = mode == FlushStateMode::IF_NEEDED && cacheSize > nCoinCacheUsage;
|
||||
// It's been a while since we wrote the block index to disk. Do this frequently, so we don't need to redownload after a crash.
|
||||
bool fPeriodicWrite = mode == FLUSH_STATE_PERIODIC && nNow > nLastWrite + (int64_t)DATABASE_WRITE_INTERVAL * 1000000;
|
||||
bool fPeriodicWrite = mode == FlushStateMode::PERIODIC && nNow > nLastWrite + (int64_t)DATABASE_WRITE_INTERVAL * 1000000;
|
||||
// It's been very long since we flushed the cache. Do this infrequently, to optimize cache usage.
|
||||
bool fPeriodicFlush = mode == FLUSH_STATE_PERIODIC && nNow > nLastFlush + (int64_t)DATABASE_FLUSH_INTERVAL * 1000000;
|
||||
bool fPeriodicFlush = mode == FlushStateMode::PERIODIC && nNow > nLastFlush + (int64_t)DATABASE_FLUSH_INTERVAL * 1000000;
|
||||
// Combine all conditions that result in a full cache flush.
|
||||
fDoFullFlush = (mode == FLUSH_STATE_ALWAYS) || fCacheLarge || fCacheCritical || fPeriodicFlush || fFlushForPrune;
|
||||
fDoFullFlush = (mode == FlushStateMode::ALWAYS) || fCacheLarge || fCacheCritical || fPeriodicFlush || fFlushForPrune;
|
||||
// Write blocks and block index to disk.
|
||||
if (fDoFullFlush || fPeriodicWrite) {
|
||||
// Depend on nMinDiskSpace to ensure we can write block index
|
||||
@ -2469,7 +2469,7 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
|
||||
nLastFlush = nNow;
|
||||
}
|
||||
}
|
||||
if (fDoFullFlush || ((mode == FLUSH_STATE_ALWAYS || mode == FLUSH_STATE_PERIODIC) && nNow > nLastSetChain + (int64_t)DATABASE_WRITE_INTERVAL * 1000000)) {
|
||||
if (fDoFullFlush || ((mode == FlushStateMode::ALWAYS || mode == FlushStateMode::PERIODIC) && nNow > nLastSetChain + (int64_t)DATABASE_WRITE_INTERVAL * 1000000)) {
|
||||
// Update best block in wallet (so we can detect restored wallets).
|
||||
GetMainSignals().SetBestChain(chainActive.GetLocator());
|
||||
nLastSetChain = nNow;
|
||||
@ -2483,14 +2483,14 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
|
||||
void FlushStateToDisk() {
|
||||
CValidationState state;
|
||||
const CChainParams& chainparams = Params();
|
||||
FlushStateToDisk(chainparams, state, FLUSH_STATE_ALWAYS);
|
||||
FlushStateToDisk(chainparams, state, FlushStateMode::ALWAYS);
|
||||
}
|
||||
|
||||
void PruneAndFlush() {
|
||||
CValidationState state;
|
||||
fCheckForPruning = true;
|
||||
const CChainParams& chainparams = Params();
|
||||
FlushStateToDisk(chainparams, state, FLUSH_STATE_NONE);
|
||||
FlushStateToDisk(chainparams, state, FlushStateMode::NONE);
|
||||
}
|
||||
|
||||
static void DoWarning(const std::string& strWarning)
|
||||
@ -2522,9 +2522,9 @@ void static UpdateTip(const CBlockIndex *pindexNew, const CChainParams& chainPar
|
||||
for (int bit = 0; bit < VERSIONBITS_NUM_BITS; bit++) {
|
||||
WarningBitsConditionChecker checker(bit);
|
||||
ThresholdState state = checker.GetStateFor(pindex, chainParams.GetConsensus(), warningcache[bit]);
|
||||
if (state == THRESHOLD_ACTIVE || state == THRESHOLD_LOCKED_IN) {
|
||||
if (state == ThresholdState::ACTIVE || state == ThresholdState::LOCKED_IN) {
|
||||
const std::string strWarning = strprintf(_("Warning: unknown new rules activated (versionbit %i)"), bit);
|
||||
if (state == THRESHOLD_ACTIVE) {
|
||||
if (state == ThresholdState::ACTIVE) {
|
||||
DoWarning(strWarning);
|
||||
} else {
|
||||
warningMessages.push_back(strWarning);
|
||||
@ -2593,7 +2593,7 @@ bool CChainState::DisconnectTip(CValidationState& state, const CChainParams& cha
|
||||
}
|
||||
LogPrint(BCLog::BENCHMARK, "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * MILLI);
|
||||
// Write the chain state to disk, if necessary.
|
||||
if (!FlushStateToDisk(chainparams, state, FLUSH_STATE_IF_NEEDED))
|
||||
if (!FlushStateToDisk(chainparams, state, FlushStateMode::IF_NEEDED))
|
||||
return false;
|
||||
|
||||
if (disconnectpool) {
|
||||
@ -2734,7 +2734,7 @@ bool CChainState::ConnectTip(CValidationState& state, const CChainParams& chainp
|
||||
int64_t nTime4 = GetTimeMicros(); nTimeFlush += nTime4 - nTime3;
|
||||
LogPrint(BCLog::BENCHMARK, " - Flush: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime4 - nTime3) * MILLI, nTimeFlush * MICRO, nTimeFlush * MILLI / nBlocksTotal);
|
||||
// Write the chain state to disk, if necessary.
|
||||
if (!FlushStateToDisk(chainparams, state, FLUSH_STATE_IF_NEEDED))
|
||||
if (!FlushStateToDisk(chainparams, state, FlushStateMode::IF_NEEDED))
|
||||
return false;
|
||||
int64_t nTime5 = GetTimeMicros(); nTimeChainState += nTime5 - nTime4;
|
||||
LogPrint(BCLog::BENCHMARK, " - Writing chainstate: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime5 - nTime4) * MILLI, nTimeChainState * MICRO, nTimeChainState * MILLI / nBlocksTotal);
|
||||
@ -3019,7 +3019,7 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
|
||||
CheckBlockIndex(chainparams.GetConsensus());
|
||||
|
||||
// Write changes periodically to disk, after relay.
|
||||
if (!FlushStateToDisk(chainparams, state, FLUSH_STATE_PERIODIC)) {
|
||||
if (!FlushStateToDisk(chainparams, state, FlushStateMode::PERIODIC)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -3503,7 +3503,7 @@ static bool ContextualCheckBlock(const CBlock& block, CValidationState& state, c
|
||||
|
||||
// Start enforcing BIP113 (Median Time Past) using versionbits logic.
|
||||
int nLockTimeFlags = 0;
|
||||
if (VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_CSV, versionbitscache) == THRESHOLD_ACTIVE) {
|
||||
if (VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_CSV, versionbitscache) == ThresholdState::ACTIVE) {
|
||||
nLockTimeFlags |= LOCKTIME_MEDIAN_TIME_PAST;
|
||||
}
|
||||
|
||||
@ -3750,7 +3750,7 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CVali
|
||||
}
|
||||
|
||||
if (fCheckForPruning)
|
||||
FlushStateToDisk(chainparams, state, FLUSH_STATE_NONE); // we just allocated more disk space for block files
|
||||
FlushStateToDisk(chainparams, state, FlushStateMode::NONE); // we just allocated more disk space for block files
|
||||
|
||||
CheckBlockIndex(chainparams.GetConsensus());
|
||||
|
||||
@ -3911,7 +3911,7 @@ void PruneBlockFilesManual(int nManualPruneHeight)
|
||||
{
|
||||
CValidationState state;
|
||||
const CChainParams& chainparams = Params();
|
||||
FlushStateToDisk(chainparams, state, FLUSH_STATE_NONE, nManualPruneHeight);
|
||||
FlushStateToDisk(chainparams, state, FlushStateMode::NONE, nManualPruneHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,12 +55,12 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex*
|
||||
while (cache.count(pindexPrev) == 0) {
|
||||
if (pindexPrev == nullptr) {
|
||||
// The genesis block is by definition defined.
|
||||
cache[pindexPrev] = THRESHOLD_DEFINED;
|
||||
cache[pindexPrev] = ThresholdState::DEFINED;
|
||||
break;
|
||||
}
|
||||
if (pindexPrev->GetMedianTimePast() < nTimeStart) {
|
||||
// Optimization: don't recompute down further, as we know every earlier block will be before the start time
|
||||
cache[pindexPrev] = THRESHOLD_DEFINED;
|
||||
cache[pindexPrev] = ThresholdState::DEFINED;
|
||||
break;
|
||||
}
|
||||
vToCompute.push_back(pindexPrev);
|
||||
@ -78,17 +78,17 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex*
|
||||
vToCompute.pop_back();
|
||||
|
||||
switch (state) {
|
||||
case THRESHOLD_DEFINED: {
|
||||
case ThresholdState::DEFINED: {
|
||||
if (pindexPrev->GetMedianTimePast() >= nTimeTimeout) {
|
||||
stateNext = THRESHOLD_FAILED;
|
||||
stateNext = ThresholdState::FAILED;
|
||||
} else if (pindexPrev->GetMedianTimePast() >= nTimeStart) {
|
||||
stateNext = THRESHOLD_STARTED;
|
||||
stateNext = ThresholdState::STARTED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case THRESHOLD_STARTED: {
|
||||
case ThresholdState::STARTED: {
|
||||
if (pindexPrev->GetMedianTimePast() >= nTimeTimeout) {
|
||||
stateNext = THRESHOLD_FAILED;
|
||||
stateNext = ThresholdState::FAILED;
|
||||
break;
|
||||
}
|
||||
// We need to count
|
||||
@ -101,17 +101,17 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex*
|
||||
pindexCount = pindexCount->pprev;
|
||||
}
|
||||
if (count >= nThreshold) {
|
||||
stateNext = THRESHOLD_LOCKED_IN;
|
||||
stateNext = ThresholdState::LOCKED_IN;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case THRESHOLD_LOCKED_IN: {
|
||||
case ThresholdState::LOCKED_IN: {
|
||||
// Always progresses into ACTIVE.
|
||||
stateNext = THRESHOLD_ACTIVE;
|
||||
stateNext = ThresholdState::ACTIVE;
|
||||
break;
|
||||
}
|
||||
case THRESHOLD_FAILED:
|
||||
case THRESHOLD_ACTIVE: {
|
||||
case ThresholdState::FAILED:
|
||||
case ThresholdState::ACTIVE: {
|
||||
// Nothing happens, these are terminal states.
|
||||
break;
|
||||
}
|
||||
@ -157,7 +157,7 @@ int AbstractThresholdConditionChecker::GetStateSinceHeightFor(const CBlockIndex*
|
||||
const ThresholdState initialState = GetStateFor(pindexPrev, params, cache);
|
||||
|
||||
// BIP 9 about state DEFINED: "The genesis block is by definition in this state for each deployment."
|
||||
if (initialState == THRESHOLD_DEFINED) {
|
||||
if (initialState == ThresholdState::DEFINED) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,12 @@ static const int32_t VERSIONBITS_TOP_MASK = 0xE0000000UL;
|
||||
/** Total bits available for versionbits */
|
||||
static const int32_t VERSIONBITS_NUM_BITS = 29;
|
||||
|
||||
enum ThresholdState {
|
||||
THRESHOLD_DEFINED,
|
||||
THRESHOLD_STARTED,
|
||||
THRESHOLD_LOCKED_IN,
|
||||
THRESHOLD_ACTIVE,
|
||||
THRESHOLD_FAILED,
|
||||
enum class ThresholdState {
|
||||
DEFINED,
|
||||
STARTED,
|
||||
LOCKED_IN,
|
||||
ACTIVE,
|
||||
FAILED,
|
||||
};
|
||||
|
||||
// A map that gives the state for blocks whose height is a multiple of Period().
|
||||
|
@ -235,13 +235,13 @@ BerkeleyEnvironment::VerifyResult BerkeleyEnvironment::Verify(const std::string&
|
||||
Db db(dbenv.get(), 0);
|
||||
int result = db.verify(strFile.c_str(), nullptr, nullptr, 0);
|
||||
if (result == 0)
|
||||
return VERIFY_OK;
|
||||
return VerifyResult::VERIFY_OK;
|
||||
else if (recoverFunc == nullptr)
|
||||
return RECOVER_FAIL;
|
||||
return VerifyResult::RECOVER_FAIL;
|
||||
|
||||
// Try to recover:
|
||||
bool fRecovered = (*recoverFunc)(fs::path(strPath) / strFile, out_backup_filename);
|
||||
return (fRecovered ? RECOVER_OK : RECOVER_FAIL);
|
||||
return (fRecovered ? VerifyResult::RECOVER_OK : VerifyResult::RECOVER_FAIL);
|
||||
}
|
||||
|
||||
bool BerkeleyBatch::Recover(const fs::path& file_path, void *callbackDataIn, bool (*recoverKVcallback)(void* callbackData, CDataStream ssKey, CDataStream ssValue), std::string& newFilename)
|
||||
@ -347,7 +347,7 @@ bool BerkeleyBatch::VerifyDatabaseFile(const fs::path& file_path, std::string& w
|
||||
{
|
||||
std::string backup_filename;
|
||||
BerkeleyEnvironment::VerifyResult r = env->Verify(walletFile, recoverFunc, backup_filename);
|
||||
if (r == BerkeleyEnvironment::RECOVER_OK)
|
||||
if (r == BerkeleyEnvironment::VerifyResult::RECOVER_OK)
|
||||
{
|
||||
warningStr = strprintf(_("Warning: Wallet file corrupt, data salvaged!"
|
||||
" Original %s saved as %s in %s; if"
|
||||
@ -355,7 +355,7 @@ bool BerkeleyBatch::VerifyDatabaseFile(const fs::path& file_path, std::string& w
|
||||
" restore from a backup."),
|
||||
walletFile, backup_filename, walletDir);
|
||||
}
|
||||
if (r == BerkeleyEnvironment::RECOVER_FAIL)
|
||||
if (r == BerkeleyEnvironment::VerifyResult::RECOVER_FAIL)
|
||||
{
|
||||
errorStr = strprintf(_("%s corrupt, salvage failed"), walletFile);
|
||||
return false;
|
||||
|
@ -54,7 +54,7 @@ public:
|
||||
* This must be called BEFORE strFile is opened.
|
||||
* Returns true if strFile is OK.
|
||||
*/
|
||||
enum VerifyResult { VERIFY_OK,
|
||||
enum class VerifyResult { VERIFY_OK,
|
||||
RECOVER_OK,
|
||||
RECOVER_FAIL };
|
||||
typedef bool (*recoverFunc_type)(const fs::path& file_path, std::string& out_backup_filename);
|
||||
|
@ -387,7 +387,7 @@ UniValue removeprunedfunds(const JSONRPCRequest& request)
|
||||
vHash.push_back(hash);
|
||||
std::vector<uint256> vHashOut;
|
||||
|
||||
if (pwallet->ZapSelectTx(vHash, vHashOut) != DB_LOAD_OK) {
|
||||
if (pwallet->ZapSelectTx(vHash, vHashOut) != DBErrors::LOAD_OK) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Could not properly delete the transaction.");
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ GetResults(CWallet& wallet, std::map<CAmount, CAccountingEntry>& results)
|
||||
std::list<CAccountingEntry> aes;
|
||||
|
||||
results.clear();
|
||||
BOOST_CHECK(wallet.ReorderTransactions() == DB_LOAD_OK);
|
||||
BOOST_CHECK(wallet.ReorderTransactions() == DBErrors::LOAD_OK);
|
||||
wallet.ListAccountCreditDebit("", aes);
|
||||
for (CAccountingEntry& ae : aes)
|
||||
{
|
||||
|
@ -958,11 +958,11 @@ DBErrors CWallet::ReorderTransactions()
|
||||
if (pwtx)
|
||||
{
|
||||
if (!batch.WriteTx(*pwtx))
|
||||
return DB_LOAD_FAIL;
|
||||
return DBErrors::LOAD_FAIL;
|
||||
}
|
||||
else
|
||||
if (!batch.WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
|
||||
return DB_LOAD_FAIL;
|
||||
return DBErrors::LOAD_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -982,16 +982,16 @@ DBErrors CWallet::ReorderTransactions()
|
||||
if (pwtx)
|
||||
{
|
||||
if (!batch.WriteTx(*pwtx))
|
||||
return DB_LOAD_FAIL;
|
||||
return DBErrors::LOAD_FAIL;
|
||||
}
|
||||
else
|
||||
if (!batch.WriteAccountingEntry(pacentry->nEntryNo, *pacentry))
|
||||
return DB_LOAD_FAIL;
|
||||
return DBErrors::LOAD_FAIL;
|
||||
}
|
||||
}
|
||||
batch.WriteOrderPosNext(nOrderPosNext);
|
||||
|
||||
return DB_LOAD_OK;
|
||||
return DBErrors::LOAD_OK;
|
||||
}
|
||||
|
||||
int64_t CWallet::IncOrderPosNext(WalletBatch *batch)
|
||||
@ -4140,7 +4140,7 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
|
||||
|
||||
fFirstRunRet = false;
|
||||
DBErrors nLoadWalletRet = WalletBatch(*database,"cr+").LoadWallet(this);
|
||||
if (nLoadWalletRet == DB_NEED_REWRITE)
|
||||
if (nLoadWalletRet == DBErrors::NEED_REWRITE)
|
||||
{
|
||||
if (database->Rewrite("\x04pool"))
|
||||
{
|
||||
@ -4168,12 +4168,12 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
|
||||
}
|
||||
}
|
||||
|
||||
if (nLoadWalletRet != DB_LOAD_OK)
|
||||
if (nLoadWalletRet != DBErrors::LOAD_OK)
|
||||
return nLoadWalletRet;
|
||||
|
||||
uiInterface.LoadWallet(this);
|
||||
|
||||
return DB_LOAD_OK;
|
||||
return DBErrors::LOAD_OK;
|
||||
}
|
||||
|
||||
// Goes through all wallet transactions and checks if they are masternode collaterals, in which case these are locked
|
||||
@ -4204,7 +4204,7 @@ DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256
|
||||
mapWallet.erase(it);
|
||||
}
|
||||
|
||||
if (nZapSelectTxRet == DB_NEED_REWRITE)
|
||||
if (nZapSelectTxRet == DBErrors::NEED_REWRITE)
|
||||
{
|
||||
if (database->Rewrite("\x04pool"))
|
||||
{
|
||||
@ -4217,19 +4217,19 @@ DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256
|
||||
}
|
||||
}
|
||||
|
||||
if (nZapSelectTxRet != DB_LOAD_OK)
|
||||
if (nZapSelectTxRet != DBErrors::LOAD_OK)
|
||||
return nZapSelectTxRet;
|
||||
|
||||
MarkDirty();
|
||||
|
||||
return DB_LOAD_OK;
|
||||
return DBErrors::LOAD_OK;
|
||||
|
||||
}
|
||||
|
||||
DBErrors CWallet::ZapWalletTx(std::vector<CWalletTx>& vWtx)
|
||||
{
|
||||
DBErrors nZapWalletTxRet = WalletBatch(*database,"cr+").ZapWalletTx(vWtx);
|
||||
if (nZapWalletTxRet == DB_NEED_REWRITE)
|
||||
if (nZapWalletTxRet == DBErrors::NEED_REWRITE)
|
||||
{
|
||||
if (database->Rewrite("\x04pool"))
|
||||
{
|
||||
@ -4244,10 +4244,10 @@ DBErrors CWallet::ZapWalletTx(std::vector<CWalletTx>& vWtx)
|
||||
}
|
||||
}
|
||||
|
||||
if (nZapWalletTxRet != DB_LOAD_OK)
|
||||
if (nZapWalletTxRet != DBErrors::LOAD_OK)
|
||||
return nZapWalletTxRet;
|
||||
|
||||
return DB_LOAD_OK;
|
||||
return DBErrors::LOAD_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -5061,7 +5061,7 @@ CWallet* CWallet::CreateWalletFromFile(const std::string& name, const fs::path&
|
||||
|
||||
std::unique_ptr<CWallet> tempWallet = MakeUnique<CWallet>(name, WalletDatabase::Create(path));
|
||||
DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx);
|
||||
if (nZapWalletRet != DB_LOAD_OK) {
|
||||
if (nZapWalletRet != DBErrors::LOAD_OK) {
|
||||
InitError(strprintf(_("Error loading %s: Wallet corrupted"), walletFile));
|
||||
return nullptr;
|
||||
}
|
||||
@ -5076,23 +5076,23 @@ CWallet* CWallet::CreateWalletFromFile(const std::string& name, const fs::path&
|
||||
auto temp_wallet = MakeUnique<CWallet>(name, WalletDatabase::Create(path));
|
||||
CWallet *walletInstance = temp_wallet.get();
|
||||
DBErrors nLoadWalletRet = walletInstance->LoadWallet(fFirstRun);
|
||||
if (nLoadWalletRet != DB_LOAD_OK)
|
||||
if (nLoadWalletRet != DBErrors::LOAD_OK)
|
||||
{
|
||||
if (nLoadWalletRet == DB_CORRUPT) {
|
||||
if (nLoadWalletRet == DBErrors::CORRUPT) {
|
||||
InitError(strprintf(_("Error loading %s: Wallet corrupted"), walletFile));
|
||||
return nullptr;
|
||||
}
|
||||
else if (nLoadWalletRet == DB_NONCRITICAL_ERROR)
|
||||
else if (nLoadWalletRet == DBErrors::NONCRITICAL_ERROR)
|
||||
{
|
||||
InitWarning(strprintf(_("Error reading %s! All keys read correctly, but transaction data"
|
||||
" or address book entries might be missing or incorrect."),
|
||||
walletFile));
|
||||
}
|
||||
else if (nLoadWalletRet == DB_TOO_NEW) {
|
||||
else if (nLoadWalletRet == DBErrors::TOO_NEW) {
|
||||
InitError(strprintf(_("Error loading %s: Wallet requires newer version of %s"), walletFile, _(PACKAGE_NAME)));
|
||||
return nullptr;
|
||||
}
|
||||
else if (nLoadWalletRet == DB_NEED_REWRITE)
|
||||
else if (nLoadWalletRet == DBErrors::NEED_REWRITE)
|
||||
{
|
||||
InitError(strprintf(_("Wallet needed to be rewritten: restart %s to complete"), _(PACKAGE_NAME)));
|
||||
return nullptr;
|
||||
|
@ -555,7 +555,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
|
||||
{
|
||||
CWalletScanState wss;
|
||||
bool fNoncriticalErrors = false;
|
||||
DBErrors result = DB_LOAD_OK;
|
||||
DBErrors result = DBErrors::LOAD_OK;
|
||||
|
||||
LOCK2(cs_main, pwallet->cs_wallet);
|
||||
try {
|
||||
@ -563,7 +563,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
|
||||
if (m_batch.Read((std::string)"minversion", nMinVersion))
|
||||
{
|
||||
if (nMinVersion > CLIENT_VERSION)
|
||||
return DB_TOO_NEW;
|
||||
return DBErrors::TOO_NEW;
|
||||
pwallet->LoadMinVersion(nMinVersion);
|
||||
}
|
||||
|
||||
@ -572,7 +572,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
|
||||
if (!pcursor)
|
||||
{
|
||||
LogPrintf("Error getting wallet database cursor\n");
|
||||
return DB_CORRUPT;
|
||||
return DBErrors::CORRUPT;
|
||||
}
|
||||
|
||||
while (true)
|
||||
@ -586,7 +586,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
|
||||
else if (ret != 0)
|
||||
{
|
||||
LogPrintf("Error reading next record from wallet database\n");
|
||||
return DB_CORRUPT;
|
||||
return DBErrors::CORRUPT;
|
||||
}
|
||||
|
||||
// Try to be tolerant of single corrupt records:
|
||||
@ -596,7 +596,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
|
||||
// losing keys is considered a catastrophic error, anything else
|
||||
// we assume the user can live with:
|
||||
if (IsKeyType(strType) || strType == "defaultkey")
|
||||
result = DB_CORRUPT;
|
||||
result = DBErrors::CORRUPT;
|
||||
else
|
||||
{
|
||||
// Leave other errors alone, if we try to fix them we might make things worse.
|
||||
@ -619,15 +619,15 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
|
||||
throw;
|
||||
}
|
||||
catch (...) {
|
||||
result = DB_CORRUPT;
|
||||
result = DBErrors::CORRUPT;
|
||||
}
|
||||
|
||||
if (fNoncriticalErrors && result == DB_LOAD_OK)
|
||||
result = DB_NONCRITICAL_ERROR;
|
||||
if (fNoncriticalErrors && result == DBErrors::LOAD_OK)
|
||||
result = DBErrors::NONCRITICAL_ERROR;
|
||||
|
||||
// Any wallet corruption at all: skip any rewriting or
|
||||
// upgrading, we don't want to make it worse.
|
||||
if (result != DB_LOAD_OK)
|
||||
if (result != DBErrors::LOAD_OK)
|
||||
return result;
|
||||
|
||||
LogPrintf("nFileVersion = %d\n", wss.nFileVersion);
|
||||
@ -645,7 +645,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
|
||||
|
||||
// Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
|
||||
if (wss.fIsEncrypted && (wss.nFileVersion == 40000 || wss.nFileVersion == 50000))
|
||||
return DB_NEED_REWRITE;
|
||||
return DBErrors::NEED_REWRITE;
|
||||
|
||||
if (wss.nFileVersion < CLIENT_VERSION) // Update
|
||||
WriteVersion(CLIENT_VERSION);
|
||||
@ -664,14 +664,14 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
|
||||
|
||||
DBErrors WalletBatch::FindWalletTx(std::vector<uint256>& vTxHash, std::vector<CWalletTx>& vWtx)
|
||||
{
|
||||
DBErrors result = DB_LOAD_OK;
|
||||
DBErrors result = DBErrors::LOAD_OK;
|
||||
|
||||
try {
|
||||
int nMinVersion = 0;
|
||||
if (m_batch.Read((std::string)"minversion", nMinVersion))
|
||||
{
|
||||
if (nMinVersion > CLIENT_VERSION)
|
||||
return DB_TOO_NEW;
|
||||
return DBErrors::TOO_NEW;
|
||||
}
|
||||
|
||||
// Get cursor
|
||||
@ -679,7 +679,7 @@ DBErrors WalletBatch::FindWalletTx(std::vector<uint256>& vTxHash, std::vector<CW
|
||||
if (!pcursor)
|
||||
{
|
||||
LogPrintf("Error getting wallet database cursor\n");
|
||||
return DB_CORRUPT;
|
||||
return DBErrors::CORRUPT;
|
||||
}
|
||||
|
||||
while (true)
|
||||
@ -693,7 +693,7 @@ DBErrors WalletBatch::FindWalletTx(std::vector<uint256>& vTxHash, std::vector<CW
|
||||
else if (ret != 0)
|
||||
{
|
||||
LogPrintf("Error reading next record from wallet database\n");
|
||||
return DB_CORRUPT;
|
||||
return DBErrors::CORRUPT;
|
||||
}
|
||||
|
||||
std::string strType;
|
||||
@ -715,7 +715,7 @@ DBErrors WalletBatch::FindWalletTx(std::vector<uint256>& vTxHash, std::vector<CW
|
||||
throw;
|
||||
}
|
||||
catch (...) {
|
||||
result = DB_CORRUPT;
|
||||
result = DBErrors::CORRUPT;
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -727,7 +727,7 @@ DBErrors WalletBatch::ZapSelectTx(std::vector<uint256>& vTxHashIn, std::vector<u
|
||||
std::vector<uint256> vTxHash;
|
||||
std::vector<CWalletTx> vWtx;
|
||||
DBErrors err = FindWalletTx(vTxHash, vWtx);
|
||||
if (err != DB_LOAD_OK) {
|
||||
if (err != DBErrors::LOAD_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -754,9 +754,9 @@ DBErrors WalletBatch::ZapSelectTx(std::vector<uint256>& vTxHashIn, std::vector<u
|
||||
}
|
||||
|
||||
if (delerror) {
|
||||
return DB_CORRUPT;
|
||||
return DBErrors::CORRUPT;
|
||||
}
|
||||
return DB_LOAD_OK;
|
||||
return DBErrors::LOAD_OK;
|
||||
}
|
||||
|
||||
DBErrors WalletBatch::ZapWalletTx(std::vector<CWalletTx>& vWtx)
|
||||
@ -764,16 +764,16 @@ DBErrors WalletBatch::ZapWalletTx(std::vector<CWalletTx>& vWtx)
|
||||
// build list of wallet TXs
|
||||
std::vector<uint256> vTxHash;
|
||||
DBErrors err = FindWalletTx(vTxHash, vWtx);
|
||||
if (err != DB_LOAD_OK)
|
||||
if (err != DBErrors::LOAD_OK)
|
||||
return err;
|
||||
|
||||
// erase each wallet TX
|
||||
for (uint256& hash : vTxHash) {
|
||||
if (!EraseTx(hash))
|
||||
return DB_CORRUPT;
|
||||
return DBErrors::CORRUPT;
|
||||
}
|
||||
|
||||
return DB_LOAD_OK;
|
||||
return DBErrors::LOAD_OK;
|
||||
}
|
||||
|
||||
void MaybeCompactWalletDB()
|
||||
|
@ -46,14 +46,14 @@ class uint256;
|
||||
using WalletDatabase = BerkeleyDatabase;
|
||||
|
||||
/** Error statuses for the wallet database */
|
||||
enum DBErrors
|
||||
enum class DBErrors
|
||||
{
|
||||
DB_LOAD_OK,
|
||||
DB_CORRUPT,
|
||||
DB_NONCRITICAL_ERROR,
|
||||
DB_TOO_NEW,
|
||||
DB_LOAD_FAIL,
|
||||
DB_NEED_REWRITE
|
||||
LOAD_OK,
|
||||
CORRUPT,
|
||||
NONCRITICAL_ERROR,
|
||||
TOO_NEW,
|
||||
LOAD_FAIL,
|
||||
NEED_REWRITE
|
||||
};
|
||||
|
||||
class CKeyMetadata
|
||||
|
Loading…
Reference in New Issue
Block a user