mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-12 08:37:58 +02:00
Let wallet importmulti RPC accept labels for standard scriptPubKeys
Allow importmulti RPC to apply address labels when importing standard scriptPubKeys. This makes the importmulti RPC less finnicky about import formats and also simpler internally.
This commit is contained in:
@@ -838,6 +838,9 @@ UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int6
|
||||
|
||||
std::vector<unsigned char> vData(ParseHex(output));
|
||||
script = CScript(vData.begin(), vData.end());
|
||||
if (!ExtractDestination(script, dest) && !internal) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Internal must be set to true for nonstandard scriptPubKey imports.");
|
||||
}
|
||||
}
|
||||
|
||||
// Watchonly and private keys
|
||||
@@ -850,11 +853,6 @@ UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int6
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Incompatibility found between internal and label");
|
||||
}
|
||||
|
||||
// Not having Internal + Script
|
||||
if (!internal && isScript) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Internal must be set for hex scriptPubKey");
|
||||
}
|
||||
|
||||
// Keys / PubKeys size check.
|
||||
if (!isP2SH && (keys.size() > 1 || pubKeys.size() > 1)) { // Address / scriptPubKey
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "More than private key given for one address");
|
||||
@@ -965,21 +963,10 @@ UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int6
|
||||
CTxDestination pubkey_dest = pubKey.GetID();
|
||||
|
||||
// Consistency check.
|
||||
if (!isScript && !(pubkey_dest == dest)) {
|
||||
if (!(pubkey_dest == dest)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Consistency check failed");
|
||||
}
|
||||
|
||||
// Consistency check.
|
||||
if (isScript) {
|
||||
CTxDestination destination;
|
||||
|
||||
if (ExtractDestination(script, destination)) {
|
||||
if (!(destination == pubkey_dest)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Consistency check failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CScript pubKeyScript = GetScriptForDestination(pubkey_dest);
|
||||
|
||||
if (::IsMine(*pwallet, pubKeyScript) == ISMINE_SPENDABLE) {
|
||||
@@ -1036,21 +1023,10 @@ UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int6
|
||||
CTxDestination pubkey_dest = pubKey.GetID();
|
||||
|
||||
// Consistency check.
|
||||
if (!isScript && !(pubkey_dest == dest)) {
|
||||
if (!(pubkey_dest == dest)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Consistency check failed");
|
||||
}
|
||||
|
||||
// Consistency check.
|
||||
if (isScript) {
|
||||
CTxDestination destination;
|
||||
|
||||
if (ExtractDestination(script, destination)) {
|
||||
if (!(destination == pubkey_dest)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Consistency check failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CKeyID vchAddress = pubKey.GetID();
|
||||
pwallet->MarkDirty();
|
||||
pwallet->SetAddressBook(vchAddress, label, "receive");
|
||||
@@ -1082,11 +1058,9 @@ UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int6
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet");
|
||||
}
|
||||
|
||||
if (scriptPubKey.getType() == UniValue::VOBJ) {
|
||||
// add to address book or update label
|
||||
if (IsValidDestination(dest)) {
|
||||
pwallet->SetAddressBook(dest, label, "receive");
|
||||
}
|
||||
// add to address book or update label
|
||||
if (IsValidDestination(dest)) {
|
||||
pwallet->SetAddressBook(dest, label, "receive");
|
||||
}
|
||||
|
||||
success = true;
|
||||
|
||||
Reference in New Issue
Block a user