Skip to content

Commit

Permalink
Don't return the address of a P2SH of a P2SH (#1455)
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerlievens authored and UdjinM6 committed May 5, 2017
1 parent b272ae5 commit e99dbe6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/rpcrawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ UniValue decodescript(const UniValue& params, bool fHelp)
" \"address\" (string) dash 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\"")
Expand All @@ -551,7 +551,16 @@ UniValue decodescript(const UniValue& 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;
}

Expand Down

0 comments on commit e99dbe6

Please sign in to comment.