Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 1,116 Lines • ▼ Show 20 Lines | try { | ||||
} else { | } else { | ||||
if (!IsHex(output)) { | if (!IsHex(output)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid scriptPubKey"); | "Invalid scriptPubKey"); | ||||
} | } | ||||
std::vector<uint8_t> vData(ParseHex(output)); | std::vector<uint8_t> vData(ParseHex(output)); | ||||
script = CScript(vData.begin(), vData.end()); | 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 | // Watchonly and private keys | ||||
if (watchOnly && keys.size()) { | if (watchOnly && keys.size()) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_PARAMETER, | RPC_INVALID_PARAMETER, | ||||
"Incompatibility found between watchonly and keys"); | "Incompatibility found between watchonly and keys"); | ||||
} | } | ||||
// Internal + Label | // Internal + Label | ||||
if (internal && data.exists("label")) { | if (internal && data.exists("label")) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_PARAMETER, | RPC_INVALID_PARAMETER, | ||||
"Incompatibility found between internal and label"); | "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. | // Keys / PubKeys size check. | ||||
if (!isP2SH && | if (!isP2SH && | ||||
(keys.size() > 1 || pubKeys.size() > 1)) { // Address / scriptPubKey | (keys.size() > 1 || pubKeys.size() > 1)) { // Address / scriptPubKey | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"More than private key given for one address"); | "More than private key given for one address"); | ||||
} | } | ||||
// Invalid P2SH redeemScript | // Invalid P2SH redeemScript | ||||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | try { | ||||
if (!pubKey.IsFullyValid()) { | if (!pubKey.IsFullyValid()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Pubkey is not a valid public key"); | "Pubkey is not a valid public key"); | ||||
} | } | ||||
CTxDestination pubkey_dest = pubKey.GetID(); | CTxDestination pubkey_dest = pubKey.GetID(); | ||||
// Consistency check. | // 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, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Consistency check failed"); | "Consistency check failed"); | ||||
} | } | ||||
} | |||||
} | |||||
CScript pubKeyScript = GetScriptForDestination(pubkey_dest); | CScript pubKeyScript = GetScriptForDestination(pubkey_dest); | ||||
if (::IsMine(*pwallet, pubKeyScript) == ISMINE_SPENDABLE) { | if (::IsMine(*pwallet, pubKeyScript) == ISMINE_SPENDABLE) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already " | throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already " | ||||
"contains the private " | "contains the private " | ||||
"key for this address " | "key for this address " | ||||
"or script"); | "or script"); | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | try { | ||||
} | } | ||||
CPubKey pubKey = key.GetPubKey(); | CPubKey pubKey = key.GetPubKey(); | ||||
assert(key.VerifyPubKey(pubKey)); | assert(key.VerifyPubKey(pubKey)); | ||||
CTxDestination pubkey_dest = pubKey.GetID(); | CTxDestination pubkey_dest = pubKey.GetID(); | ||||
// Consistency check. | // Consistency check. | ||||
if (!isScript && !(pubkey_dest == dest)) { | if (!(pubkey_dest == dest)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Consistency check failed"); | "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(); | CKeyID vchAddress = pubKey.GetID(); | ||||
pwallet->MarkDirty(); | pwallet->MarkDirty(); | ||||
pwallet->SetAddressBook(vchAddress, label, "receive"); | pwallet->SetAddressBook(vchAddress, label, "receive"); | ||||
if (pwallet->HaveKey(vchAddress)) { | if (pwallet->HaveKey(vchAddress)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already " | throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already " | ||||
"contains the private " | "contains the private " | ||||
"key for this address " | "key for this address " | ||||
Show All 23 Lines | try { | ||||
pwallet->MarkDirty(); | pwallet->MarkDirty(); | ||||
if (!pwallet->AddWatchOnly(script, timestamp)) { | if (!pwallet->AddWatchOnly(script, timestamp)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error adding address to wallet"); | "Error adding address to wallet"); | ||||
} | } | ||||
if (scriptPubKey.getType() == UniValue::VOBJ) { | if (!internal) { | ||||
nakihito: This is a reapplication of https://github.com/bitcoin/bitcoin/pull/14679/files#diff… | |||||
// add to address book or update label | // add to address book or update label | ||||
if (IsValidDestination(dest)) { | if (IsValidDestination(dest)) { | ||||
pwallet->SetAddressBook(dest, label, "receive"); | pwallet->SetAddressBook(dest, label, "receive"); | ||||
} | } | ||||
} | } | ||||
success = true; | success = true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 334 Lines • Show Last 20 Lines |
This is a reapplication of https://github.com/bitcoin/bitcoin/pull/14679/files#diff-522490d83dce5375d423b23886e4125eR997-R999.