diff --git a/src/core_write.cpp b/src/core_write.cpp index 4abe44c833..922089cf8b 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -159,13 +159,13 @@ std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags) { CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | serializeFlags); ssTx << tx; - return HexStr(ssTx.begin(), ssTx.end()); + return HexStr(ssTx); } void ScriptToUniv(const CScript& script, UniValue& out, bool include_address) { out.pushKV("asm", ScriptToAsmStr(script)); - out.pushKV("hex", HexStr(script.begin(), script.end())); + out.pushKV("hex", HexStr(script)); std::vector> solns; txnouttype type = Solver(script, solns); @@ -187,7 +187,7 @@ static void SidechainScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& o out.pushKV(prefix + "asm", ScriptToAsmStr(scriptPubKey)); if (fIncludeHex) - out.pushKV(prefix + "hex", HexStr(scriptPubKey.begin(), scriptPubKey.end())); + out.pushKV(prefix + "hex", HexStr(scriptPubKey)); if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired) || type == TX_PUBKEY) { out.pushKV(prefix + "type", GetTxnOutputType(type)); @@ -242,13 +242,13 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, const CTxIn& txin = tx.vin[i]; UniValue in(UniValue::VOBJ); if (tx.IsCoinBase()) - in.pushKV("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); + in.pushKV("coinbase", HexStr(txin.scriptSig)); else { in.pushKV("txid", txin.prevout.hash.GetHex()); in.pushKV("vout", (int64_t)txin.prevout.n); UniValue o(UniValue::VOBJ); o.pushKV("asm", ScriptToAsmStr(txin.scriptSig, true)); - o.pushKV("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); + o.pushKV("hex", HexStr(txin.scriptSig)); in.pushKV("scriptSig", o); in.pushKV("is_pegin", txin.m_is_pegin); } @@ -260,7 +260,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, if (!scriptWitness.IsNull()) { UniValue txinwitness(UniValue::VARR); for (const auto &item : scriptWitness.stack) { - txinwitness.push_back(HexStr(item.begin(), item.end())); + txinwitness.push_back(HexStr(item)); } in.pushKV("txinwitness", txinwitness); } @@ -269,7 +269,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, if (tx.witness.vtxinwit.size() > i && !tx.witness.vtxinwit[i].m_pegin_witness.IsNull()) { UniValue pegin_witness(UniValue::VARR); for (const auto& item : tx.witness.vtxinwit[i].m_pegin_witness.stack) { - pegin_witness.push_back(HexStr(item.begin(), item.end())); + pegin_witness.push_back(HexStr(item)); } in.pushKV("pegin_witness", pegin_witness); } diff --git a/src/rest.cpp b/src/rest.cpp index 9dafca15f3..cb518a3d82 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -188,7 +188,7 @@ static bool rest_headers(const util::Ref& context, ssHeader << pindex->GetBlockHeader(); } - std::string strHex = HexStr(ssHeader.begin(), ssHeader.end()) + "\n"; + std::string strHex = HexStr(ssHeader) + "\n"; req->WriteHeader("Content-Type", "text/plain"); req->WriteReply(HTTP_OK, strHex); return true; @@ -253,7 +253,7 @@ static bool rest_block(HTTPRequest* req, case RetFormat::HEX: { CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags()); ssBlock << block; - std::string strHex = HexStr(ssBlock.begin(), ssBlock.end()) + "\n"; + std::string strHex = HexStr(ssBlock) + "\n"; req->WriteHeader("Content-Type", "text/plain"); req->WriteReply(HTTP_OK, strHex); return true; @@ -391,7 +391,7 @@ static bool rest_tx(const util::Ref& context, HTTPRequest* req, const std::strin CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags()); ssTx << tx; - std::string strHex = HexStr(ssTx.begin(), ssTx.end()) + "\n"; + std::string strHex = HexStr(ssTx) + "\n"; req->WriteHeader("Content-Type", "text/plain"); req->WriteReply(HTTP_OK, strHex); return true; @@ -556,7 +556,7 @@ static bool rest_getutxos(const util::Ref& context, HTTPRequest* req, const std: case RetFormat::HEX: { CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION); ssGetUTXOResponse << ::ChainActive().Height() << ::ChainActive().Tip()->GetBlockHash() << bitmap << outs; - std::string strHex = HexStr(ssGetUTXOResponse.begin(), ssGetUTXOResponse.end()) + "\n"; + std::string strHex = HexStr(ssGetUTXOResponse) + "\n"; req->WriteHeader("Content-Type", "text/plain"); req->WriteReply(HTTP_OK, strHex); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 89b058a3c2..53582ce30d 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -839,7 +839,7 @@ static UniValue getblockheader(const JSONRPCRequest& request) { CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION); ssBlock << pblockindex->GetBlockHeader(); - std::string strHex = HexStr(ssBlock.begin(), ssBlock.end()); + std::string strHex = HexStr(ssBlock); return strHex; } @@ -984,7 +984,7 @@ static UniValue getblock(const JSONRPCRequest& request) { CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags()); ssBlock << block; - std::string strHex = HexStr(ssBlock.begin(), ssBlock.end()); + std::string strHex = HexStr(ssBlock); return strHex; } @@ -2321,7 +2321,7 @@ UniValue scantxoutset(const JSONRPCRequest& request) UniValue unspent(UniValue::VOBJ); unspent.pushKV("txid", outpoint.hash.GetHex()); unspent.pushKV("vout", (int32_t)outpoint.n); - unspent.pushKV("scriptPubKey", HexStr(txo.scriptPubKey.begin(), txo.scriptPubKey.end())); + unspent.pushKV("scriptPubKey", HexStr(txo.scriptPubKey)); unspent.pushKV("desc", descriptors[txo.scriptPubKey]); unspent.pushKV("amount", ValueFromAmount(txo.nValue.GetAmount())); unspent.pushKV("height", (int32_t)coin.nHeight); @@ -2344,7 +2344,7 @@ UniValue scantxoutset(const JSONRPCRequest& request) UniValue unspent(UniValue::VOBJ); unspent.pushKV("txid", outpoint.hash.GetHex()); unspent.pushKV("vout", (int32_t)outpoint.n); - unspent.pushKV("scriptPubKey", HexStr(txo.scriptPubKey.begin(), txo.scriptPubKey.end())); + unspent.pushKV("scriptPubKey", HexStr(txo.scriptPubKey)); unspent.pushKV("desc", descriptors[txo.scriptPubKey]); if (txo.nValue.IsExplicit()) { unspent.pushKV("amount", ValueFromAmount(txo.nValue.GetAmount())); @@ -2409,7 +2409,7 @@ UniValue getsidechaininfo(const JSONRPCRequest& request) const uint256& parent_blockhash = Params().ParentGenesisBlockHash(); UniValue obj(UniValue::VOBJ); - obj.pushKV("fedpegscript", HexStr(consensus.fedpegScript.begin(), consensus.fedpegScript.end())); + obj.pushKV("fedpegscript", HexStr(consensus.fedpegScript)); // We use mempool_validation as true to show what is enforced for *next* block std::vector> fedpegscripts = GetValidFedpegScripts(::ChainActive().Tip(), consensus, true /* nextblock_validation */); UniValue fedpeg_prog_entries(UniValue::VARR); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 1fbe26c946..0ae4eacf41 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -895,7 +895,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request) result.pushKV("height", (int64_t)(pindexPrev->nHeight+1)); if (!pblocktemplate->vchCoinbaseCommitment.empty()) { - result.pushKV("default_witness_commitment", HexStr(pblocktemplate->vchCoinbaseCommitment.begin(), pblocktemplate->vchCoinbaseCommitment.end())); + result.pushKV("default_witness_commitment", HexStr(pblocktemplate->vchCoinbaseCommitment)); } return result; @@ -1308,7 +1308,7 @@ UniValue getnewblockhex(const JSONRPCRequest& request) CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION); ssBlock << pblocktemplate->block; - return HexStr(ssBlock.begin(), ssBlock.end()); + return HexStr(ssBlock); } UniValue combineblocksigs(const JSONRPCRequest& request) @@ -1394,7 +1394,7 @@ UniValue combineblocksigs(const JSONRPCRequest& request) CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags()); ssBlock << block; UniValue result(UniValue::VOBJ); - result.pushKV("hex", HexStr(ssBlock.begin(), ssBlock.end())); + result.pushKV("hex", HexStr(ssBlock)); result.pushKV("complete", CheckProof(block, params)); return result; } @@ -1426,7 +1426,7 @@ UniValue getcompactsketch(const JSONRPCRequest& request) CDataStream ssCompactBlock(SER_NETWORK, PROTOCOL_VERSION); ssCompactBlock << cmpctblock; - return HexStr(ssCompactBlock.begin(), ssCompactBlock.end()); + return HexStr(ssCompactBlock); } @@ -1496,14 +1496,14 @@ UniValue consumecompactsketch(const JSONRPCRequest& request) CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION); ssBlock << *pblock; - ret.pushKV("blockhex", HexStr(ssBlock.begin(), ssBlock.end())); + ret.pushKV("blockhex", HexStr(ssBlock)); } else { // Serialize the list of transactions we found CDataStream ssFound(SER_NETWORK, PROTOCOL_VERSION); ssFound << found; - ret.pushKV("block_tx_req", HexStr(ssReq.begin(), ssReq.end())); - ret.pushKV("found_transactions", HexStr(ssFound.begin(), ssFound.end())); + ret.pushKV("block_tx_req", HexStr(ssReq)); + ret.pushKV("found_transactions", HexStr(ssFound)); } return ret; } @@ -1549,7 +1549,7 @@ UniValue consumegetblocktxn(const JSONRPCRequest& request) CDataStream ssResp(SER_NETWORK, PROTOCOL_VERSION); ssResp << resp; - return HexStr(ssResp.begin(), ssResp.end()); + return HexStr(ssResp); } UniValue finalizecompactblock(const JSONRPCRequest& request) @@ -1618,7 +1618,7 @@ UniValue finalizecompactblock(const JSONRPCRequest& request) CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION); ssBlock << *pblock; - return HexStr(ssBlock.begin(), ssBlock.end()); + return HexStr(ssBlock); } UniValue testproposedblock(const JSONRPCRequest& request) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 47ac980117..9a9345a0cc 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -78,7 +78,7 @@ static UniValue validateaddress(const JSONRPCRequest& request) ret.pushKV("address", currentAddress); CScript scriptPubKey = GetScriptForDestination(dest); - ret.pushKV("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())); + ret.pushKV("scriptPubKey", HexStr(scriptPubKey)); UniValue detail = DescribeAddress(dest); ret.pushKVs(detail); @@ -91,7 +91,7 @@ static UniValue validateaddress(const JSONRPCRequest& request) parent_info.pushKV("address", currentAddress); CScript scriptPubKey = GetScriptForDestination(parent_dest); - parent_info.pushKV("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())); + parent_info.pushKV("scriptPubKey", HexStr(scriptPubKey)); UniValue detail = DescribeAddress(parent_dest); parent_info.pushKVs(detail); @@ -162,7 +162,7 @@ static UniValue createmultisig(const JSONRPCRequest& request) UniValue result(UniValue::VOBJ); result.pushKV("address", EncodeDestination(dest)); - result.pushKV("redeemScript", HexStr(inner.begin(), inner.end())); + result.pushKV("redeemScript", HexStr(inner)); result.pushKV("descriptor", descriptor->ToString()); return result; diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 873a1b14ff..c57ffdf620 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -325,7 +325,7 @@ static UniValue gettxoutproof(const JSONRPCRequest& request) CDataStream ssMB(SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS); CMerkleBlock mb(block, setTxids); ssMB << mb; - std::string strHex = HexStr(ssMB.begin(), ssMB.end()); + std::string strHex = HexStr(ssMB); return strHex; } @@ -1370,7 +1370,7 @@ UniValue decodepsbt(const JSONRPCRequest& request) if (!input.final_script_witness.IsNull()) { UniValue txinwitness(UniValue::VARR); for (const auto& item : input.final_script_witness.stack) { - txinwitness.push_back(HexStr(item.begin(), item.end())); + txinwitness.push_back(HexStr(item)); } in.pushKV("final_scriptwitness", txinwitness); } @@ -1402,7 +1402,7 @@ UniValue decodepsbt(const JSONRPCRequest& request) if (btc_peg_in_tx) { CDataStream ss_tx(SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS); ss_tx << btc_peg_in_tx; - in.pushKV("pegin_bitcoin_tx", HexStr(ss_tx.begin(), ss_tx.end())); + in.pushKV("pegin_bitcoin_tx", HexStr(ss_tx)); } } if (input.txout_proof.which() > 0) { @@ -1410,7 +1410,7 @@ UniValue decodepsbt(const JSONRPCRequest& request) if (!btc_txout_proof.header.IsNull()) { CDataStream ss_mb(SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS); ss_mb << btc_txout_proof; - in.pushKV("pegin_txout_proof", HexStr(ss_mb.begin(), ss_mb.end())); + in.pushKV("pegin_txout_proof", HexStr(ss_mb)); } } } else { @@ -1419,7 +1419,7 @@ UniValue decodepsbt(const JSONRPCRequest& request) if (elem_peg_in_tx) { CDataStream ss_tx(SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS); ss_tx << elem_peg_in_tx; - in.pushKV("pegin_bitcoin_tx", HexStr(ss_tx.begin(), ss_tx.end())); + in.pushKV("pegin_bitcoin_tx", HexStr(ss_tx)); } } if (input.txout_proof.which() > 0) { @@ -1427,12 +1427,12 @@ UniValue decodepsbt(const JSONRPCRequest& request) if (!elem_txout_proof.header.IsNull()) { CDataStream ss_mb(SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS); ss_mb << elem_txout_proof; - in.pushKV("pegin_txout_proof", HexStr(ss_mb.begin(), ss_mb.end())); + in.pushKV("pegin_txout_proof", HexStr(ss_mb)); } } } if (!input.claim_script.empty()) { - in.pushKV("pegin_claim_script", HexStr(input.claim_script.begin(), input.claim_script.end())); + in.pushKV("pegin_claim_script", HexStr(input.claim_script)); } if (!input.genesis_hash.IsNull()) { in.pushKV("pegin_genesis_hash", input.genesis_hash.GetHex()); diff --git a/src/rpc/rawtransaction_util.cpp b/src/rpc/rawtransaction_util.cpp index 685e3cc3c3..cb5aa46534 100644 --- a/src/rpc/rawtransaction_util.cpp +++ b/src/rpc/rawtransaction_util.cpp @@ -362,10 +362,10 @@ static void TxInErrorToJSON(const CTxIn& txin, const CTxInWitness& txinwit, UniV entry.pushKV("vout", (uint64_t)txin.prevout.n); UniValue witness(UniValue::VARR); for (unsigned int i = 0; i < txinwit.scriptWitness.stack.size(); i++) { - witness.push_back(HexStr(txinwit.scriptWitness.stack[i].begin(), txinwit.scriptWitness.stack[i].end())); + witness.push_back(HexStr(txinwit.scriptWitness.stack[i])); } entry.pushKV("witness", witness); - entry.pushKV("scriptSig", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); + entry.pushKV("scriptSig", HexStr(txin.scriptSig)); entry.pushKV("sequence", (uint64_t)txin.nSequence); entry.pushKV("error", strMessage); vErrorsRet.push_back(entry); diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 8ff72af5e2..2f9b1d1319 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -227,7 +227,7 @@ public: obj.pushKV("isscript", false); obj.pushKV("iswitness", true); obj.pushKV("witness_version", 0); - obj.pushKV("witness_program", HexStr(id.begin(), id.end())); + obj.pushKV("witness_program", HexStr(id)); return obj; } @@ -237,7 +237,7 @@ public: obj.pushKV("isscript", true); obj.pushKV("iswitness", true); obj.pushKV("witness_version", 0); - obj.pushKV("witness_program", HexStr(id.begin(), id.end())); + obj.pushKV("witness_program", HexStr(id)); return obj; } @@ -927,7 +927,7 @@ public: UniValue obj(UniValue::VOBJ); const CPubKey& blind_pub = pkhash.blinding_pubkey; if (IsBlindDestination(pkhash)) { - obj.pushKV("confidential_key", HexStr(blind_pub.begin(), blind_pub.end())); + obj.pushKV("confidential_key", HexStr(blind_pub)); PKHash unblinded(pkhash); unblinded.blinding_pubkey = CPubKey(); obj.pushKV("unconfidential", EncodeDestination(unblinded)); @@ -943,7 +943,7 @@ public: UniValue obj(UniValue::VOBJ); const CPubKey& blind_pub = scripthash.blinding_pubkey; if (IsBlindDestination(scripthash)) { - obj.pushKV("confidential_key", HexStr(blind_pub.begin(), blind_pub.end())); + obj.pushKV("confidential_key", HexStr(blind_pub)); ScriptHash unblinded(scripthash); unblinded.blinding_pubkey = CPubKey(); obj.pushKV("unconfidential", EncodeDestination(unblinded)); @@ -960,7 +960,7 @@ public: UniValue obj(UniValue::VOBJ); const CPubKey& blind_pub = id.blinding_pubkey; if (IsBlindDestination(id)) { - obj.pushKV("confidential_key", HexStr(blind_pub.begin(), blind_pub.end())); + obj.pushKV("confidential_key", HexStr(blind_pub)); WitnessV0KeyHash unblinded(id); unblinded.blinding_pubkey = CPubKey(); obj.pushKV("unconfidential", EncodeDestination(unblinded)); @@ -977,7 +977,7 @@ public: UniValue obj(UniValue::VOBJ); const CPubKey& blind_pub = id.blinding_pubkey; if (IsBlindDestination(id)) { - obj.pushKV("confidential_key", HexStr(blind_pub.begin(), blind_pub.end())); + obj.pushKV("confidential_key", HexStr(blind_pub)); WitnessV0ScriptHash unblinded(id); unblinded.blinding_pubkey = CPubKey(); obj.pushKV("unconfidential", EncodeDestination(unblinded)); diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index 7a5421ab6f..2634d3ad4f 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -235,7 +235,7 @@ public: } bool IsRange() const override { return false; } size_t GetSize() const override { return m_pubkey.size(); } - std::string ToString() const override { return HexStr(m_pubkey.begin(), m_pubkey.end()); } + std::string ToString() const override { return HexStr(m_pubkey); } bool ToPrivateString(const SigningProvider& arg, std::string& ret) const override { CKey key; @@ -583,7 +583,7 @@ class RawDescriptor final : public DescriptorImpl { const CScript m_script; protected: - std::string ToStringExtra() const override { return HexStr(m_script.begin(), m_script.end()); } + std::string ToStringExtra() const override { return HexStr(m_script); } std::vector MakeScripts(const std::vector&, const CScript*, FlatSigningProvider&) const override { return Vector(m_script); } public: RawDescriptor(CScript script) : DescriptorImpl({}, {}, "raw"), m_script(std::move(script)) {} diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index 1db5f59e99..85995c3de2 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -539,7 +539,7 @@ BOOST_AUTO_TEST_CASE(ccoins_serialization) CDataStream tmp(SER_DISK, CLIENT_VERSION); uint64_t x = 3000000000ULL; tmp << VARINT(x); - BOOST_CHECK_EQUAL(HexStr(tmp.begin(), tmp.end()), "8a95c0bb00"); + BOOST_CHECK_EQUAL(HexStr(tmp), "8a95c0bb00"); CDataStream ss5(ParseHex("00008a95c0bb00"), SER_DISK, CLIENT_VERSION); try { Coin cc5; diff --git a/src/test/descriptor_tests.cpp b/src/test/descriptor_tests.cpp index 5f9a78ceb2..5d7065dafb 100644 --- a/src/test/descriptor_tests.cpp +++ b/src/test/descriptor_tests.cpp @@ -216,7 +216,7 @@ void DoCheck(const std::string& prv, const std::string& pub, int flags, const st // For each of the produced scripts, verify solvability, and when possible, try to sign a transaction spending it. for (size_t n = 0; n < spks.size(); ++n) { - BOOST_CHECK_EQUAL(ref[n], HexStr(spks[n].begin(), spks[n].end())); + BOOST_CHECK_EQUAL(ref[n], HexStr(spks[n])); BOOST_CHECK_EQUAL(IsSolvable(Merge(key_provider, script_provider), spks[n]), (flags & UNSOLVABLE) == 0); if (flags & SIGNABLE) { diff --git a/src/test/fuzz/decode_tx.cpp b/src/test/fuzz/decode_tx.cpp index 09c4ff05df..0d89d4228a 100644 --- a/src/test/fuzz/decode_tx.cpp +++ b/src/test/fuzz/decode_tx.cpp @@ -14,7 +14,7 @@ void test_one_input(const std::vector& buffer) { - const std::string tx_hex = HexStr(std::string{buffer.begin(), buffer.end()}); + const std::string tx_hex = HexStr(buffer); CMutableTransaction mtx; const bool result_none = DecodeHexTx(mtx, tx_hex, false, false); const bool result_try_witness = DecodeHexTx(mtx, tx_hex, false, true); diff --git a/src/test/fuzz/key.cpp b/src/test/fuzz/key.cpp index 1919a5f881..58735545c9 100644 --- a/src/test/fuzz/key.cpp +++ b/src/test/fuzz/key.cpp @@ -108,7 +108,7 @@ void test_one_input(const std::vector& buffer) assert(pubkey.IsCompressed()); assert(pubkey.IsValid()); assert(pubkey.IsFullyValid()); - assert(HexToPubKey(HexStr(pubkey.begin(), pubkey.end())) == pubkey); + assert(HexToPubKey(HexStr(pubkey)) == pubkey); assert(GetAllDestinationsForKey(pubkey).size() == 3); } diff --git a/src/test/sighash_tests.cpp b/src/test/sighash_tests.cpp index 5ca136ea6e..c0bb92258b 100644 --- a/src/test/sighash_tests.cpp +++ b/src/test/sighash_tests.cpp @@ -141,7 +141,7 @@ BOOST_AUTO_TEST_CASE(sighash_test) ss << txTo; std::cout << "\t[\"" ; - std::cout << HexStr(ss.begin(), ss.end()) << "\", \""; + std::cout << HexStr(ss) << "\", \""; std::cout << HexStr(scriptCode) << "\", "; std::cout << nIn << ", "; std::cout << nHashType << ", \""; diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 65c968e310..6c03468f30 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -824,7 +824,7 @@ UniValue dumpwallet(const JSONRPCRequest& request) create_time = FormatISO8601DateTime(it->second.nCreateTime); } if(spk_man.GetCScript(scriptid, script)) { - file << strprintf("%s %s script=1", HexStr(script.begin(), script.end()), create_time); + file << strprintf("%s %s script=1", HexStr(script), create_time); file << strprintf(" # addr=%s\n", address); } } @@ -1217,7 +1217,7 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con // Check whether we have any work to do for (const CScript& script : script_pub_keys) { if (pwallet->IsMine(script) & ISMINE_SPENDABLE) { - throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the private key for this address or script (\"" + HexStr(script.begin(), script.end()) + "\")"); + throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the private key for this address or script (\"" + HexStr(script) + "\")"); } // ELEMENTS: @@ -2021,7 +2021,7 @@ UniValue dumpblindingkey(const JSONRPCRequest& request) if (key.IsValid()) { CPubKey pubkey(key.GetPubKey()); if (pubkey == GetDestinationBlindingKey(dest)) { - return HexStr(key.begin(), key.end()); + return HexStr(key); } } @@ -2110,7 +2110,7 @@ UniValue dumpissuanceblindingkey(const JSONRPCRequest& request) CScript blindingScript(CScript() << OP_RETURN << std::vector(pcoin->tx->vin[vindex].prevout.hash.begin(), pcoin->tx->vin[vindex].prevout.hash.end()) << pcoin->tx->vin[vindex].prevout.n); CKey key; key = pwallet->GetBlindingKey(&blindingScript); - return HexStr(key.begin(), key.end()); + return HexStr(key); } else { // We don't know how to deblind this using our wallet throw JSONRPCError(RPC_WALLET_ERROR, "Unable to unblind issuance with wallet blinding key."); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d7cce60897..190dd8ecc1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1089,7 +1089,7 @@ static UniValue addmultisigaddress(const JSONRPCRequest& request) UniValue result(UniValue::VOBJ); result.pushKV("address", EncodeDestination(dest)); - result.pushKV("redeemScript", HexStr(inner.begin(), inner.end())); + result.pushKV("redeemScript", HexStr(inner)); result.pushKV("descriptor", descriptor->ToString()); return result; } @@ -3128,7 +3128,7 @@ static UniValue listunspent(const JSONRPCRequest& request) const CScriptID& hash = CScriptID(boost::get(address)); CScript redeemScript; if (provider->GetCScript(hash, redeemScript)) { - entry.pushKV("redeemScript", HexStr(redeemScript.begin(), redeemScript.end())); + entry.pushKV("redeemScript", HexStr(redeemScript)); // Now check if the redeemScript is actually a P2WSH script CTxDestination witness_destination; if (redeemScript.IsPayToWitnessScriptHash()) { @@ -3140,7 +3140,7 @@ static UniValue listunspent(const JSONRPCRequest& request) CRIPEMD160().Write(whash.begin(), whash.size()).Finalize(id.begin()); CScript witnessScript; if (provider->GetCScript(id, witnessScript)) { - entry.pushKV("witnessScript", HexStr(witnessScript.begin(), witnessScript.end())); + entry.pushKV("witnessScript", HexStr(witnessScript)); } } } @@ -3150,13 +3150,13 @@ static UniValue listunspent(const JSONRPCRequest& request) CRIPEMD160().Write(whash.begin(), whash.size()).Finalize(id.begin()); CScript witnessScript; if (provider->GetCScript(id, witnessScript)) { - entry.pushKV("witnessScript", HexStr(witnessScript.begin(), witnessScript.end())); + entry.pushKV("witnessScript", HexStr(witnessScript)); } } } } - entry.pushKV("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())); + entry.pushKV("scriptPubKey", HexStr(scriptPubKey)); entry.pushKV("amount", ValueFromAmount(amount)); if (g_con_elementsmode) { if (tx_out.nAsset.IsCommitment()) { @@ -3880,7 +3880,7 @@ public: std::vector> solutions_data; txnouttype which_type = Solver(subscript, solutions_data); obj.pushKV("script", GetTxnOutputType(which_type)); - obj.pushKV("hex", HexStr(subscript.begin(), subscript.end())); + obj.pushKV("hex", HexStr(subscript)); CTxDestination embedded; if (ExtractDestination(subscript, embedded)) { @@ -3891,7 +3891,7 @@ public: UniValue wallet_detail = boost::apply_visitor(*this, embedded); subobj.pushKVs(wallet_detail); subobj.pushKV("address", EncodeDestination(embedded)); - subobj.pushKV("scriptPubKey", HexStr(subscript.begin(), subscript.end())); + subobj.pushKV("scriptPubKey", HexStr(subscript)); // Always report the pubkey at the top level, so that `getnewaddress()['pubkey']` always works. if (subobj.exists("pubkey")) obj.pushKV("pubkey", subobj["pubkey"]); obj.pushKV("embedded", std::move(subobj)); @@ -3902,7 +3902,7 @@ public: UniValue pubkeys(UniValue::VARR); for (size_t i = 1; i < solutions_data.size() - 1; ++i) { CPubKey key(solutions_data[i].begin(), solutions_data[i].end()); - pubkeys.push_back(HexStr(key.begin(), key.end())); + pubkeys.push_back(HexStr(key)); } obj.pushKV("pubkeys", std::move(pubkeys)); } @@ -4139,7 +4139,7 @@ UniValue getaddressinfo(const JSONRPCRequest& request) ret.pushKV("address", currentAddress); CScript scriptPubKey = GetScriptForDestination(dest); - ret.pushKV("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())); + ret.pushKV("scriptPubKey", HexStr(scriptPubKey)); std::unique_ptr provider = pwallet->GetSolvingProvider(scriptPubKey); @@ -4905,8 +4905,8 @@ UniValue signblock(const JSONRPCRequest& request) UniValue ret(UniValue::VARR); for (const auto& signature : block_sigs.signatures) { UniValue obj(UniValue::VOBJ); - obj.pushKV("pubkey", HexStr(signature.second.first.begin(), signature.second.first.end())); - obj.pushKV("sig", HexStr(signature.second.second.begin(), signature.second.second.end())); + obj.pushKV("pubkey", HexStr(signature.second.first)); + obj.pushKV("sig", HexStr(signature.second.second)); ret.push_back(obj); } return ret; @@ -6548,7 +6548,7 @@ UniValue generatepegoutproof(const JSONRPCRequest& request) assert(expectedOutputSize == preSize); std::vector voutput(output, output + expectedOutputSize / sizeof(output[0])); - return HexStr(voutput.begin(), voutput.end()); + return HexStr(voutput); } // Only used for functionary integration tests @@ -6623,7 +6623,7 @@ UniValue getpegoutkeys(const JSONRPCRequest& request) UniValue ret(UniValue::VOBJ); ret.pushKV("sumkey", EncodeSecret(sumseckey)); - ret.pushKV("btcpubkey", HexStr(bitcoinpubkey.begin(), bitcoinpubkey.end())); + ret.pushKV("btcpubkey", HexStr(bitcoinpubkey)); ret.pushKV("btcaddress", EncodeParentDestination(PKHash(bitcoinpubkey.GetID()))); return ret; diff --git a/src/wallet/test/psbt_wallet_tests.cpp b/src/wallet/test/psbt_wallet_tests.cpp index d41f85d10f..be4e519d99 100644 --- a/src/wallet/test/psbt_wallet_tests.cpp +++ b/src/wallet/test/psbt_wallet_tests.cpp @@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE(psbt_updater_test) // Get the final tx CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << psbtx; - std::string final_hex = HexStr(ssTx.begin(), ssTx.end()); + std::string final_hex = HexStr(ssTx); BOOST_CHECK_EQUAL(final_hex, "70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000000104475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae2206029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f10d90c6a4f000000800000008000000080220602dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d710d90c6a4f00000080000000800100008001090880f0fa02000000000001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e88701042200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903010547522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae2206023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7310d90c6a4f000000800000008003000080220603089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc10d90c6a4f00000080000000800200008001090800c2eb0b0000000000220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080010521010000000000000000000000000000000000000000000000000000000000000000002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008001052101000000000000000000000000000000000000000000000000000000000000000000"); // Mutate the transaction so that one of the inputs is invalid diff --git a/src/wallet/test/wallet_crypto_tests.cpp b/src/wallet/test/wallet_crypto_tests.cpp index 97f8c94fa6..10ddfa22ef 100644 --- a/src/wallet/test/wallet_crypto_tests.cpp +++ b/src/wallet/test/wallet_crypto_tests.cpp @@ -24,10 +24,10 @@ static void TestPassphraseSingle(const std::vector& vchSalt, cons if(!correctKey.empty()) BOOST_CHECK_MESSAGE(memcmp(crypt.vchKey.data(), correctKey.data(), crypt.vchKey.size()) == 0, \ - HexStr(crypt.vchKey.begin(), crypt.vchKey.end()) + std::string(" != ") + HexStr(correctKey.begin(), correctKey.end())); + HexStr(crypt.vchKey) + std::string(" != ") + HexStr(correctKey)); if(!correctIV.empty()) BOOST_CHECK_MESSAGE(memcmp(crypt.vchIV.data(), correctIV.data(), crypt.vchIV.size()) == 0, - HexStr(crypt.vchIV.begin(), crypt.vchIV.end()) + std::string(" != ") + HexStr(correctIV.begin(), correctIV.end())); + HexStr(crypt.vchIV) + std::string(" != ") + HexStr(correctIV)); } static void TestPassphrase(const std::vector& vchSalt, const SecureString& passphrase, uint32_t rounds,