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
This commit is contained in:
2026-05-08 22:26:31 -07:00
parent 150828b806
commit 9d80ddb6ac
19 changed files with 224 additions and 209 deletions
+5 -6
View File
@@ -7,7 +7,6 @@
#include <filesystem>
#include <fstream>
#include <boost/algorithm/string.hpp>
#include <zlib.h>
@@ -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());
+1 -2
View File
@@ -30,7 +30,6 @@
#include <filesystem>
#include <fstream>
#include <boost/interprocess/sync/file_lock.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <openssl/crypto.h>
#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<unsigned char>(a)) == std::tolower(static_cast<unsigned char>(b)); }))
fCommandLine = true;
if (fCommandLine)
+7 -14
View File
@@ -24,7 +24,6 @@
#include <algorithm>
#include <deque>
#include <memory>
#include <boost/algorithm/string/replace.hpp>
#include <filesystem>
#include <fstream>
@@ -984,8 +983,7 @@ bool CTransaction::AreInputsStandard(const MapPrevTx& mapInputs) const
const CUtxoEntry& entry = mi->second;
vector<vector<unsigned char> > 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<vector<unsigned char> > 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<vector<unsigned char> > 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<valtype> 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;
+1 -2
View File
@@ -13,7 +13,6 @@
#endif
#include "strlcpy.h"
#include <boost/algorithm/string/case_conv.hpp> // 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;
+4 -2
View File
@@ -13,7 +13,6 @@
#include "ui_interface.h"
#include "util.h"
#include <boost/algorithm/string/predicate.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/interprocess/ipc/message_queue.hpp>
#include <boost/version.hpp>
@@ -26,6 +25,9 @@ using namespace boost;
using namespace boost::interprocess;
using namespace boost::posix_time;
#include <algorithm>
#include <cctype>
#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<unsigned char>(a)) == std::tolower(static_cast<unsigned char>(b)); }))
{
const char *strURI = argv[i];
try {
+5 -7
View File
@@ -12,8 +12,6 @@
#include "wallet.h"
#include "init.h"
#include <boost/algorithm/string.hpp>
using namespace std;
using namespace json_spirit;
@@ -149,12 +147,12 @@ static void ParseRESTPath(const string& strURI, vector<string>& parts, map<strin
}
// Split path into parts
boost::split(parts, path, boost::is_any_of("/"));
auto parts = SplitString(path, '/');
// Parse query parameters
if (!queryString.empty()) {
vector<string> 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<string, string>& 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",
+5 -5
View File
@@ -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;
+3 -4
View File
@@ -11,7 +11,6 @@
#include "base58.h"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/algorithm/string.hpp>
#define printf OutputDebugStringF
@@ -168,7 +167,7 @@ Value importwallet(const Array& params, bool fHelp)
continue;
std::vector<std::string> 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;
}
+8 -8
View File
@@ -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<boost::int64_t>(health.lastBlockTime)));
healthObj.push_back(Pair("lastblocktime", static_cast<int64_t>(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;
+9 -9
View File
@@ -17,7 +17,7 @@ using namespace json_spirit;
void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out, bool fIncludeHex)
{
txnouttype type;
TxnOutType type;
vector<CTxDestination> 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));
+11 -11
View File
@@ -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<CTxDestination> 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;
}
+57 -69
View File
@@ -93,15 +93,15 @@ static inline void popstack(vector<valtype>& 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<unsigned char>& vchSig, const vector<unsigned char>&
//
// Return public keys or hashes from scriptPubKey, for 'standard' transaction types.
//
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsigned char> >& vSolutionsRet)
bool Solver(const CScript& scriptPubKey, TxnOutType& typeRet, vector<vector<unsigned char> >& vSolutionsRet)
{
// Templates
static map<txnouttype, CScript> mTemplates;
static map<TxnOutType, CScript> 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<unsigned char> 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<vector<unsi
{
// Found a match
typeRet = tplate.first;
if (typeRet == TX_MULTISIG)
if (typeRet == TxnOutType::MultiSig)
{
// Additional checks for TX_MULTISIG:
unsigned char m = vSolutionsRet.front()[0];
@@ -1419,7 +1413,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsi
}
vSolutionsRet.clear();
typeRet = TX_NONSTANDARD;
typeRet = TxnOutType::NonStandard;
return false;
}
@@ -1460,7 +1454,7 @@ bool SignN(const vector<valtype>& 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<std::vector<unsigned char> >& vSolutions)
int ScriptSigArgsExpected(TxnOutType t, const std::vector<std::vector<unsigned char> >& 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<std::vector<unsigned c
bool IsStandard(const CScript& scriptPubKey)
{
vector<valtype> 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<valtype> 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<valtype> 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<CKeyID> &vKeysIn) : keystore(keystoreIn), vKeys(vKeysIn) {}
void Process(const CScript &script) {
txnouttype type;
TxnOutType type;
std::vector<CTxDestination> 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<CTxDestination>& addressRet, int& nRequiredRet)
bool ExtractDestinations(const CScript& scriptPubKey, TxnOutType& typeRet, vector<CTxDestination>& addressRet, int& nRequiredRet)
{
addressRet.clear();
typeRet = TX_NONSTANDARD;
typeRet = TxnOutType::NonStandard;
vector<valtype> 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<valtype>(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<valtype>& vSolutions,
const TxnOutType txType, const vector<valtype>& vSolutions,
vector<valtype>& sigs1, vector<valtype>& 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<vector<unsigned char> > 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<vector<unsigned char> > vSolutions;
Solver(scriptPubKey, txType, vSolutions);
+10 -11
View File
@@ -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<CNoDestination, CKeyID, CScriptID> CTxDestination;
const char* GetTxnOutputType(txnouttype t);
const char* GetTxnOutputType(TxnOutType t);
/** Script opcodes */
enum opcodetype
@@ -590,14 +589,14 @@ public:
bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, int nHashType);
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet);
int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned char> >& vSolutions);
bool Solver(const CScript& scriptPubKey, TxnOutType& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet);
int ScriptSigArgsExpected(TxnOutType t, const std::vector<std::vector<unsigned char> >& 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<CKeyID> &vKeys);
bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet);
bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);
bool ExtractDestinations(const CScript& scriptPubKey, TxnOutType& typeRet, std::vector<CTxDestination>& 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,
+2 -4
View File
@@ -47,8 +47,6 @@ Notes:
#include <openssl/hmac.h>
#include <string>
#include <boost/algorithm/string/predicate.hpp>
#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);
+5 -5
View File
@@ -181,7 +181,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1)
{
vector<valtype> 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<valtype> 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<valtype> 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<valtype> 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<valtype> 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));
+29 -33
View File
@@ -22,7 +22,6 @@
#include <filesystem>
#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/asio/ssl.hpp>
#include <fstream>
#include <boost/shared_ptr.hpp>
@@ -461,7 +460,7 @@ int ReadHTTPStatus(std::basic_istream<char>& stream, int &proto,
if (!str.empty() && str[str.size()-1] == '\r')
str.resize(str.size()-1);
vector<string> 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<char>& stream, map<string, string>& 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<string, string>& 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_acceptor<Protocol, SocketA
acceptor->async_accept(
conn->sslStream.lowest_layer(),
conn->peer,
boost::bind(&RPCAcceptHandler<Protocol, SocketAcceptorService>,
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<std::stri
if (strMethod == "stop" && n > 0) ConvertTo<bool>(params[0]);
if (strMethod == "sendtoaddress" && n > 1) ConvertTo<double>(params[1]);
if (strMethod == "settxfee" && n > 0) ConvertTo<double>(params[0]);
if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "listreceivedbyaddress" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo<int64_t>(params[1]);
if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo<int64_t>(params[1]);
if (strMethod == "listreceivedbyaddress" && n > 0) ConvertTo<int64_t>(params[0]);
if (strMethod == "listreceivedbyaddress" && n > 1) ConvertTo<bool>(params[1]);
if (strMethod == "listreceivedbyaccount" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "listreceivedbyaccount" && n > 0) ConvertTo<int64_t>(params[0]);
if (strMethod == "listreceivedbyaccount" && n > 1) ConvertTo<bool>(params[1]);
if (strMethod == "getbalance" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "getbalance" && n > 1) ConvertTo<int64_t>(params[1]);
if (strMethod == "getblock" && n > 1) ConvertTo<bool>(params[1]);
if (strMethod == "getblockbynumber" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "getblockbynumber" && n > 0) ConvertTo<int64_t>(params[0]);
if (strMethod == "getblockbynumber" && n > 1) ConvertTo<bool>(params[1]);
if (strMethod == "getblockhash" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "getblockhash" && n > 0) ConvertTo<int64_t>(params[0]);
if (strMethod == "move" && n > 2) ConvertTo<double>(params[2]);
if (strMethod == "move" && n > 3) ConvertTo<boost::int64_t>(params[3]);
if (strMethod == "move" && n > 3) ConvertTo<int64_t>(params[3]);
if (strMethod == "sendfrom" && n > 2) ConvertTo<double>(params[2]);
if (strMethod == "sendfrom" && n > 3) ConvertTo<boost::int64_t>(params[3]);
if (strMethod == "listtransactions" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "listtransactions" && n > 2) ConvertTo<boost::int64_t>(params[2]);
if (strMethod == "listaccounts" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "walletpassphrase" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "sendfrom" && n > 3) ConvertTo<int64_t>(params[3]);
if (strMethod == "listtransactions" && n > 1) ConvertTo<int64_t>(params[1]);
if (strMethod == "listtransactions" && n > 2) ConvertTo<int64_t>(params[2]);
if (strMethod == "listaccounts" && n > 0) ConvertTo<int64_t>(params[0]);
if (strMethod == "walletpassphrase" && n > 1) ConvertTo<int64_t>(params[1]);
if (strMethod == "walletpassphrase" && n > 2) ConvertTo<bool>(params[2]);
if (strMethod == "listsinceblock" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "listsinceblock" && n > 1) ConvertTo<int64_t>(params[1]);
if (strMethod == "sendmany" && n > 1) ConvertTo<Object>(params[1]);
if (strMethod == "sendmany" && n > 2) ConvertTo<boost::int64_t>(params[2]);
if (strMethod == "sendmany" && n > 2) ConvertTo<int64_t>(params[2]);
if (strMethod == "reservebalance" && n > 0) ConvertTo<bool>(params[0]);
if (strMethod == "reservebalance" && n > 1) ConvertTo<double>(params[1]);
if (strMethod == "addmultisigaddress" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "addmultisigaddress" && n > 0) ConvertTo<int64_t>(params[0]);
if (strMethod == "addmultisigaddress" && n > 1) ConvertTo<Array>(params[1]);
if (strMethod == "listunspent" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "listunspent" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "listunspent" && n > 0) ConvertTo<int64_t>(params[0]);
if (strMethod == "listunspent" && n > 1) ConvertTo<int64_t>(params[1]);
if (strMethod == "listunspent" && n > 2) ConvertTo<Array>(params[2]);
if (strMethod == "getrawtransaction" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "getrawtransaction" && n > 1) ConvertTo<int64_t>(params[1]);
if (strMethod == "createrawtransaction" && n > 0) ConvertTo<Array>(params[0]);
if (strMethod == "createrawtransaction" && n > 1) ConvertTo<Object>(params[1]);
if (strMethod == "signrawtransaction" && n > 1) ConvertTo<Array>(params[1], true);
if (strMethod == "signrawtransaction" && n > 2) ConvertTo<Array>(params[2], true);
if (strMethod == "keypoolrefill" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "keypoolrefill" && n > 0) ConvertTo<int64_t>(params[0]);
if (strMethod == "getblockheader" && n > 1) ConvertTo<bool>(params[1]);
if (strMethod == "estimatefee" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "estimatefee" && n > 0) ConvertTo<int64_t>(params[0]);
if (strMethod == "getaddressbalance" && n > 0) ConvertTo<Object>(params[0]);
if (strMethod == "getaddressutxos" && n > 0) ConvertTo<Object>(params[0]);
if (strMethod == "getaddresstxids" && n > 0) ConvertTo<Object>(params[0]);
+2 -3
View File
@@ -40,7 +40,6 @@
#include "strlcpy.h"
#include "version.h"
#include "ui_interface.h"
#include <boost/algorithm/string/join.hpp>
// 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();
}
+49 -1
View File
@@ -18,6 +18,8 @@
#include <vector>
#include <string>
#include <string_view>
#include <sstream>
#include <algorithm>
#include <chrono>
#include <thread>
@@ -184,7 +186,7 @@ bool ParseMoney(const std::string& str, int64_t& nRet);
bool ParseMoney(const char* pszIn, int64_t& nRet);
std::vector<unsigned char> ParseHex(const char* psz);
std::vector<unsigned char> ParseHex(const std::string& str);
bool IsHex(const std::string& str);
bool IsHex(std::string_view str);
std::vector<unsigned char> 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<std::string> SplitString(const std::string& str, char delim)
{
std::vector<std::string> 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<std::string>& 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<typename T>
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
{
+11 -13
View File
@@ -13,7 +13,6 @@
#include "coincontrol.h"
#include "addressindex.h"
#include <memory>
#include <boost/algorithm/string/replace.hpp>
#include <algorithm>
#include <random>
#include <deque>
@@ -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<valtype> 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<int>(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<int>(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<int>(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<int>(whichType));
break; // unable to find corresponding public key
}