Skip to content

Commit 1d048b9

Browse files
jnewberylaanwj
authored andcommitted
Don't return the address of a P2SH of a P2SH.
Github-Pull: #8845 Rebased-From: d51f18246165b580761af824f1bb4a49b6908f28
1 parent ce0d817 commit 1d048b9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ UniValue decodescript(const UniValue& params, bool fHelp)
535535
" \"address\" (string) bitcoin address\n"
536536
" ,...\n"
537537
" ],\n"
538-
" \"p2sh\",\"address\" (string) script address\n"
538+
" \"p2sh\",\"address\" (string) address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH).\n"
539539
"}\n"
540540
"\nExamples:\n"
541541
+ HelpExampleCli("decodescript", "\"hexstring\"")
@@ -554,7 +554,15 @@ UniValue decodescript(const UniValue& params, bool fHelp)
554554
}
555555
ScriptPubKeyToJSON(script, r, false);
556556

557-
r.push_back(Pair("p2sh", CBitcoinAddress(CScriptID(script)).ToString()));
557+
UniValue type;
558+
type = find_value(r, "type");
559+
560+
if (type.isStr() && type.get_str() != "scripthash") {
561+
// P2SH cannot be wrapped in a P2SH. If this script is already a P2SH,
562+
// don't return the address for a P2SH of the P2SH.
563+
r.push_back(Pair("p2sh", CBitcoinAddress(CScriptID(script)).ToString()));
564+
}
565+
558566
return r;
559567
}
560568

0 commit comments

Comments
 (0)