refactor: Use CPubKey vector constructor where possible

pull/21817/head
MarcoFalke 4 years ago
parent fabb6dfe6e
commit fa05dddc42
No known key found for this signature in database
GPG Key ID: CE2B75697E69A548

@ -124,7 +124,7 @@ bool DecompressScript(CScript& script, unsigned int nSize, const CompressedScrip
unsigned char vch[33] = {}; unsigned char vch[33] = {};
vch[0] = nSize - 2; vch[0] = nSize - 2;
memcpy(&vch[1], in.data(), 32); memcpy(&vch[1], in.data(), 32);
CPubKey pubkey(&vch[0], &vch[33]); CPubKey pubkey{vch};
if (!pubkey.Decompress()) if (!pubkey.Decompress())
return false; return false;
assert(pubkey.size() == 65); assert(pubkey.size() == 65);

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

@ -1098,7 +1098,7 @@ std::unique_ptr<DescriptorImpl> InferScript(const CScript& script, ParseScriptCo
TxoutType txntype = Solver(script, data); TxoutType txntype = Solver(script, data);
if (txntype == TxoutType::PUBKEY) { if (txntype == TxoutType::PUBKEY) {
CPubKey pubkey(data[0].begin(), data[0].end()); CPubKey pubkey(data[0]);
if (pubkey.IsValid()) { if (pubkey.IsValid()) {
return std::make_unique<PKDescriptor>(InferPubkey(pubkey, ctx, provider)); return std::make_unique<PKDescriptor>(InferPubkey(pubkey, ctx, provider));
} }
@ -1122,7 +1122,7 @@ std::unique_ptr<DescriptorImpl> InferScript(const CScript& script, ParseScriptCo
if (txntype == TxoutType::MULTISIG) { if (txntype == TxoutType::MULTISIG) {
std::vector<std::unique_ptr<PubkeyProvider>> providers; std::vector<std::unique_ptr<PubkeyProvider>> providers;
for (size_t i = 1; i + 1 < data.size(); ++i) { 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)); providers.push_back(InferPubkey(pubkey, ctx, provider));
} }
return std::make_unique<MultisigDescriptor>((int)data[0][0], std::move(providers)); return std::make_unique<MultisigDescriptor>((int)data[0][0], std::move(providers));

@ -469,7 +469,7 @@ RPCHelpMan importpubkey()
if (!IsHex(request.params[0].get_str())) if (!IsHex(request.params[0].get_str()))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey must be a hex string"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey must be a hex string");
std::vector<unsigned char> data(ParseHex(request.params[0].get_str())); std::vector<unsigned char> data(ParseHex(request.params[0].get_str()));
CPubKey pubKey(data.begin(), data.end()); CPubKey pubKey(data);
if (!pubKey.IsFullyValid()) if (!pubKey.IsFullyValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey is not a valid public key"); 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) { switch (script_type) {
case TxoutType::PUBKEY: { case TxoutType::PUBKEY: {
CPubKey pubkey(solverdata[0].begin(), solverdata[0].end()); CPubKey pubkey(solverdata[0]);
import_data.used_keys.emplace(pubkey.GetID(), false); import_data.used_keys.emplace(pubkey.GetID(), false);
return ""; return "";
} }
@ -893,7 +893,7 @@ static std::string RecurseImportData(const CScript& script, ImportData& import_d
} }
case TxoutType::MULTISIG: { case TxoutType::MULTISIG: {
for (size_t i = 1; i + 1< solverdata.size(); ++i) { 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); import_data.used_keys.emplace(pubkey.GetID(), false);
} }
return ""; return "";
@ -997,7 +997,7 @@ static UniValue ProcessImportLegacy(ImportData& import_data, std::map<CKeyID, CP
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey \"" + str + "\" must be a hex string"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey \"" + str + "\" must be a hex string");
} }
auto parsed_pubkey = ParseHex(str); auto parsed_pubkey = ParseHex(str);
CPubKey pubkey(parsed_pubkey.begin(), parsed_pubkey.end()); CPubKey pubkey(parsed_pubkey);
if (!pubkey.IsFullyValid()) { if (!pubkey.IsFullyValid()) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey \"" + str + "\" is not a valid public key"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey \"" + str + "\" is not a valid public key");
} }

Loading…
Cancel
Save