From 103c724d82a32aeb6787cb87f6ca9defa83f737f Mon Sep 17 00:00:00 2001 From: jnewbery Date: Mon, 26 Sep 2016 17:01:10 -0400 Subject: [PATCH] Bugfix: Don't return the address of a P2SH of a P2SH Github-Pull: #8845 Rebased-From: cef66cbca48fa969c9fb3374f2892202a4fe31ac --- src/rpcrawtransaction.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 8de15ff9e2f7e..e4b5c2d010677 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -461,7 +461,7 @@ Value decodescript(const Array& params, bool fHelp) " \"address\" (string) bitcoin address\n" " ,...\n" " ],\n" - " \"p2sh\",\"address\" (string) script address\n" + " \"p2sh\",\"address\" (string) address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH).\n" "}\n" "\nExamples:\n" + HelpExampleCli("decodescript", "\"hexstring\"") @@ -480,7 +480,15 @@ Value decodescript(const Array& params, bool fHelp) } ScriptPubKeyToJSON(script, r, false); - r.push_back(Pair("p2sh", CBitcoinAddress(CScriptID(script)).ToString())); + UniValue type; + type = find_value(r, "type"); + + if (type.isStr() && type.get_str() != "scripthash") { + // P2SH cannot be wrapped in a P2SH. If this script is already a P2SH, + // don't return the address for a P2SH of the P2SH. + r.push_back(Pair("p2sh", CBitcoinAddress(CScriptID(script)).ToString())); + } + return r; }