Skip to content

Commit

Permalink
scripted-diff: Convert 11 enums into scoped enums (C++11)
Browse files Browse the repository at this point in the history
-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 RBFTransactionState/enum class RBFTransactionState/g' src/policy/rbf.h
git grep -l RBF_ | xargs sed -i 's/RBF_TRANSACTIONSTATE_\(UNKNOWN\|REPLACEABLE_BIP125\|FINAL\)/RBFTransactionState::\1/g'
sed -i 's/^    RBFTransactionState::/    /g' src/policy/rbf.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

sed -i 's/enum WitnessMode {/enum class WitnessMode {/g' src/test/script_tests.cpp
sed -i 's/WITNESS_\(NONE\|PKH\|SH\)/WitnessMode::\1/g' src/test/script_tests.cpp
sed -i 's/^    WitnessMode::/    /g' src/test/script_tests.cpp

-END VERIFY SCRIPT-
  • Loading branch information
practicalswift committed Mar 9, 2018
1 parent 29fad97 commit 1f45e21
Show file tree
Hide file tree
Showing 38 changed files with 295 additions and 295 deletions.
2 changes: 1 addition & 1 deletion src/bench/verify_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static void VerifyScriptBench(benchmark::State& state)
CMutableTransaction txSpend = BuildSpendingTransaction(scriptSig, txCredit);
CScriptWitness& witness = txSpend.vin[0].scriptWitness;
witness.stack.emplace_back();
key.Sign(SignatureHash(witScriptPubkey, txSpend, 0, SIGHASH_ALL, txCredit.vout[0].nValue, SIGVERSION_WITNESS_V0), witness.stack.back(), 0);
key.Sign(SignatureHash(witScriptPubkey, txSpend, 0, SIGHASH_ALL, txCredit.vout[0].nValue, SigVersion::WITNESS_V0), witness.stack.back(), 0);
witness.stack.back().push_back(static_cast<unsigned char>(SIGHASH_ALL));
witness.stack.push_back(ToByteVector(pubkey));

Expand Down
2 changes: 1 addition & 1 deletion src/bitcoind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bool AppInit(int argc, char* argv[])
strUsage += "\n" + _("Usage:") + "\n" +
" bitcoind [options] " + strprintf(_("Start %s Daemon"), _(PACKAGE_NAME)) + "\n";

strUsage += "\n" + HelpMessage(HMM_BITCOIND);
strUsage += "\n" + HelpMessage(HelpMessageMode::BITCOIND);
}

fprintf(stdout, "%s", strUsage.c_str());
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ std::string HelpMessage(HelpMessageMode mode)
if (showDebug)
strUsage += HelpMessageOpt("-blocksonly", strprintf(_("Whether to operate in a blocks only mode (default: %u)"), DEFAULT_BLOCKSONLY));
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"));
Expand Down
6 changes: 3 additions & 3 deletions src/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ bool AppInitLockDataDirectory();
bool AppInitMain();

/** 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) */
Expand Down
2 changes: 1 addition & 1 deletion src/policy/fees.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,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
Expand Down
4 changes: 2 additions & 2 deletions src/policy/policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,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;
Expand Down Expand Up @@ -215,7 +215,7 @@ bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
// If the scriptPubKey is P2SH, we try to extract the redeemScript casually by converting the scriptSig
// into a stack. We do not check IsPushOnly nor compare the hash as these will be done later anyway.
// If the check fails at this stage, we know that this txid must be a bad one.
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;
Expand Down
8 changes: 4 additions & 4 deletions src/policy/rbf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ RBFTransactionState IsRBFOptIn(const CTransaction &tx, CTxMemPool &pool)

// First check the transaction itself.
if (SignalsOptInRBF(tx)) {
return RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125;
return RBFTransactionState::REPLACEABLE_BIP125;
}

// If this transaction is not in our mempool, then we can't be sure
// we will know about all its inputs.
if (!pool.exists(tx.GetHash())) {
return RBF_TRANSACTIONSTATE_UNKNOWN;
return RBFTransactionState::UNKNOWN;
}

// If all the inputs have nSequence >= maxint-1, it still might be
Expand All @@ -40,8 +40,8 @@ RBFTransactionState IsRBFOptIn(const CTransaction &tx, CTxMemPool &pool)

for (CTxMemPool::txiter it : setAncestors) {
if (SignalsOptInRBF(it->GetTx())) {
return RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125;
return RBFTransactionState::REPLACEABLE_BIP125;
}
}
return RBF_TRANSACTIONSTATE_FINAL;
return RBFTransactionState::FINAL;
}
8 changes: 4 additions & 4 deletions src/policy/rbf.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

static const uint32_t MAX_BIP125_RBF_SEQUENCE = 0xfffffffd;

enum RBFTransactionState {
RBF_TRANSACTIONSTATE_UNKNOWN,
RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125,
RBF_TRANSACTIONSTATE_FINAL
enum class RBFTransactionState {
UNKNOWN,
REPLACEABLE_BIP125,
FINAL
};

// Check whether the sequence numbers on this transaction are signaling
Expand Down
8 changes: 4 additions & 4 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,25 +780,25 @@ 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;
}
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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,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)
Expand Down
10 changes: 5 additions & 5 deletions src/qt/clientmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,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 {
Expand Down
2 changes: 1 addition & 1 deletion src/qt/utilitydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) :
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) {
Expand Down
54 changes: 27 additions & 27 deletions src/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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";
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,20 +1121,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.pushKV("status", "defined"); break;
case THRESHOLD_STARTED: rv.pushKV("status", "started"); break;
case THRESHOLD_LOCKED_IN: rv.pushKV("status", "locked_in"); break;
case THRESHOLD_ACTIVE: rv.pushKV("status", "active"); break;
case THRESHOLD_FAILED: rv.pushKV("status", "failed"); break;
case ThresholdState::DEFINED: rv.pushKV("status", "defined"); break;
case ThresholdState::STARTED: rv.pushKV("status", "started"); break;
case ThresholdState::LOCKED_IN: rv.pushKV("status", "locked_in"); break;
case ThresholdState::ACTIVE: rv.pushKV("status", "active"); break;
case ThresholdState::FAILED: rv.pushKV("status", "failed"); break;
}
if (THRESHOLD_STARTED == thresholdState)
if (ThresholdState::STARTED == thresholdState)
{
rv.pushKV("bit", consensusParams.vDeployments[id].bit);
}
rv.pushKV("startTime", consensusParams.vDeployments[id].nStartTime);
rv.pushKV("timeout", consensusParams.vDeployments[id].nTimeout);
rv.pushKV("since", VersionBitsTipStateSinceHeight(consensusParams, id));
if (THRESHOLD_STARTED == thresholdState)
if (ThresholdState::STARTED == thresholdState)
{
UniValue statsUV(UniValue::VOBJ);
BIP9Stats statsStruct = VersionBitsTipStatistics(consensusParams, id);
Expand Down
Loading

0 comments on commit 1f45e21

Please sign in to comment.