diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index f9763da996..58896f9452 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -279,11 +279,11 @@ static UniValue createmultisig(const JSONRPCRequest& request) } // Construct using pay-to-script-hash: - CScript inner = CreateMultisigRedeemscript(required, pubkeys); - CScriptID innerID(inner); + CScript inner; + const CTxDestination dest = AddAndGetMultisigDestination(required, pubkeys, inner); UniValue result(UniValue::VOBJ); - result.pushKV("address", EncodeDestination(ScriptHash(innerID))); + result.pushKV("address", EncodeDestination(dest)); result.pushKV("redeemScript", HexStr(inner)); return result; diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 77bee22957..2540b6e6b2 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -209,8 +209,8 @@ CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string& return vchPubKey; } -// Creates a multisig redeemscript from a given list of public keys and number required. -CScript CreateMultisigRedeemscript(const int required, const std::vector& pubkeys) +// Creates a multisig address from a given list of public keys, number of signatures required +CTxDestination AddAndGetMultisigDestination(const int required, const std::vector& pubkeys, CScript& script_out) { // Gather public keys if (required < 1) { @@ -223,13 +223,14 @@ CScript CreateMultisigRedeemscript(const int required, const std::vector 16\nReduce the number"); } - CScript result = GetScriptForMultisig(required, pubkeys); + script_out = GetScriptForMultisig(required, pubkeys); - if (result.size() > MAX_SCRIPT_ELEMENT_SIZE) { - throw JSONRPCError(RPC_INVALID_PARAMETER, (strprintf("redeemScript exceeds size limit: %d > %d", result.size(), MAX_SCRIPT_ELEMENT_SIZE))); + if (script_out.size() > MAX_SCRIPT_ELEMENT_SIZE) { + throw JSONRPCError(RPC_INVALID_PARAMETER, (strprintf("redeemScript exceeds size limit: %d > %d", script_out.size(), MAX_SCRIPT_ELEMENT_SIZE))); } - return result; + // Make the address (simplier implementation in compare to bitcoin) + return ScriptHash(script_out); } class DescribeAddressVisitor diff --git a/src/rpc/util.h b/src/rpc/util.h index 07af6ffb10..16e835f71d 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -84,7 +84,7 @@ extern std::string HelpExampleRpc(const std::string& methodname, const std::stri CPubKey HexToPubKey(const std::string& hex_in); CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string& addr_in); -CScript CreateMultisigRedeemscript(const int required, const std::vector& pubkeys); +CTxDestination AddAndGetMultisigDestination(const int required, const std::vector& pubkeys, CScript& script_out); UniValue DescribeAddress(const CTxDestination& dest); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5118f7401f..72ea43bb1c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1030,14 +1030,15 @@ UniValue addmultisigaddress(const JSONRPCRequest& request) } // Construct using pay-to-script-hash: - CScript inner = CreateMultisigRedeemscript(required, pubkeys); - ScriptHash innerHash(inner); + CScript inner; + CTxDestination dest = AddAndGetMultisigDestination(required, pubkeys, inner); + spk_man.AddCScript(inner); - pwallet->SetAddressBook(innerHash, label, "send"); + pwallet->SetAddressBook(dest, label, "send"); UniValue result(UniValue::VOBJ); - result.pushKV("address", EncodeDestination(innerHash)); + result.pushKV("address", EncodeDestination(dest)); result.pushKV("redeemScript", HexStr(inner)); return result; }