Skip to content

Commit

Permalink
Remove createwitnessaddress
Browse files Browse the repository at this point in the history
This RPC command is unsafe as it will return an address even if the script is invalid.

Github-Pull: #8699
Rebased-From: 86c3f8d
  • Loading branch information
jl2012 authored and laanwj committed Sep 26, 2016
1 parent b394a96 commit a5ec248
Showing 1 changed file with 0 additions and 38 deletions.
38 changes: 0 additions & 38 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,43 +320,6 @@ UniValue createmultisig(const UniValue& params, bool fHelp)
return result;
}

UniValue createwitnessaddress(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 1)
{
string msg = "createwitnessaddress \"script\"\n"
"\nCreates a witness address for a particular script.\n"
"It returns a json object with the address and witness script.\n"

"\nArguments:\n"
"1. \"script\" (string, required) A hex encoded script\n"

"\nResult:\n"
"{\n"
" \"address\":\"multisigaddress\", (string) The value of the new address (P2SH of witness script).\n"
" \"witnessScript\":\"script\" (string) The string value of the hex-encoded witness script.\n"
"}\n"
;
throw runtime_error(msg);
}

if (!IsHex(params[0].get_str())) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Script must be hex-encoded");
}

std::vector<unsigned char> code = ParseHex(params[0].get_str());
CScript script(code.begin(), code.end());
CScript witscript = GetScriptForWitness(script);
CScriptID witscriptid(witscript);
CBitcoinAddress address(witscriptid);

UniValue result(UniValue::VOBJ);
result.push_back(Pair("address", address.ToString()));
result.push_back(Pair("witnessScript", HexStr(witscript.begin(), witscript.end())));

return result;
}

UniValue verifymessage(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 3)
Expand Down Expand Up @@ -490,7 +453,6 @@ static const CRPCCommand commands[] =
{ "control", "getinfo", &getinfo, true }, /* uses wallet if enabled */
{ "util", "validateaddress", &validateaddress, true }, /* uses wallet if enabled */
{ "util", "createmultisig", &createmultisig, true },
{ "util", "createwitnessaddress", &createwitnessaddress, true },
{ "util", "verifymessage", &verifymessage, true },
{ "util", "signmessagewithprivkey", &signmessagewithprivkey, true },

Expand Down

0 comments on commit a5ec248

Please sign in to comment.