aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2015-12-30 01:13:08 +0100
committerPieter Wuille <pieter.wuille@gmail.com>2016-06-22 15:43:01 +0200
commitf4691ab3a9d4f3321afa024984c03fe6e10bfdbc (patch)
treeaa9a07a6686ab5ed4d570f471bfe530634c11425 /src/rpc
parent605e8473a7ddca13b24a4020c7bd630aa5d374e2 (diff)
[RPC] Add wallet support for witness transactions (using P2SH)
Includes support for pushkeyhash wit v0 by Alex Morcos.
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/misc.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp
index 09f5185781..f2a29416e6 100644
--- a/src/rpc/misc.cpp
+++ b/src/rpc/misc.cpp
@@ -312,6 +312,43 @@ 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)
@@ -445,6 +482,7 @@ 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 },