diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2018-07-13 20:26:42 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2018-07-13 20:31:13 -0700 |
commit | b25a4c2284babdf1e8cf0ec3b1402200dd25f33f (patch) | |
tree | b49a711b29e6701947591f27f31c015a61a518e1 /src/rpc | |
parent | 1329ef1f00e4fad83937ddd8721d0292ccfe7808 (diff) | |
parent | f40b3b82dfe873dd55ee24f4d6dec5d43756260a (diff) |
Merge #13072: Update createmultisig RPC to support segwit
f40b3b82df [tests] functional test for createmultisig RPC (Anthony Towns)
b9024fdda3 segwit support for createmultisig RPC (Anthony Towns)
d58055d25f Move AddAndGetDestinationForScript from wallet to outputype module (Anthony Towns)
9a44db2e46 Add outputtype module (Anthony Towns)
Pull request description:
Adds an "address_type" parameter that accepts "legacy", "p2sh-segwit", and "bech32" to choose the type of address created. Defaults to "legacy" rather than the value of the `-address-type` option for backwards compatibility.
As part of implementing this, OutputType is moved from wallet into its own module, and `AddAndGetDestinationForScript` is changed to apply to a `CKeyStore` rather than a wallet, and to invoke `keystore.AddCScript(script)` itself rather than expecting the caller to have done that.
Fixes #12502
Tree-SHA512: a08c1cfa89976e4fd7d29caa90919ebd34a446354d17abb862e99f2ee60ed9bc19d8a21a18547c51dc3812cb9fbed86af0bef2f1e971f62bf95cade4a7d86237
Diffstat (limited to 'src/rpc')
-rw-r--r-- | src/rpc/misc.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 4eeb7f29d2..09812bb980 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -12,6 +12,7 @@ #include <httpserver.h> #include <net.h> #include <netbase.h> +#include <outputtype.h> #include <rpc/blockchain.h> #include <rpc/server.h> #include <rpc/util.h> @@ -91,9 +92,9 @@ class CWallet; static UniValue createmultisig(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 2 || request.params.size() > 2) + if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) { - std::string msg = "createmultisig nrequired [\"key\",...]\n" + std::string msg = "createmultisig nrequired [\"key\",...] ( \"address_type\" )\n" "\nCreates a multi-signature address with n signature of m keys required.\n" "It returns a json object with the address and redeemScript.\n" "\nArguments:\n" @@ -103,6 +104,7 @@ static UniValue createmultisig(const JSONRPCRequest& request) " \"key\" (string) The hex-encoded public key\n" " ,...\n" " ]\n" + "3. \"address_type\" (string, optional) The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\". Default is legacy.\n" "\nResult:\n" "{\n" @@ -133,12 +135,21 @@ static UniValue createmultisig(const JSONRPCRequest& request) } } + // Get the output type + OutputType output_type = OutputType::LEGACY; + if (!request.params[2].isNull()) { + if (!ParseOutputType(request.params[2].get_str(), output_type)) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[2].get_str())); + } + } + // Construct using pay-to-script-hash: - CScript inner = CreateMultisigRedeemscript(required, pubkeys); - CScriptID innerID(inner); + const CScript inner = CreateMultisigRedeemscript(required, pubkeys); + CBasicKeyStore keystore; + const CTxDestination dest = AddAndGetDestinationForScript(keystore, inner, output_type); UniValue result(UniValue::VOBJ); - result.pushKV("address", EncodeDestination(innerID)); + result.pushKV("address", EncodeDestination(dest)); result.pushKV("redeemScript", HexStr(inner.begin(), inner.end())); return result; |