From fa05dddc42770809fdae4d9c35155f8117960019 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 30 Apr 2021 15:32:40 +0200 Subject: refactor: Use CPubKey vector constructor where possible --- src/compressor.cpp | 2 +- src/pubkey.h | 2 +- src/script/descriptor.cpp | 4 ++-- src/wallet/rpcdump.cpp | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/compressor.cpp b/src/compressor.cpp index ef3135e7a5..a161c42866 100644 --- a/src/compressor.cpp +++ b/src/compressor.cpp @@ -124,7 +124,7 @@ bool DecompressScript(CScript& script, unsigned int nSize, const CompressedScrip unsigned char vch[33] = {}; vch[0] = nSize - 2; memcpy(&vch[1], in.data(), 32); - CPubKey pubkey(&vch[0], &vch[33]); + CPubKey pubkey{vch}; if (!pubkey.Decompress()) return false; assert(pubkey.size() == 65); diff --git a/src/pubkey.h b/src/pubkey.h index 12514fc3c9..066d2d5d48 100644 --- a/src/pubkey.h +++ b/src/pubkey.h @@ -101,7 +101,7 @@ public: } //! Construct a public key from a byte vector. - explicit CPubKey(const std::vector& _vch) + explicit CPubKey(Span _vch) { Set(_vch.begin(), _vch.end()); } diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index e433ed6764..b54ba204f0 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -1098,7 +1098,7 @@ std::unique_ptr InferScript(const CScript& script, ParseScriptCo TxoutType txntype = Solver(script, data); if (txntype == TxoutType::PUBKEY) { - CPubKey pubkey(data[0].begin(), data[0].end()); + CPubKey pubkey(data[0]); if (pubkey.IsValid()) { return std::make_unique(InferPubkey(pubkey, ctx, provider)); } @@ -1122,7 +1122,7 @@ std::unique_ptr InferScript(const CScript& script, ParseScriptCo if (txntype == TxoutType::MULTISIG) { std::vector> providers; for (size_t i = 1; i + 1 < data.size(); ++i) { - CPubKey pubkey(data[i].begin(), data[i].end()); + CPubKey pubkey(data[i]); providers.push_back(InferPubkey(pubkey, ctx, provider)); } return std::make_unique((int)data[0][0], std::move(providers)); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 653dbdfc1d..a851765c57 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -469,7 +469,7 @@ RPCHelpMan importpubkey() if (!IsHex(request.params[0].get_str())) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey must be a hex string"); std::vector data(ParseHex(request.params[0].get_str())); - CPubKey pubKey(data.begin(), data.end()); + CPubKey pubKey(data); if (!pubKey.IsFullyValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey is not a valid public key"); @@ -871,7 +871,7 @@ static std::string RecurseImportData(const CScript& script, ImportData& import_d switch (script_type) { case TxoutType::PUBKEY: { - CPubKey pubkey(solverdata[0].begin(), solverdata[0].end()); + CPubKey pubkey(solverdata[0]); import_data.used_keys.emplace(pubkey.GetID(), false); return ""; } @@ -893,7 +893,7 @@ static std::string RecurseImportData(const CScript& script, ImportData& import_d } case TxoutType::MULTISIG: { for (size_t i = 1; i + 1< solverdata.size(); ++i) { - CPubKey pubkey(solverdata[i].begin(), solverdata[i].end()); + CPubKey pubkey(solverdata[i]); import_data.used_keys.emplace(pubkey.GetID(), false); } return ""; @@ -997,7 +997,7 @@ static UniValue ProcessImportLegacy(ImportData& import_data, std::map