Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 1,109 Lines • ▼ Show 20 Lines | |||||
// Analyse the provided scriptPubKey, determining which keys and which redeem | // Analyse the provided scriptPubKey, determining which keys and which redeem | ||||
// scripts from the ImportData struct are needed to spend it, and mark them as | // scripts from the ImportData struct are needed to spend it, and mark them as | ||||
// used. Returns an error string, or the empty string for success. | // used. Returns an error string, or the empty string for success. | ||||
static std::string RecurseImportData(const CScript &script, | static std::string RecurseImportData(const CScript &script, | ||||
ImportData &import_data, | ImportData &import_data, | ||||
const ScriptContext script_ctx) { | const ScriptContext script_ctx) { | ||||
// Use Solver to obtain script type and parsed pubkeys or hashes: | // Use Solver to obtain script type and parsed pubkeys or hashes: | ||||
std::vector<std::vector<uint8_t>> solverdata; | std::vector<std::vector<uint8_t>> solverdata; | ||||
txnouttype script_type = Solver(script, solverdata); | TxoutType script_type = Solver(script, solverdata); | ||||
switch (script_type) { | switch (script_type) { | ||||
case TX_PUBKEY: { | case TxoutType::PUBKEY: { | ||||
CPubKey pubkey(solverdata[0].begin(), solverdata[0].end()); | CPubKey pubkey(solverdata[0].begin(), solverdata[0].end()); | ||||
import_data.used_keys.emplace(pubkey.GetID(), false); | import_data.used_keys.emplace(pubkey.GetID(), false); | ||||
return ""; | return ""; | ||||
} | } | ||||
case TX_PUBKEYHASH: { | case TxoutType::PUBKEYHASH: { | ||||
CKeyID id = CKeyID(uint160(solverdata[0])); | CKeyID id = CKeyID(uint160(solverdata[0])); | ||||
import_data.used_keys[id] = true; | import_data.used_keys[id] = true; | ||||
return ""; | return ""; | ||||
} | } | ||||
case TX_SCRIPTHASH: { | case TxoutType::SCRIPTHASH: { | ||||
if (script_ctx == ScriptContext::P2SH) { | if (script_ctx == ScriptContext::P2SH) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Trying to nest P2SH inside another P2SH"); | "Trying to nest P2SH inside another P2SH"); | ||||
} | } | ||||
CHECK_NONFATAL(script_ctx == ScriptContext::TOP); | CHECK_NONFATAL(script_ctx == ScriptContext::TOP); | ||||
CScriptID id = CScriptID(uint160(solverdata[0])); | CScriptID id = CScriptID(uint160(solverdata[0])); | ||||
// Remove redeemscript from import_data to check for superfluous | // Remove redeemscript from import_data to check for superfluous | ||||
// script later. | // script later. | ||||
auto subscript = std::move(import_data.redeemscript); | auto subscript = std::move(import_data.redeemscript); | ||||
if (!subscript) { | if (!subscript) { | ||||
return "missing redeemscript"; | return "missing redeemscript"; | ||||
} | } | ||||
if (CScriptID(*subscript) != id) { | if (CScriptID(*subscript) != id) { | ||||
return "redeemScript does not match the scriptPubKey"; | return "redeemScript does not match the scriptPubKey"; | ||||
} | } | ||||
import_data.import_scripts.emplace(*subscript); | import_data.import_scripts.emplace(*subscript); | ||||
return RecurseImportData(*subscript, import_data, | return RecurseImportData(*subscript, import_data, | ||||
ScriptContext::P2SH); | ScriptContext::P2SH); | ||||
} | } | ||||
case TX_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].begin(), solverdata[i].end()); | ||||
import_data.used_keys.emplace(pubkey.GetID(), false); | import_data.used_keys.emplace(pubkey.GetID(), false); | ||||
} | } | ||||
return ""; | return ""; | ||||
} | } | ||||
case TX_NULL_DATA: | case TxoutType::NULL_DATA: | ||||
return "unspendable script"; | return "unspendable script"; | ||||
case TX_NONSTANDARD: | case TxoutType::NONSTANDARD: | ||||
default: | default: | ||||
return "unrecognized script"; | return "unrecognized script"; | ||||
} | } | ||||
} | } | ||||
static UniValue ProcessImportLegacy( | static UniValue ProcessImportLegacy( | ||||
CWallet *const pwallet, ImportData &import_data, | CWallet *const pwallet, ImportData &import_data, | ||||
std::map<CKeyID, CPubKey> &pubkey_map, std::map<CKeyID, CKey> &privkey_map, | std::map<CKeyID, CPubKey> &pubkey_map, std::map<CKeyID, CKey> &privkey_map, | ||||
▲ Show 20 Lines • Show All 1,164 Lines • Show Last 20 Lines |