From 9d80ddb6ac3087fd70774dfdebd8056c4f40cc71 Mon Sep 17 00:00:00 2001 From: Sami Ahmed Date: Fri, 8 May 2026 22:26:31 -0700 Subject: [PATCH] C++20 Round 4: enum class TxnOutType, remove boost string alg, boost::int64_t -> int64_t - txnouttype -> enum class TxnOutType (NonStandard, PubKey, PubKeyHash, ScriptHash, MultiSig) Updated script.h/cpp, main.cpp, wallet.cpp, rpcrawtransaction.cpp, rpcwallet.cpp, multisig_tests.cpp - boost::int64_t/uint64_t -> int64_t/uint64_t across all RPC files (7 files, 52 replacements) - Replace all boost string algorithm includes with std:: equivalents: - Added TrimString(), ToLower(), ReplaceAll(), SplitString(), JoinStrings() to util.h - boost::trim -> TrimString() (bootstrap.cpp, trianglesrpc.cpp, rest.cpp) - boost::to_lower -> ToLower() (netbase.cpp, trianglesrpc.cpp) - boost::split/is_any_of -> SplitString() (rpcdump.cpp, trianglesrpc.cpp, rest.cpp) - boost::replace_all -> ReplaceAll() (main.cpp, wallet.cpp) - boost::algorithm::starts_with/ends_with -> std::string::starts_with/ends_with (rpcdump.cpp, smessage.cpp) - boost::algorithm::istarts_with -> case-insensitive lambda (init.cpp, qtipcserver.cpp) - boost::algorithm::join -> JoinStrings() (util.cpp) - boost::bind -> lambda in trianglesrpc.cpp async_accept handler - IsHex() parameter: const string& -> string_view --- src/bootstrap.cpp | 11 ++-- src/init.cpp | 3 +- src/main.cpp | 21 ++---- src/netbase.cpp | 3 +- src/qt/qtipcserver.cpp | 6 +- src/rest.cpp | 12 ++-- src/rpcblockchain.cpp | 10 +-- src/rpcdump.cpp | 7 +- src/rpcnet.cpp | 16 ++--- src/rpcrawtransaction.cpp | 18 +++--- src/rpcwallet.cpp | 22 +++---- src/script.cpp | 126 ++++++++++++++++-------------------- src/script.h | 21 +++--- src/smessage.cpp | 6 +- src/test/multisig_tests.cpp | 10 +-- src/trianglesrpc.cpp | 62 +++++++++--------- src/util.cpp | 5 +- src/util.h | 50 +++++++++++++- src/wallet.cpp | 24 ++++--- 19 files changed, 224 insertions(+), 209 deletions(-) diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp index d505b3b..0c7bab5 100644 --- a/src/bootstrap.cpp +++ b/src/bootstrap.cpp @@ -7,7 +7,6 @@ #include #include -#include #include @@ -300,7 +299,7 @@ bool DownloadFile(const std::string& host, const std::string& urlPath, location = headerData.substr(valStart, lineEnd - valStart); else location = headerData.substr(valStart); - boost::trim(location); + location = TrimString(location); // Parse redirect URL — supports http://, https://, and relative paths if (location.compare(0, 7, "http://") == 0 || @@ -416,7 +415,7 @@ bool FetchFileList(const std::string& host, files.clear(); std::string line; while (std::getline(in, line)) { - boost::trim(line); + line = TrimString(line); if (!line.empty() && line[0] != '#') files.push_back(line); } @@ -576,7 +575,7 @@ bool ParseManifest(const fs::path& manifestPath, std::string line; while (std::getline(in, line)) { - boost::trim(line); + line = TrimString(line); if (line.empty() || line[0] == '#') continue; @@ -586,8 +585,8 @@ bool ParseManifest(const fs::path& manifestPath, std::string key = line.substr(0, eq); std::string val = line.substr(eq + 1); - boost::trim(key); - boost::trim(val); + key = TrimString(key); + val = TrimString(val); if (key == "format") manifest.format = std::atoi(val.c_str()); diff --git a/src/init.cpp b/src/init.cpp index 371443a..372cbc1 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #ifndef WIN32 @@ -339,7 +338,7 @@ bool AppInit(int argc, char* argv[]) // Command-line RPC for (int i = 1; i < argc; i++) - if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "Triangles:")) + if (!IsSwitchChar(argv[i][0]) && !std::equal(std::begin("Triangles:"), std::end("Triangles:") - 1, argv[i], [](char a, char b) { return std::tolower(static_cast(a)) == std::tolower(static_cast(b)); })) fCommandLine = true; if (fCommandLine) diff --git a/src/main.cpp b/src/main.cpp index af20602..efa4cb6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -984,8 +983,7 @@ bool CTransaction::AreInputsStandard(const MapPrevTx& mapInputs) const const CUtxoEntry& entry = mi->second; vector > vSolutions; - txnouttype whichType; - // get the scriptPubKey corresponding to this input: + TxnOutType whichType; const CScript& prevScript = entry.scriptPubKey; if (!Solver(prevScript, whichType, vSolutions)) return false; @@ -993,25 +991,20 @@ bool CTransaction::AreInputsStandard(const MapPrevTx& mapInputs) const if (nArgsExpected < 0) return false; - // Transactions with extra stuff in their scriptSigs are - // non-standard. Note that this EvalScript() call will - // be quick, because if there are any operations - // beside "push data" in the scriptSig the - // IsStandard() call returns false vector > stack; if (!EvalScript(stack, vin[i].scriptSig, *this, i, 0)) return false; - if (whichType == TX_SCRIPTHASH) + if (whichType == TxnOutType::ScriptHash) { if (stack.empty()) return false; CScript subscript(stack.back().begin(), stack.back().end()); vector > vSolutions2; - txnouttype whichType2; + TxnOutType whichType2; if (!Solver(subscript, whichType2, vSolutions2)) return false; - if (whichType2 == TX_SCRIPTHASH) + if (whichType2 == TxnOutType::ScriptHash) return false; int tmpExpected; @@ -3048,7 +3041,7 @@ bool CBlock::SetBestChain(CTxDBBase& txdb, CBlockIndex* pindexNew) if (!fIsInitialDownload && !strCmd.empty()) { - boost::replace_all(strCmd, "%s", hashBestChain.GetHex()); + ReplaceAll(strCmd, "%s", hashBestChain.GetHex()); std::thread(runCommand, strCmd).detach(); // thread runs free } @@ -3795,14 +3788,14 @@ bool CBlock::CheckBlockSignature() const return vchBlockSig.empty(); vector vSolutions; - txnouttype whichType; + TxnOutType whichType; const CTxOut& txout = vtx[1].vout[1]; if (!Solver(txout.scriptPubKey, whichType, vSolutions)) return false; - if (whichType == TX_PUBKEY) + if (whichType == TxnOutType::PubKey) { valtype& vchPubKey = vSolutions[0]; CKey key; diff --git a/src/netbase.cpp b/src/netbase.cpp index 82e11db..216fd4e 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -13,7 +13,6 @@ #endif #include "strlcpy.h" -#include // for to_lower() using namespace std; @@ -27,7 +26,7 @@ bool fNameLookup = false; static const unsigned char pchIPv4[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff }; enum Network ParseNetwork(std::string net) { - boost::to_lower(net); + net = ToLower(net); if (net == "ipv4") return NET_IPV4; if (net == "ipv6") return NET_IPV6; if (net == "tor") return NET_TOR; diff --git a/src/qt/qtipcserver.cpp b/src/qt/qtipcserver.cpp index 39acff2..16adc30 100644 --- a/src/qt/qtipcserver.cpp +++ b/src/qt/qtipcserver.cpp @@ -13,7 +13,6 @@ #include "ui_interface.h" #include "util.h" -#include #include #include #include @@ -26,6 +25,9 @@ using namespace boost; using namespace boost::interprocess; using namespace boost::posix_time; +#include +#include + #if defined MAC_OSX || defined __FreeBSD__ // URI handling not implemented on OSX yet @@ -42,7 +44,7 @@ static bool ipcScanCmd(int argc, char *argv[], bool fRelay) bool fSent = false; for (int i = 1; i < argc; i++) { - if (boost::algorithm::istarts_with(argv[i], "Triangles:")) + if (std::equal(std::begin("Triangles:"), std::end("Triangles:") - 1, argv[i], [](char a, char b) { return std::tolower(static_cast(a)) == std::tolower(static_cast(b)); })) { const char *strURI = argv[i]; try { diff --git a/src/rest.cpp b/src/rest.cpp index 0217b6d..0470189 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -12,8 +12,6 @@ #include "wallet.h" #include "init.h" -#include - using namespace std; using namespace json_spirit; @@ -149,12 +147,12 @@ static void ParseRESTPath(const string& strURI, vector& parts, map pairs; - boost::split(pairs, queryString, boost::is_any_of("&")); + auto pairs = SplitString(queryString, '&'); for (size_t i = 0; i < pairs.size(); i++) { size_t eq = pairs[i].find('='); if (eq != string::npos) @@ -180,7 +178,7 @@ static bool RESTAuthorized(map& mapHeaders) string strAuth = mapHeaders.count("authorization") ? mapHeaders["authorization"] : ""; if (strAuth.substr(0, 7) == "Bearer ") { string strToken = strAuth.substr(7); - boost::trim(strToken); + strToken = TrimString(strToken); if (TimingResistantEqual(strToken, strApiKey)) return true; } @@ -300,8 +298,8 @@ static bool HandleBlockHeader(const string& param, string& strReply, int& nStatu result.push_back(Pair("height", pblockindex->nHeight)); result.push_back(Pair("version", pblockindex->nVersion)); result.push_back(Pair("merkleroot", pblockindex->hashMerkleRoot.GetHex())); - result.push_back(Pair("time", (boost::int64_t)pblockindex->GetBlockTime())); - result.push_back(Pair("nonce", (boost::uint64_t)pblockindex->nNonce)); + result.push_back(Pair("time", (int64_t)pblockindex->GetBlockTime())); + result.push_back(Pair("nonce", (uint64_t)pblockindex->nNonce)); result.push_back(Pair("bits", HexBits(pblockindex->nBits))); result.push_back(Pair("difficulty", GetDifficulty(pblockindex))); result.push_back(Pair("flags", strprintf("%s%s", diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 950299e..9d93dce 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -128,8 +128,8 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool fPri result.push_back(Pair("version", block.nVersion)); result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex())); result.push_back(Pair("mint", ValueFromAmount(blockindex->nMint))); - result.push_back(Pair("time", (boost::int64_t)block.GetBlockTime())); - result.push_back(Pair("nonce", (boost::uint64_t)block.nNonce)); + result.push_back(Pair("time", (int64_t)block.GetBlockTime())); + result.push_back(Pair("nonce", (uint64_t)block.nNonce)); result.push_back(Pair("bits", HexBits(block.nBits))); result.push_back(Pair("difficulty", GetDifficulty(blockindex))); result.push_back(Pair("blocktrust", leftTrim(blockindex->GetBlockTrust().GetHex(), '0'))); @@ -330,8 +330,8 @@ Value getblockheader(const Array& params, bool fHelp) result.push_back(Pair("version", pblockindex->nVersion)); result.push_back(Pair("merkleroot", pblockindex->hashMerkleRoot.GetHex())); result.push_back(Pair("mint", ValueFromAmount(pblockindex->nMint))); - result.push_back(Pair("time", (boost::int64_t)pblockindex->GetBlockTime())); - result.push_back(Pair("nonce", (boost::uint64_t)pblockindex->nNonce)); + result.push_back(Pair("time", (int64_t)pblockindex->GetBlockTime())); + result.push_back(Pair("nonce", (uint64_t)pblockindex->nNonce)); result.push_back(Pair("bits", HexBits(pblockindex->nBits))); result.push_back(Pair("difficulty", GetDifficulty(pblockindex))); result.push_back(Pair("blocktrust", leftTrim(pblockindex->GetBlockTrust().GetHex(), '0'))); @@ -708,7 +708,7 @@ Value getblockchaininfo(const Array& params, bool fHelp) obj.push_back(Pair("difficulty", diff)); obj.push_back(Pair("moneysupply", ValueFromAmount(pindexBest->nMoneySupply))); - obj.push_back(Pair("timeoffset", (boost::int64_t)GetTimeOffset())); + obj.push_back(Pair("timeoffset", (int64_t)GetTimeOffset())); obj.push_back(Pair("connections", (int)vNodes.size())); obj.push_back(Pair("errors", GetWarnings("statusbar"))); return obj; diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp index d686d17..b1c1d77 100644 --- a/src/rpcdump.cpp +++ b/src/rpcdump.cpp @@ -11,7 +11,6 @@ #include "base58.h" #include -#include #define printf OutputDebugStringF @@ -168,7 +167,7 @@ Value importwallet(const Array& params, bool fHelp) continue; std::vector vstr; - boost::split(vstr, line, boost::is_any_of(" ")); + auto vstr = SplitString(line, ' '); if (vstr.size() < 2) continue; CTrianglesSecret vchSecret; @@ -189,13 +188,13 @@ Value importwallet(const Array& params, bool fHelp) std::string strLabel; bool fLabel = true; for (unsigned int nStr = 2; nStr < vstr.size(); nStr++) { - if (boost::algorithm::starts_with(vstr[nStr], "#")) + if (vstr[nStr].starts_with("#")) break; if (vstr[nStr] == "change=1") fLabel = false; if (vstr[nStr] == "reserve=1") fLabel = false; - if (boost::algorithm::starts_with(vstr[nStr], "label=")) { + if (vstr[nStr].starts_with("label=")) { strLabel = DecodeDumpString(vstr[nStr].substr(6)); fLabel = true; } diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 986ad9e..3d70e85 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -31,7 +31,7 @@ Value getnetworkinfo(const Array& params, bool fHelp) healthObj.push_back(Pair("torpeers", health.torPeers)); healthObj.push_back(Pair("bootstrapped", health.isBootstrapped)); healthObj.push_back(Pair("syncing", health.isSyncing)); - healthObj.push_back(Pair("lastblocktime", static_cast(health.lastBlockTime))); + healthObj.push_back(Pair("lastblocktime", static_cast(health.lastBlockTime))); healthObj.push_back(Pair("networkmode", "tor_native")); Object obj; @@ -88,9 +88,9 @@ Value getpeerinfo(const Array& params, bool fHelp) obj.push_back(Pair("addr", stats.addrName)); obj.push_back(Pair("services", strprintf("%08"PRIx64, stats.nServices))); - obj.push_back(Pair("lastsend", (boost::int64_t)stats.nLastSend)); - obj.push_back(Pair("lastrecv", (boost::int64_t)stats.nLastRecv)); - obj.push_back(Pair("conntime", (boost::int64_t)stats.nTimeConnected)); + obj.push_back(Pair("lastsend", (int64_t)stats.nLastSend)); + obj.push_back(Pair("lastrecv", (int64_t)stats.nLastRecv)); + obj.push_back(Pair("conntime", (int64_t)stats.nTimeConnected)); obj.push_back(Pair("version", stats.nVersion)); obj.push_back(Pair("subver", stats.strSubVer)); obj.push_back(Pair("inbound", stats.fInbound)); @@ -195,7 +195,7 @@ Value getseedlist(const Array& params, bool fHelp) Object obj; obj.push_back(Pair("address", addr.ToStringIP())); obj.push_back(Pair("port", (int)addr.GetPort())); - obj.push_back(Pair("lastseen", (boost::int64_t)addr.nTime)); + obj.push_back(Pair("lastseen", (int64_t)addr.nTime)); ret.push_back(obj); } @@ -274,11 +274,11 @@ Value getnetworkstability(const Array& params, bool fHelp) obj.push_back(Pair("ping", pingObj)); Object uptimeObj; - uptimeObj.push_back(Pair("newest_sec", nTotal > 0 ? (boost::int64_t)nNewestConnection : 0)); - uptimeObj.push_back(Pair("oldest_sec", nTotal > 0 ? (boost::int64_t)nOldestConnection : 0)); + uptimeObj.push_back(Pair("newest_sec", nTotal > 0 ? (int64_t)nNewestConnection : 0)); + uptimeObj.push_back(Pair("oldest_sec", nTotal > 0 ? (int64_t)nOldestConnection : 0)); obj.push_back(Pair("connection_uptime", uptimeObj)); - obj.push_back(Pair("seconds_since_last_block", (boost::int64_t)(GetTime() - nTimeBestReceived))); + obj.push_back(Pair("seconds_since_last_block", (int64_t)(GetTime() - nTimeBestReceived))); obj.push_back(Pair("current_height", nBestHeight)); return obj; diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index b827c0a..40df03b 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -17,7 +17,7 @@ using namespace json_spirit; void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out, bool fIncludeHex) { - txnouttype type; + TxnOutType type; vector addresses; int nRequired; @@ -28,7 +28,7 @@ void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out, bool fIncludeH if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) { - out.push_back(Pair("type", GetTxnOutputType(TX_NONSTANDARD))); + out.push_back(Pair("type", GetTxnOutputType(TxnOutType::NonStandard))); return; } @@ -45,8 +45,8 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) { entry.push_back(Pair("txid", tx.GetHash().GetHex())); entry.push_back(Pair("version", tx.nVersion)); - entry.push_back(Pair("time", (boost::int64_t)tx.nTime)); - entry.push_back(Pair("locktime", (boost::int64_t)tx.nLockTime)); + entry.push_back(Pair("time", (int64_t)tx.nTime)); + entry.push_back(Pair("locktime", (int64_t)tx.nLockTime)); Array vin; for (const CTxIn& txin : tx.vin) { @@ -56,13 +56,13 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) else { in.push_back(Pair("txid", txin.prevout.hash.GetHex())); - in.push_back(Pair("vout", (boost::int64_t)txin.prevout.n)); + in.push_back(Pair("vout", (int64_t)txin.prevout.n)); Object o; o.push_back(Pair("asm", txin.scriptSig.ToString())); o.push_back(Pair("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); in.push_back(Pair("scriptSig", o)); } - in.push_back(Pair("sequence", (boost::int64_t)txin.nSequence)); + in.push_back(Pair("sequence", (int64_t)txin.nSequence)); vin.push_back(in); } entry.push_back(Pair("vin", vin)); @@ -72,7 +72,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) const CTxOut& txout = tx.vout[i]; Object out; out.push_back(Pair("value", ValueFromAmount(txout.nValue))); - out.push_back(Pair("n", (boost::int64_t)i)); + out.push_back(Pair("n", (int64_t)i)); Object o; ScriptPubKeyToJSON(txout.scriptPubKey, o, false); out.push_back(Pair("scriptPubKey", o)); @@ -90,8 +90,8 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) if (pindex->IsInMainChain()) { entry.push_back(Pair("confirmations", 1 + nBestHeight - pindex->nHeight)); - entry.push_back(Pair("time", (boost::int64_t)pindex->nTime)); - entry.push_back(Pair("blocktime", (boost::int64_t)pindex->nTime)); + entry.push_back(Pair("time", (int64_t)pindex->nTime)); + entry.push_back(Pair("blocktime", (int64_t)pindex->nTime)); } else entry.push_back(Pair("confirmations", 0)); diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index bfda2be..3045bc9 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -59,11 +59,11 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry) entry.push_back(Pair("blockindex", wtx.nIndex)); auto mi = mapBlockIndex.find(wtx.hashBlock); if (mi != mapBlockIndex.end() && mi->second) - entry.push_back(Pair("blocktime", (boost::int64_t)(mi->second->nTime))); + entry.push_back(Pair("blocktime", (int64_t)(mi->second->nTime))); } entry.push_back(Pair("txid", wtx.GetHash().GetHex())); - entry.push_back(Pair("time", (boost::int64_t)wtx.GetTxTime())); - entry.push_back(Pair("timereceived", (boost::int64_t)wtx.nTimeReceived)); + entry.push_back(Pair("time", (int64_t)wtx.GetTxTime())); + entry.push_back(Pair("timereceived", (int64_t)wtx.nTimeReceived)); for (const auto& item : wtx.mapValue) entry.push_back(Pair(item.first, item.second)); } @@ -94,7 +94,7 @@ Value getinfo(const Array& params, bool fHelp) obj.push_back(Pair("newmint", ValueFromAmount(pwalletMain->GetNewMint()))); obj.push_back(Pair("stake", ValueFromAmount(pwalletMain->GetStake()))); obj.push_back(Pair("blocks", (int)nBestHeight)); - obj.push_back(Pair("timeoffset", (boost::int64_t)GetTimeOffset())); + obj.push_back(Pair("timeoffset", (int64_t)GetTimeOffset())); obj.push_back(Pair("moneysupply", ValueFromAmount(pindexBest->nMoneySupply))); obj.push_back(Pair("connections", (int)vNodes.size())); obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string()))); @@ -105,14 +105,14 @@ Value getinfo(const Array& params, bool fHelp) obj.push_back(Pair("difficulty", diff)); obj.push_back(Pair("testnet", fTestNet)); - obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime())); + obj.push_back(Pair("keypoololdest", (int64_t)pwalletMain->GetOldestKeyPoolTime())); obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize())); obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee))); obj.push_back(Pair("mininput", ValueFromAmount(nMinimumInputValue))); if (pwalletMain->IsCrypted()) { LOCK(cs_nWalletUnlockTime); - obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime / 1000)); + obj.push_back(Pair("unlocked_until", (int64_t)nWalletUnlockTime / 1000)); } obj.push_back(Pair("errors", GetWarnings("statusbar"))); return obj; @@ -139,14 +139,14 @@ Value getwalletinfo(const Array& params, bool fHelp) obj.push_back(Pair("stake", ValueFromAmount(pwalletMain->GetStake()))); obj.push_back(Pair("newmint", ValueFromAmount(pwalletMain->GetNewMint()))); obj.push_back(Pair("txcount", txCount)); - obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime())); + obj.push_back(Pair("keypoololdest", (int64_t)pwalletMain->GetOldestKeyPoolTime())); obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize())); obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee))); obj.push_back(Pair("mininput", ValueFromAmount(nMinimumInputValue))); if (pwalletMain->IsCrypted()) { LOCK(cs_nWalletUnlockTime); - obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime / 1000)); + obj.push_back(Pair("unlocked_until", (int64_t)nWalletUnlockTime / 1000)); } return obj; } @@ -1151,7 +1151,7 @@ void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, Ar Object entry; entry.push_back(Pair("account", acentry.strAccount)); entry.push_back(Pair("category", "move")); - entry.push_back(Pair("time", (boost::int64_t)acentry.nTime)); + entry.push_back(Pair("time", (int64_t)acentry.nTime)); entry.push_back(Pair("amount", ValueFromAmount(acentry.nCreditDebit))); entry.push_back(Pair("otheraccount", acentry.strOtherAccount)); entry.push_back(Pair("comment", acentry.strComment)); @@ -1654,7 +1654,7 @@ public: CScript subscript; pwalletMain->GetCScript(scriptID, subscript); std::vector addresses; - txnouttype whichType; + TxnOutType whichType; int nRequired; ExtractDestinations(subscript, whichType, addresses, nRequired); obj.push_back(Pair("script", GetTxnOutputType(whichType))); @@ -1663,7 +1663,7 @@ public: for (const CTxDestination& addr : addresses) a.push_back(CTrianglesAddress(addr).ToString()); obj.push_back(Pair("addresses", a)); - if (whichType == TX_MULTISIG) + if (whichType == TxnOutType::MultiSig) obj.push_back(Pair("sigsrequired", nRequired)); return obj; } diff --git a/src/script.cpp b/src/script.cpp index 9123031..8797511 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -93,15 +93,15 @@ static inline void popstack(vector& stack) } -const char* GetTxnOutputType(txnouttype t) +const char* GetTxnOutputType(TxnOutType t) { switch (t) { - case TX_NONSTANDARD: return "nonstandard"; - case TX_PUBKEY: return "pubkey"; - case TX_PUBKEYHASH: return "pubkeyhash"; - case TX_SCRIPTHASH: return "scripthash"; - case TX_MULTISIG: return "multisig"; + case TxnOutType::NonStandard: return "nonstandard"; + case TxnOutType::PubKey: return "pubkey"; + case TxnOutType::PubKeyHash: return "pubkeyhash"; + case TxnOutType::ScriptHash: return "scripthash"; + case TxnOutType::MultiSig: return "multisig"; } return nullptr; } @@ -1312,27 +1312,21 @@ bool CheckSig(const vector& vchSig, const vector& // // Return public keys or hashes from scriptPubKey, for 'standard' transaction types. // -bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector >& vSolutionsRet) +bool Solver(const CScript& scriptPubKey, TxnOutType& typeRet, vector >& vSolutionsRet) { - // Templates - static map mTemplates; + static map mTemplates; if (mTemplates.empty()) { - // Standard tx, sender provides pubkey, receiver adds signature - mTemplates.insert(make_pair(TX_PUBKEY, CScript() << OP_PUBKEY << OP_CHECKSIG)); - - // Triangles address tx, sender provides hash of pubkey, receiver provides signature and pubkey - mTemplates.insert(make_pair(TX_PUBKEYHASH, CScript() << OP_DUP << OP_HASH160 << OP_PUBKEYHASH << OP_EQUALVERIFY << OP_CHECKSIG)); - - // Sender provides N pubkeys, receivers provides M signatures - mTemplates.insert(make_pair(TX_MULTISIG, CScript() << OP_SMALLINTEGER << OP_PUBKEYS << OP_SMALLINTEGER << OP_CHECKMULTISIG)); + mTemplates.insert(make_pair(TxnOutType::PubKey, CScript() << OP_PUBKEY << OP_CHECKSIG)); + mTemplates.insert(make_pair(TxnOutType::PubKeyHash, CScript() << OP_DUP << OP_HASH160 << OP_PUBKEYHASH << OP_EQUALVERIFY << OP_CHECKSIG)); + mTemplates.insert(make_pair(TxnOutType::MultiSig, CScript() << OP_SMALLINTEGER << OP_PUBKEYS << OP_SMALLINTEGER << OP_CHECKMULTISIG)); } // Shortcut for pay-to-script-hash, which are more constrained than the other types: // it is always OP_HASH160 20 [20 byte hash] OP_EQUAL if (scriptPubKey.IsPayToScriptHash()) { - typeRet = TX_SCRIPTHASH; + typeRet = TxnOutType::ScriptHash; vector hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22); vSolutionsRet.push_back(hashBytes); return true; @@ -1357,7 +1351,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector& multisigdata, const CKeyStore& keystore, uint2 // Returns false if scriptPubKey could not be completely satisfied. // bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash, int nHashType, - CScript& scriptSigRet, txnouttype& whichTypeRet) + CScript& scriptSigRet, TxnOutType& whichTypeRet) { scriptSigRet.clear(); @@ -1471,12 +1465,12 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash CKeyID keyID; switch (whichTypeRet) { - case TX_NONSTANDARD: + case TxnOutType::NonStandard: return false; - case TX_PUBKEY: + case TxnOutType::PubKey: keyID = CPubKey(vSolutions[0]).GetID(); return Sign1(keyID, keystore, hash, nHashType, scriptSigRet); - case TX_PUBKEYHASH: + case TxnOutType::PubKeyHash: keyID = CKeyID(uint160(vSolutions[0])); if (!Sign1(keyID, keystore, hash, nHashType, scriptSigRet)) return false; @@ -1487,32 +1481,32 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash scriptSigRet << vch; } return true; - case TX_SCRIPTHASH: + case TxnOutType::ScriptHash: return keystore.GetCScript(uint160(vSolutions[0]), scriptSigRet); - case TX_MULTISIG: - scriptSigRet << OP_0; // workaround CHECKMULTISIG bug + case TxnOutType::MultiSig: + scriptSigRet << OP_0; return (SignN(vSolutions, keystore, hash, nHashType, scriptSigRet)); } return false; } -int ScriptSigArgsExpected(txnouttype t, const std::vector >& vSolutions) +int ScriptSigArgsExpected(TxnOutType t, const std::vector >& vSolutions) { switch (t) { - case TX_NONSTANDARD: + case TxnOutType::NonStandard: return -1; - case TX_PUBKEY: + case TxnOutType::PubKey: return 1; - case TX_PUBKEYHASH: + case TxnOutType::PubKeyHash: return 2; - case TX_MULTISIG: + case TxnOutType::MultiSig: if (vSolutions.size() < 1 || vSolutions[0].size() < 1) return -1; return vSolutions[0][0] + 1; - case TX_SCRIPTHASH: - return 1; // doesn't include args needed by the script + case TxnOutType::ScriptHash: + return 1; } return -1; } @@ -1520,11 +1514,11 @@ int ScriptSigArgsExpected(txnouttype t, const std::vector vSolutions; - txnouttype whichType; + TxnOutType whichType; if (!Solver(scriptPubKey, whichType, vSolutions)) return false; - if (whichType == TX_MULTISIG) + if (whichType == TxnOutType::MultiSig) { unsigned char m = vSolutions.front()[0]; unsigned char n = vSolutions.back()[0]; @@ -1535,7 +1529,7 @@ bool IsStandard(const CScript& scriptPubKey) return false; } - return whichType != TX_NONSTANDARD; + return whichType != TxnOutType::NonStandard; } @@ -1571,29 +1565,29 @@ bool IsMine(const CKeyStore &keystore, const CTxDestination &dest) bool IsMine(const CKeyStore &keystore, const CScript& scriptPubKey) { vector vSolutions; - txnouttype whichType; + TxnOutType whichType; if (!Solver(scriptPubKey, whichType, vSolutions)) return false; CKeyID keyID; switch (whichType) { - case TX_NONSTANDARD: + case TxnOutType::NonStandard: return false; - case TX_PUBKEY: + case TxnOutType::PubKey: keyID = CPubKey(vSolutions[0]).GetID(); return keystore.HaveKey(keyID); - case TX_PUBKEYHASH: + case TxnOutType::PubKeyHash: keyID = CKeyID(uint160(vSolutions[0])); return keystore.HaveKey(keyID); - case TX_SCRIPTHASH: + case TxnOutType::ScriptHash: { CScript subscript; if (!keystore.GetCScript(CScriptID(uint160(vSolutions[0])), subscript)) return false; return IsMine(keystore, subscript); } - case TX_MULTISIG: + case TxnOutType::MultiSig: { // Only consider transactions "mine" if we own ALL the // keys involved. multi-signature transactions that are @@ -1610,21 +1604,21 @@ bool IsMine(const CKeyStore &keystore, const CScript& scriptPubKey) bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet) { vector vSolutions; - txnouttype whichType; + TxnOutType whichType; if (!Solver(scriptPubKey, whichType, vSolutions)) return false; - if (whichType == TX_PUBKEY) + if (whichType == TxnOutType::PubKey) { addressRet = CPubKey(vSolutions[0]).GetID(); return true; } - else if (whichType == TX_PUBKEYHASH) + else if (whichType == TxnOutType::PubKeyHash) { addressRet = CKeyID(uint160(vSolutions[0])); return true; } - else if (whichType == TX_SCRIPTHASH) + else if (whichType == TxnOutType::ScriptHash) { addressRet = CScriptID(uint160(vSolutions[0])); return true; @@ -1642,7 +1636,7 @@ public: CAffectedKeysVisitor(const CKeyStore &keystoreIn, std::vector &vKeysIn) : keystore(keystoreIn), vKeys(vKeysIn) {} void Process(const CScript &script) { - txnouttype type; + TxnOutType type; std::vector vDest; int nRequired; if (ExtractDestinations(script, type, vDest, nRequired)) { @@ -1671,15 +1665,15 @@ void ExtractAffectedKeys(const CKeyStore &keystore, const CScript& scriptPubKey, CAffectedKeysVisitor(keystore, vKeys).Process(scriptPubKey); } -bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, vector& addressRet, int& nRequiredRet) +bool ExtractDestinations(const CScript& scriptPubKey, TxnOutType& typeRet, vector& addressRet, int& nRequiredRet) { addressRet.clear(); - typeRet = TX_NONSTANDARD; + typeRet = TxnOutType::NonStandard; vector vSolutions; if (!Solver(scriptPubKey, typeRet, vSolutions)) return false; - if (typeRet == TX_MULTISIG) + if (typeRet == TxnOutType::MultiSig) { nRequiredRet = vSolutions.front()[0]; for (unsigned int i = 1; i < vSolutions.size()-1; i++) @@ -1747,23 +1741,19 @@ bool SignSignature(const CKeyStore &keystore, const CScript& fromPubKey, CTransa // The checksig op will also drop the signatures from its hash. uint256 hash = SignatureHash(fromPubKey, txTo, nIn, nHashType); - txnouttype whichType; + TxnOutType whichType; if (!Solver(keystore, fromPubKey, hash, nHashType, txin.scriptSig, whichType)) return false; - if (whichType == TX_SCRIPTHASH) + if (whichType == TxnOutType::ScriptHash) { - // Solver returns the subscript that need to be evaluated; - // the final scriptSig is the signatures from that - // and then the serialized subscript: CScript subscript = txin.scriptSig; - // Recompute txn hash using subscript in place of scriptPubKey: uint256 hash2 = SignatureHash(subscript, txTo, nIn, nHashType); - txnouttype subType; + TxnOutType subType; bool fSolved = - Solver(keystore, subscript, hash2, nHashType, txin.scriptSig, subType) && subType != TX_SCRIPTHASH; + Solver(keystore, subscript, hash2, nHashType, txin.scriptSig, subType) && subType != TxnOutType::ScriptHash; // Append serialized subscript whether or not it is completely signed: txin.scriptSig << static_cast(subscript); if (!fSolved) return false; @@ -1862,23 +1852,21 @@ static CScript CombineMultisig(CScript scriptPubKey, const CTransaction& txTo, u } static CScript CombineSignatures(CScript scriptPubKey, const CTransaction& txTo, unsigned int nIn, - const txnouttype txType, const vector& vSolutions, + const TxnOutType txType, const vector& vSolutions, vector& sigs1, vector& sigs2) { switch (txType) { - case TX_NONSTANDARD: - // Don't know anything about this, assume bigger one is correct: + case TxnOutType::NonStandard: if (sigs1.size() >= sigs2.size()) return PushAll(sigs1); return PushAll(sigs2); - case TX_PUBKEY: - case TX_PUBKEYHASH: - // Signatures are bigger than placeholders or empty scripts: + case TxnOutType::PubKey: + case TxnOutType::PubKeyHash: if (sigs1.empty() || sigs1[0].empty()) return PushAll(sigs2); return PushAll(sigs1); - case TX_SCRIPTHASH: + case TxnOutType::ScriptHash: if (sigs1.empty() || sigs1.back().empty()) return PushAll(sigs2); else if (sigs2.empty() || sigs2.back().empty()) @@ -1889,7 +1877,7 @@ static CScript CombineSignatures(CScript scriptPubKey, const CTransaction& txTo, valtype spk = sigs1.back(); CScript pubKey2(spk.begin(), spk.end()); - txnouttype txType2; + TxnOutType txType2; vector > vSolutions2; Solver(pubKey2, txType2, vSolutions2); sigs1.pop_back(); @@ -1898,7 +1886,7 @@ static CScript CombineSignatures(CScript scriptPubKey, const CTransaction& txTo, result << spk; return result; } - case TX_MULTISIG: + case TxnOutType::MultiSig: return CombineMultisig(scriptPubKey, txTo, nIn, vSolutions, sigs1, sigs2); } @@ -1908,7 +1896,7 @@ static CScript CombineSignatures(CScript scriptPubKey, const CTransaction& txTo, CScript CombineSignatures(CScript scriptPubKey, const CTransaction& txTo, unsigned int nIn, const CScript& scriptSig1, const CScript& scriptSig2) { - txnouttype txType; + TxnOutType txType; vector > vSolutions; Solver(scriptPubKey, txType, vSolutions); diff --git a/src/script.h b/src/script.h index dd46a21..b6f6069 100644 --- a/src/script.h +++ b/src/script.h @@ -30,14 +30,13 @@ enum }; -enum txnouttype +enum class TxnOutType { - TX_NONSTANDARD, - // 'standard' transaction types: - TX_PUBKEY, - TX_PUBKEYHASH, - TX_SCRIPTHASH, - TX_MULTISIG, + NonStandard, + PubKey, + PubKeyHash, + ScriptHash, + MultiSig, }; class CNoDestination { @@ -54,7 +53,7 @@ public: */ typedef std::variant CTxDestination; -const char* GetTxnOutputType(txnouttype t); +const char* GetTxnOutputType(TxnOutType t); /** Script opcodes */ enum opcodetype @@ -590,14 +589,14 @@ public: bool EvalScript(std::vector >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, int nHashType); -bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector >& vSolutionsRet); -int ScriptSigArgsExpected(txnouttype t, const std::vector >& vSolutions); +bool Solver(const CScript& scriptPubKey, TxnOutType& typeRet, std::vector >& vSolutionsRet); +int ScriptSigArgsExpected(TxnOutType t, const std::vector >& vSolutions); bool IsStandard(const CScript& scriptPubKey); bool IsMine(const CKeyStore& keystore, const CScript& scriptPubKey); bool IsMine(const CKeyStore& keystore, const CTxDestination &dest); void ExtractAffectedKeys(const CKeyStore &keystore, const CScript& scriptPubKey, std::vector &vKeys); bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet); -bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector& addressRet, int& nRequiredRet); +bool ExtractDestinations(const CScript& scriptPubKey, TxnOutType& typeRet, std::vector& addressRet, int& nRequiredRet); bool SignSignature(const CKeyStore& keystore, const CScript& fromPubKey, CTransaction& txTo, unsigned int nIn, int nHashType=SIGHASH_ALL); bool SignSignature(const CKeyStore& keystore, const CTransaction& txFrom, CTransaction& txTo, unsigned int nIn, int nHashType=SIGHASH_ALL); bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CTransaction& txTo, unsigned int nIn, diff --git a/src/smessage.cpp b/src/smessage.cpp index bd27cf0..ee3592e 100644 --- a/src/smessage.cpp +++ b/src/smessage.cpp @@ -47,8 +47,6 @@ Notes: #include #include -#include - #include "base58.h" #include "crypto_ecdh.h" @@ -292,12 +290,12 @@ bool SecureMsgAllDigits(const std::string& value) bool SecureMsgParseBucketFilename(const std::string& fileName, int64_t& bucket, uint32_t& fileIndex, bool& fWalletLocked) { - if (!boost::algorithm::ends_with(fileName, ".dat")) + if (!fileName.ends_with(".dat")) return false; std::string baseName = fileName.substr(0, fileName.size() - 4); fWalletLocked = false; - if (boost::algorithm::ends_with(baseName, "_wl")) + if (baseName.ends_with("_wl")) { fWalletLocked = true; baseName.erase(baseName.size() - 3); diff --git a/src/test/multisig_tests.cpp b/src/test/multisig_tests.cpp index be541ec..58ca9d5 100644 --- a/src/test/multisig_tests.cpp +++ b/src/test/multisig_tests.cpp @@ -181,7 +181,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1) { vector solutions; - txnouttype whichType; + TxnOutType whichType; CScript s; s << key[0].GetPubKey() << OP_CHECKSIG; BOOST_CHECK(Solver(s, whichType, solutions)); @@ -194,7 +194,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1) } { vector solutions; - txnouttype whichType; + TxnOutType whichType; CScript s; s << OP_DUP << OP_HASH160 << key[0].GetPubKey().GetID() << OP_EQUALVERIFY << OP_CHECKSIG; BOOST_CHECK(Solver(s, whichType, solutions)); @@ -207,7 +207,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1) } { vector solutions; - txnouttype whichType; + TxnOutType whichType; CScript s; s << OP_2 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG; BOOST_CHECK(Solver(s, whichType, solutions)); @@ -220,7 +220,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1) } { vector solutions; - txnouttype whichType; + TxnOutType whichType; CScript s; s << OP_1 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG; BOOST_CHECK(Solver(s, whichType, solutions)); @@ -237,7 +237,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1) } { vector solutions; - txnouttype whichType; + TxnOutType whichType; CScript s; s << OP_2 << key[0].GetPubKey() << key[1].GetPubKey() << key[2].GetPubKey() << OP_3 << OP_CHECKMULTISIG; BOOST_CHECK(Solver(s, whichType, solutions)); diff --git a/src/trianglesrpc.cpp b/src/trianglesrpc.cpp index b440ac1..0729523 100644 --- a/src/trianglesrpc.cpp +++ b/src/trianglesrpc.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -461,7 +460,7 @@ int ReadHTTPStatus(std::basic_istream& stream, int &proto, if (!str.empty() && str[str.size()-1] == '\r') str.resize(str.size()-1); vector vWords; - boost::split(vWords, str, boost::is_any_of(" ")); + auto vWords = SplitString(str, ' '); if (vWords.size() < 2) return HTTP_INTERNAL_SERVER_ERROR; proto = 0; @@ -493,10 +492,10 @@ int ReadHTTPHeader(std::basic_istream& stream, map& mapHea if (nColon != string::npos) { string strHeader = str.substr(0, nColon); - boost::trim(strHeader); - boost::to_lower(strHeader); + strHeader = TrimString(strHeader); + strHeader = ToLower(strHeader); string strValue = str.substr(nColon+1); - boost::trim(strValue); + strValue = TrimString(strValue); mapHeadersRet[strHeader] = strValue; if (strHeader == "content-length") nLen = atoi(strValue.c_str()); @@ -550,7 +549,7 @@ bool HTTPAuthorized(map& mapHeaders) string strAuth = mapHeaders["authorization"]; if (strAuth.substr(0,6) != "Basic ") return false; - string strUserPass64 = strAuth.substr(6); boost::trim(strUserPass64); + string strUserPass64 = strAuth.substr(6); strUserPass64 = TrimString(strUserPass64); string strUserPass = DecodeBase64(strUserPass64); return TimingResistantEqual(strUserPass, strRPCUserColonPass); } @@ -768,12 +767,9 @@ static void RPCListen(boost::shared_ptr< basic_socket_acceptorasync_accept( conn->sslStream.lowest_layer(), conn->peer, - boost::bind(&RPCAcceptHandler, - acceptor, - boost::ref(context), - fUseSSL, - conn, - boost::asio::placeholders::error)); + [acceptor, &context, fUseSSL, conn](const boost::system::error_code& error) { + RPCAcceptHandler(acceptor, context, fUseSSL, conn, error); + }); } /** @@ -1383,45 +1379,45 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 0) ConvertTo(params[0]); if (strMethod == "sendtoaddress" && n > 1) ConvertTo(params[1]); if (strMethod == "settxfee" && n > 0) ConvertTo(params[0]); - if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo(params[1]); - if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo(params[1]); - if (strMethod == "listreceivedbyaddress" && n > 0) ConvertTo(params[0]); + if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo(params[1]); + if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo(params[1]); + if (strMethod == "listreceivedbyaddress" && n > 0) ConvertTo(params[0]); if (strMethod == "listreceivedbyaddress" && n > 1) ConvertTo(params[1]); - if (strMethod == "listreceivedbyaccount" && n > 0) ConvertTo(params[0]); + if (strMethod == "listreceivedbyaccount" && n > 0) ConvertTo(params[0]); if (strMethod == "listreceivedbyaccount" && n > 1) ConvertTo(params[1]); - if (strMethod == "getbalance" && n > 1) ConvertTo(params[1]); + if (strMethod == "getbalance" && n > 1) ConvertTo(params[1]); if (strMethod == "getblock" && n > 1) ConvertTo(params[1]); - if (strMethod == "getblockbynumber" && n > 0) ConvertTo(params[0]); + if (strMethod == "getblockbynumber" && n > 0) ConvertTo(params[0]); if (strMethod == "getblockbynumber" && n > 1) ConvertTo(params[1]); - if (strMethod == "getblockhash" && n > 0) ConvertTo(params[0]); + if (strMethod == "getblockhash" && n > 0) ConvertTo(params[0]); if (strMethod == "move" && n > 2) ConvertTo(params[2]); - if (strMethod == "move" && n > 3) ConvertTo(params[3]); + if (strMethod == "move" && n > 3) ConvertTo(params[3]); if (strMethod == "sendfrom" && n > 2) ConvertTo(params[2]); - if (strMethod == "sendfrom" && n > 3) ConvertTo(params[3]); - if (strMethod == "listtransactions" && n > 1) ConvertTo(params[1]); - if (strMethod == "listtransactions" && n > 2) ConvertTo(params[2]); - if (strMethod == "listaccounts" && n > 0) ConvertTo(params[0]); - if (strMethod == "walletpassphrase" && n > 1) ConvertTo(params[1]); + if (strMethod == "sendfrom" && n > 3) ConvertTo(params[3]); + if (strMethod == "listtransactions" && n > 1) ConvertTo(params[1]); + if (strMethod == "listtransactions" && n > 2) ConvertTo(params[2]); + if (strMethod == "listaccounts" && n > 0) ConvertTo(params[0]); + if (strMethod == "walletpassphrase" && n > 1) ConvertTo(params[1]); if (strMethod == "walletpassphrase" && n > 2) ConvertTo(params[2]); - if (strMethod == "listsinceblock" && n > 1) ConvertTo(params[1]); + if (strMethod == "listsinceblock" && n > 1) ConvertTo(params[1]); if (strMethod == "sendmany" && n > 1) ConvertTo(params[1]); - if (strMethod == "sendmany" && n > 2) ConvertTo(params[2]); + if (strMethod == "sendmany" && n > 2) ConvertTo(params[2]); if (strMethod == "reservebalance" && n > 0) ConvertTo(params[0]); if (strMethod == "reservebalance" && n > 1) ConvertTo(params[1]); - if (strMethod == "addmultisigaddress" && n > 0) ConvertTo(params[0]); + if (strMethod == "addmultisigaddress" && n > 0) ConvertTo(params[0]); if (strMethod == "addmultisigaddress" && n > 1) ConvertTo(params[1]); - if (strMethod == "listunspent" && n > 0) ConvertTo(params[0]); - if (strMethod == "listunspent" && n > 1) ConvertTo(params[1]); + if (strMethod == "listunspent" && n > 0) ConvertTo(params[0]); + if (strMethod == "listunspent" && n > 1) ConvertTo(params[1]); if (strMethod == "listunspent" && n > 2) ConvertTo(params[2]); - if (strMethod == "getrawtransaction" && n > 1) ConvertTo(params[1]); + if (strMethod == "getrawtransaction" && n > 1) ConvertTo(params[1]); if (strMethod == "createrawtransaction" && n > 0) ConvertTo(params[0]); if (strMethod == "createrawtransaction" && n > 1) ConvertTo(params[1]); if (strMethod == "signrawtransaction" && n > 1) ConvertTo(params[1], true); if (strMethod == "signrawtransaction" && n > 2) ConvertTo(params[2], true); - if (strMethod == "keypoolrefill" && n > 0) ConvertTo(params[0]); + if (strMethod == "keypoolrefill" && n > 0) ConvertTo(params[0]); if (strMethod == "getblockheader" && n > 1) ConvertTo(params[1]); - if (strMethod == "estimatefee" && n > 0) ConvertTo(params[0]); + if (strMethod == "estimatefee" && n > 0) ConvertTo(params[0]); if (strMethod == "getaddressbalance" && n > 0) ConvertTo(params[0]); if (strMethod == "getaddressutxos" && n > 0) ConvertTo(params[0]); if (strMethod == "getaddresstxids" && n > 0) ConvertTo(params[0]); diff --git a/src/util.cpp b/src/util.cpp index 3910931..308be4d 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -40,7 +40,6 @@ #include "strlcpy.h" #include "version.h" #include "ui_interface.h" -#include // Work around clang compilation problem in Boost 1.46: // /usr/include/boost/program_options/detail/config_file.hpp:163:17: error: call to function 'to_internal' that is neither visible in the template definition nor found by argument-dependent lookup @@ -464,7 +463,7 @@ static const signed char phexdigit[256] = -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, }; -bool IsHex(const string& str) +bool IsHex(std::string_view str) { for (unsigned char c : str) { @@ -1288,7 +1287,7 @@ std::string FormatSubVersion(const std::string& name, int nClientVersion, const ss << "/"; ss << name << ":" << FormatVersion(nClientVersion); if (!comments.empty()) - ss << "(" << boost::algorithm::join(comments, "; ") << ")"; + ss << "(" << JoinStrings(comments, "; ") << ")"; ss << "/"; return ss.str(); } diff --git a/src/util.h b/src/util.h index 7685be0..c7bbe01 100644 --- a/src/util.h +++ b/src/util.h @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include #include @@ -184,7 +186,7 @@ bool ParseMoney(const std::string& str, int64_t& nRet); bool ParseMoney(const char* pszIn, int64_t& nRet); std::vector ParseHex(const char* psz); std::vector ParseHex(const std::string& str); -bool IsHex(const std::string& str); +bool IsHex(std::string_view str); std::vector DecodeBase64(const char* p, bool* pfInvalid = nullptr); std::string DecodeBase64(const std::string& str); std::string EncodeBase64(const unsigned char* pch, size_t len); @@ -288,6 +290,52 @@ inline std::string leftTrim(std::string src, char chr) return src; } +inline std::string TrimString(std::string str) +{ + auto start = str.find_first_not_of(" \t\r\n"); + if (start == std::string::npos) return {}; + auto end = str.find_last_not_of(" \t\r\n"); + return str.substr(start, end - start + 1); +} + +inline std::string ToLower(std::string str) +{ + std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c) { return std::tolower(c); }); + return str; +} + +inline void ReplaceAll(std::string& str, const std::string& from, const std::string& to) +{ + if (from.empty()) return; + size_t pos = 0; + while ((pos = str.find(from, pos)) != std::string::npos) + { + str.replace(pos, from.length(), to); + pos += to.length(); + } +} + +inline std::vector SplitString(const std::string& str, char delim) +{ + std::vector tokens; + std::istringstream iss(str); + std::string token; + while (std::getline(iss, token, delim)) + tokens.push_back(token); + return tokens; +} + +inline std::string JoinStrings(const std::vector& parts, const std::string& sep) +{ + std::string result; + for (size_t i = 0; i < parts.size(); ++i) + { + if (i > 0) result += sep; + result += parts[i]; + } + return result; +} + template std::string HexStr(const T itbegin, const T itend, bool fSpaces=false) { diff --git a/src/wallet.cpp b/src/wallet.cpp index 0d49e47..c4eadd8 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -13,7 +13,6 @@ #include "coincontrol.h" #include "addressindex.h" #include -#include #include #include #include @@ -652,7 +651,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) if ( !strCmd.empty()) { - boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex()); + ReplaceAll(strCmd, "%s", wtxIn.GetHash().GetHex()); std::thread(runCommand, strCmd).detach(); // thread runs free } @@ -1983,7 +1982,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int if (fDebug && GetBoolArg("-printcoinstake")) printf("CreateCoinStake : kernel found\n"); vector vSolutions; - txnouttype whichType; + TxnOutType whichType; CScript scriptPubKeyOut; scriptPubKeyKernel = pcoin.first->vout[pcoin.second].scriptPubKey; if (!Solver(scriptPubKeyKernel, whichType, vSolutions)) @@ -1993,31 +1992,30 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int break; } if (fDebug && GetBoolArg("-printcoinstake")) - printf("CreateCoinStake : parsed kernel type=%d\n", whichType); - if (whichType != TX_PUBKEY && whichType != TX_PUBKEYHASH) + printf("CreateCoinStake : parsed kernel type=%d\n", static_cast(whichType)); + if (whichType != TxnOutType::PubKey && whichType != TxnOutType::PubKeyHash) { if (fDebug && GetBoolArg("-printcoinstake")) - printf("CreateCoinStake : no support for kernel type=%d\n", whichType); - break; // only support pay to public key and pay to address + printf("CreateCoinStake : no support for kernel type=%d\n", static_cast(whichType)); + break; } - if (whichType == TX_PUBKEYHASH) // pay to address type + if (whichType == TxnOutType::PubKeyHash) { - // convert to pay to public key type if (!keystore.GetKey(uint160(vSolutions[0]), key)) { if (fDebug && GetBoolArg("-printcoinstake")) - printf("CreateCoinStake : failed to get key for kernel type=%d\n", whichType); - break; // unable to find corresponding public key + printf("CreateCoinStake : failed to get key for kernel type=%d\n", static_cast(whichType)); + break; } scriptPubKeyOut << key.GetPubKey() << OP_CHECKSIG; } - if (whichType == TX_PUBKEY) + if (whichType == TxnOutType::PubKey) { valtype& vchPubKey = vSolutions[0]; if (!keystore.GetKey(Hash160(vchPubKey), key)) { if (fDebug && GetBoolArg("-printcoinstake")) - printf("CreateCoinStake : failed to get key for kernel type=%d\n", whichType); + printf("CreateCoinStake : failed to get key for kernel type=%d\n", static_cast(whichType)); break; // unable to find corresponding public key }