Skip to content

Commit fa05ddd

Browse files
author
MarcoFalke
committed
refactor: Use CPubKey vector constructor where possible
1 parent fabb6df commit fa05ddd

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/compressor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ bool DecompressScript(CScript& script, unsigned int nSize, const CompressedScrip
124124
unsigned char vch[33] = {};
125125
vch[0] = nSize - 2;
126126
memcpy(&vch[1], in.data(), 32);
127-
CPubKey pubkey(&vch[0], &vch[33]);
127+
CPubKey pubkey{vch};
128128
if (!pubkey.Decompress())
129129
return false;
130130
assert(pubkey.size() == 65);

src/pubkey.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class CPubKey
101101
}
102102

103103
//! Construct a public key from a byte vector.
104-
explicit CPubKey(const std::vector<unsigned char>& _vch)
104+
explicit CPubKey(Span<const uint8_t> _vch)
105105
{
106106
Set(_vch.begin(), _vch.end());
107107
}

src/script/descriptor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ std::unique_ptr<DescriptorImpl> InferScript(const CScript& script, ParseScriptCo
10981098
TxoutType txntype = Solver(script, data);
10991099

11001100
if (txntype == TxoutType::PUBKEY) {
1101-
CPubKey pubkey(data[0].begin(), data[0].end());
1101+
CPubKey pubkey(data[0]);
11021102
if (pubkey.IsValid()) {
11031103
return std::make_unique<PKDescriptor>(InferPubkey(pubkey, ctx, provider));
11041104
}
@@ -1122,7 +1122,7 @@ std::unique_ptr<DescriptorImpl> InferScript(const CScript& script, ParseScriptCo
11221122
if (txntype == TxoutType::MULTISIG) {
11231123
std::vector<std::unique_ptr<PubkeyProvider>> providers;
11241124
for (size_t i = 1; i + 1 < data.size(); ++i) {
1125-
CPubKey pubkey(data[i].begin(), data[i].end());
1125+
CPubKey pubkey(data[i]);
11261126
providers.push_back(InferPubkey(pubkey, ctx, provider));
11271127
}
11281128
return std::make_unique<MultisigDescriptor>((int)data[0][0], std::move(providers));

src/wallet/rpcdump.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ RPCHelpMan importpubkey()
469469
if (!IsHex(request.params[0].get_str()))
470470
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey must be a hex string");
471471
std::vector<unsigned char> data(ParseHex(request.params[0].get_str()));
472-
CPubKey pubKey(data.begin(), data.end());
472+
CPubKey pubKey(data);
473473
if (!pubKey.IsFullyValid())
474474
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey is not a valid public key");
475475

@@ -871,7 +871,7 @@ static std::string RecurseImportData(const CScript& script, ImportData& import_d
871871

872872
switch (script_type) {
873873
case TxoutType::PUBKEY: {
874-
CPubKey pubkey(solverdata[0].begin(), solverdata[0].end());
874+
CPubKey pubkey(solverdata[0]);
875875
import_data.used_keys.emplace(pubkey.GetID(), false);
876876
return "";
877877
}
@@ -893,7 +893,7 @@ static std::string RecurseImportData(const CScript& script, ImportData& import_d
893893
}
894894
case TxoutType::MULTISIG: {
895895
for (size_t i = 1; i + 1< solverdata.size(); ++i) {
896-
CPubKey pubkey(solverdata[i].begin(), solverdata[i].end());
896+
CPubKey pubkey(solverdata[i]);
897897
import_data.used_keys.emplace(pubkey.GetID(), false);
898898
}
899899
return "";
@@ -997,7 +997,7 @@ static UniValue ProcessImportLegacy(ImportData& import_data, std::map<CKeyID, CP
997997
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey \"" + str + "\" must be a hex string");
998998
}
999999
auto parsed_pubkey = ParseHex(str);
1000-
CPubKey pubkey(parsed_pubkey.begin(), parsed_pubkey.end());
1000+
CPubKey pubkey(parsed_pubkey);
10011001
if (!pubkey.IsFullyValid()) {
10021002
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey \"" + str + "\" is not a valid public key");
10031003
}

0 commit comments

Comments
 (0)