aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorPedro Branco <branco@uphold.com>2016-10-19 15:17:42 +0100
committerPedro Branco <branco@uphold.com>2016-10-19 15:17:42 +0100
commit215caba4ed4547d6f2a0954fa9fe1ae78f4a7c40 (patch)
treeda88271ec1e64d3307c04522c87632791f14a5fb /src/wallet
parentcb08fdbf78685b55029768524ca867772711c32b (diff)
downloadbitcoin-215caba4ed4547d6f2a0954fa9fe1ae78f4a7c40.tar.xz
Add consistency check to RPC call importmulti
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/rpcdump.cpp48
1 files changed, 40 insertions, 8 deletions
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp
index 0297337c2a..7b16b4adfb 100644
--- a/src/wallet/rpcdump.cpp
+++ b/src/wallet/rpcdump.cpp
@@ -641,9 +641,6 @@ UniValue dumpwallet(const JSONRPCRequest& request)
UniValue processImport(const UniValue& data) {
- // TODO List:
- // - Check consistency between pubkeys/privkeys and scriptPubKey/redeemScript.
-
try {
bool success = false;
@@ -713,8 +710,6 @@ UniValue processImport(const UniValue& data) {
// P2SH
if (isP2SH) {
- // TODO: check consistency between private keys and p2sh redeemscript + p2sh address
-
// Import redeem script.
std::vector<unsigned char> vData(ParseHex(strRedeemScript));
CScript redeemScript = CScript(vData.begin(), vData.end());
@@ -795,8 +790,6 @@ UniValue processImport(const UniValue& data) {
success = true;
} else {
- // TODO: check consistency between private/public keys and scriptPubKey / address
-
// Import public keys.
if (pubKeys.size() && keys.size() == 0) {
const string& strPubKey = pubKeys[0].get_str();
@@ -813,6 +806,25 @@ UniValue processImport(const UniValue& data) {
}
CBitcoinAddress pubKeyAddress = CBitcoinAddress(pubKey.GetID());
+
+ // Consistency check.
+ if (!isScript && pubKeyAddress.Get() != address.Get()) {
+ throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Consistency check failed");
+ }
+
+ // Consistency check.
+ if (isScript) {
+ CBitcoinAddress scriptAddress;
+ CTxDestination destination;
+
+ if (ExtractDestination(script, destination)) {
+ scriptAddress = CBitcoinAddress(destination);
+ if (scriptAddress.Get() != pubKeyAddress.Get()) {
+ throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Consistency check failed");
+ }
+ }
+ }
+
CScript pubKeyScript = GetScriptForDestination(pubKeyAddress.Get());
if (::IsMine(*pwalletMain, pubKeyScript) == ISMINE_SPENDABLE) {
@@ -866,7 +878,27 @@ UniValue processImport(const UniValue& data) {
CPubKey pubKey = key.GetPubKey();
assert(key.VerifyPubKey(pubKey));
- CKeyID vchAddress = pubkey.GetID();
+ CBitcoinAddress pubKeyAddress = CBitcoinAddress(pubKey.GetID());
+
+ // Consistency check.
+ if (!isScript && pubKeyAddress.Get() != address.Get()) {
+ throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Consistency check failed");
+ }
+
+ // Consistency check.
+ if (isScript) {
+ CBitcoinAddress scriptAddress;
+ CTxDestination destination;
+
+ if (ExtractDestination(script, destination)) {
+ scriptAddress = CBitcoinAddress(destination);
+ if (scriptAddress.Get() != pubKeyAddress.Get()) {
+ throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Consistency check failed");
+ }
+ }
+ }
+
+ CKeyID vchAddress = pubKey.GetID();
pwalletMain->MarkDirty();
pwalletMain->SetAddressBook(vchAddress, label, "receive");