Skip to content

Commit e46fc93

Browse files
committed
Add warnings field to addmultisigaddress to warn about uncompressed keys
1 parent d1a9742 commit e46fc93

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/wallet/rpc/addresses.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ RPCHelpMan addmultisigaddress()
238238
{RPCResult::Type::STR, "address", "The value of the new multisig address"},
239239
{RPCResult::Type::STR_HEX, "redeemScript", "The string value of the hex-encoded redemption script"},
240240
{RPCResult::Type::STR, "descriptor", "The descriptor for this multisig"},
241+
{RPCResult::Type::ARR, "warnings", /* optional */ true, "Any warnings resulting from the creation of this multisig",
242+
{
243+
{RPCResult::Type::STR, "", ""},
244+
}},
241245
}
242246
},
243247
RPCExamples{
@@ -295,6 +299,14 @@ RPCHelpMan addmultisigaddress()
295299
result.pushKV("address", EncodeDestination(dest));
296300
result.pushKV("redeemScript", HexStr(inner));
297301
result.pushKV("descriptor", descriptor->ToString());
302+
303+
UniValue warnings(UniValue::VARR);
304+
if (!request.params[3].isNull() && OutputTypeFromDestination(dest) != output_type) {
305+
// Only warns if the user has explicitly chosen an address type we cannot generate
306+
warnings.push_back("Unable to make chosen address type, please ensure no uncompressed public keys are present.");
307+
}
308+
if (warnings.size()) result.pushKV("warnings", warnings);
309+
298310
return result;
299311
},
300312
};

test/functional/rpc_createmultisig.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,19 @@ def run_test(self):
7575
for keys in itertools.permutations([pk0, pk1, pk2]):
7676
# Results should be the same as this legacy one
7777
legacy_addr = node0.createmultisig(2, keys, 'legacy')['address']
78-
assert_equal(legacy_addr, wmulti0.addmultisigaddress(2, keys, '', 'legacy')['address'])
78+
result = wmulti0.addmultisigaddress(2, keys, '', 'legacy')
79+
assert_equal(legacy_addr, result['address'])
80+
assert 'warnings' not in result
7981

8082
# Generate addresses with the segwit types. These should all make legacy addresses
8183
for addr_type in ['bech32', 'p2sh-segwit']:
8284
result = wmulti0.createmultisig(2, keys, addr_type)
8385
assert_equal(legacy_addr, result['address'])
8486
assert_equal(result['warnings'], ["Unable to make chosen address type, please ensure no uncompressed public keys are present."])
8587

86-
assert_equal(legacy_addr, wmulti0.addmultisigaddress(2, keys, '', 'bech32')['address'])
87-
assert_equal(legacy_addr, wmulti0.addmultisigaddress(2, keys, '', 'p2sh-segwit')['address'])
88+
result = wmulti0.addmultisigaddress(2, keys, '', addr_type)
89+
assert_equal(legacy_addr, result['address'])
90+
assert_equal(result['warnings'], ["Unable to make chosen address type, please ensure no uncompressed public keys are present."])
8891

8992
self.log.info('Testing sortedmulti descriptors with BIP 67 test vectors')
9093
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/rpc_bip67.json'), encoding='utf-8') as f:

0 commit comments

Comments
 (0)