Skip to content

Commit

Permalink
Output a descriptor in createmultisig and addmultisigaddress
Browse files Browse the repository at this point in the history
  • Loading branch information
achow101 committed Jan 30, 2020
1 parent 3b69310 commit f529fe0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/rpc/misc.cpp
Expand Up @@ -83,6 +83,7 @@ static UniValue createmultisig(const JSONRPCRequest& request)
"{\n"
" \"address\":\"multisigaddress\", (string) The value of the new multisig address.\n"
" \"redeemScript\":\"script\" (string) The string value of the hex-encoded redemption script.\n"
" \"descriptor\":\"descriptor\" (string) The descriptor for the P2SH address for this multisig\n"
"}\n"
},
RPCExamples{
Expand Down Expand Up @@ -119,9 +120,13 @@ static UniValue createmultisig(const JSONRPCRequest& request)
CScript inner;
const CTxDestination dest = AddAndGetMultisigDestination(required, pubkeys, output_type, keystore, inner);

// Make the descriptor
std::unique_ptr<Descriptor> descriptor = InferDescriptor(GetScriptForDestination(dest), keystore);

UniValue result(UniValue::VOBJ);
result.pushKV("address", EncodeDestination(dest));
result.pushKV("redeemScript", HexStr(inner.begin(), inner.end()));
result.pushKV("descriptor", descriptor->ToString());

return result;
}
Expand Down
5 changes: 5 additions & 0 deletions src/wallet/rpcwallet.cpp
Expand Up @@ -974,6 +974,7 @@ static UniValue addmultisigaddress(const JSONRPCRequest& request)
"{\n"
" \"address\":\"multisigaddress\", (string) The value of the new multisig address.\n"
" \"redeemScript\":\"script\" (string) The string value of the hex-encoded redemption script.\n"
" \"descriptor\":\"descriptor\" (string) The descriptor for the P2SH address for this multisig\n"
"}\n"
},
RPCExamples{
Expand Down Expand Up @@ -1018,9 +1019,13 @@ static UniValue addmultisigaddress(const JSONRPCRequest& request)
CTxDestination dest = AddAndGetMultisigDestination(required, pubkeys, output_type, spk_man, inner);
pwallet->SetAddressBook(dest, label, "send");

// Make the descriptor
std::unique_ptr<Descriptor> descriptor = InferDescriptor(GetScriptForDestination(dest), spk_man);

UniValue result(UniValue::VOBJ);
result.pushKV("address", EncodeDestination(dest));
result.pushKV("redeemScript", HexStr(inner.begin(), inner.end()));
result.pushKV("descriptor", descriptor->ToString());
return result;
}

Expand Down
12 changes: 12 additions & 0 deletions test/functional/rpc_createmultisig.py
Expand Up @@ -116,16 +116,28 @@ def checkbalances(self):
def do_multisig(self):
node0, node1, node2 = self.nodes

# Construct the expected descriptor
desc = 'multi({},{})'.format(self.nsigs, ','.join(self.pub))
if self.output_type == 'legacy':
desc = 'sh({})'.format(desc)
elif self.output_type == 'p2sh-segwit':
desc = 'sh(wsh({}))'.format(desc)
elif self.output_type == 'bech32':
desc = 'wsh({})'.format(desc)
desc = descsum_create(desc)

msig = node2.createmultisig(self.nsigs, self.pub, self.output_type)
madd = msig["address"]
mredeem = msig["redeemScript"]
assert_equal(desc, msig['descriptor'])
if self.output_type == 'bech32':
assert madd[0:4] == "bcrt" # actually a bech32 address

# compare against addmultisigaddress
msigw = node1.addmultisigaddress(self.nsigs, self.pub, None, self.output_type)
maddw = msigw["address"]
mredeemw = msigw["redeemScript"]
assert_equal(desc, msig['descriptor'])
# addmultisigiaddress and createmultisig work the same
assert maddw == madd
assert mredeemw == mredeem
Expand Down

0 comments on commit f529fe0

Please sign in to comment.