Skip to content

Commit 595b22e

Browse files
committed
Stop treating importaddress'ed scripts as change
Before this, if someone imported a scriptPubKey directly (in hex form) using importaddress, outputs sending to it would be treated as change, as the corresponding CTxDestination was not added to the address book. Fix this by trying to detect scriptPubKeys that are in fact convertible to a CTxDestination and add them anyway. Add a warning to the RPC help to warn against importing raw non-standard scripts.
1 parent 7fa8d75 commit 595b22e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/wallet/rpcdump.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ void ImportScript(const CScript& script, const string& strLabel, bool isRedeemSc
167167
if (!pwalletMain->HaveCScript(script) && !pwalletMain->AddCScript(script))
168168
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding p2sh redeemScript to wallet");
169169
ImportAddress(CBitcoinAddress(CScriptID(script)), strLabel);
170+
} else {
171+
CTxDestination destination;
172+
if (ExtractDestination(script, destination)) {
173+
pwalletMain->SetAddressBook(destination, strLabel, "receive");
174+
}
170175
}
171176
}
172177

@@ -195,6 +200,8 @@ UniValue importaddress(const UniValue& params, bool fHelp)
195200
"4. p2sh (boolean, optional, default=false) Add the P2SH version of the script as well\n"
196201
"\nNote: This call can take minutes to complete if rescan is true.\n"
197202
"If you have the full public key, you should call importpubkey instead of this.\n"
203+
"\nNote: If you import a non-standard raw script in hex form, outputs sending to it will be treated\n"
204+
"as change, and not show up in many RPCs.\n"
198205
"\nExamples:\n"
199206
"\nImport a script with rescan\n"
200207
+ HelpExampleCli("importaddress", "\"myscript\"") +

0 commit comments

Comments
 (0)