diff options
author | Samuel Dobson <dobsonsa68@gmail.com> | 2021-09-28 15:08:13 +1300 |
---|---|---|
committer | Samuel Dobson <dobsonsa68@gmail.com> | 2021-12-08 17:11:46 +1300 |
commit | d1a9742623e2a8f3307c84c2df6993f62617a6f6 (patch) | |
tree | ea7492b6ab42700a29dbfa78c3e4823f11b1114a | |
parent | fa3fb46b8172597cb64ff401b27f6c799fb832d7 (diff) | |
download | bitcoin-d1a9742623e2a8f3307c84c2df6993f62617a6f6.tar.xz |
Add warnings field to createmultisig to warn about uncompressed keys
-rw-r--r-- | src/rpc/misc.cpp | 11 | ||||
-rwxr-xr-x | test/functional/rpc_createmultisig.py | 7 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 2c05fc39fd..762f6665da 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -113,6 +113,10 @@ static RPCHelpMan createmultisig() {RPCResult::Type::STR, "address", "The value of the new multisig address."}, {RPCResult::Type::STR_HEX, "redeemScript", "The string value of the hex-encoded redemption script."}, {RPCResult::Type::STR, "descriptor", "The descriptor for this multisig"}, + {RPCResult::Type::ARR, "warnings", /* optional */ true, "Any warnings resulting from the creation of this multisig", + { + {RPCResult::Type::STR, "", ""}, + }}, } }, RPCExamples{ @@ -161,6 +165,13 @@ static RPCHelpMan createmultisig() result.pushKV("redeemScript", HexStr(inner)); result.pushKV("descriptor", descriptor->ToString()); + UniValue warnings(UniValue::VARR); + if (!request.params[2].isNull() && OutputTypeFromDestination(dest) != output_type) { + // Only warns if the user has explicitly chosen an address type we cannot generate + warnings.push_back("Unable to make chosen address type, please ensure no uncompressed public keys are present."); + } + if (warnings.size()) result.pushKV("warnings", warnings); + return result; }, }; diff --git a/test/functional/rpc_createmultisig.py b/test/functional/rpc_createmultisig.py index f56e71ae7a..fb5964595a 100755 --- a/test/functional/rpc_createmultisig.py +++ b/test/functional/rpc_createmultisig.py @@ -78,8 +78,11 @@ class RpcCreateMultiSigTest(BitcoinTestFramework): assert_equal(legacy_addr, wmulti0.addmultisigaddress(2, keys, '', 'legacy')['address']) # Generate addresses with the segwit types. These should all make legacy addresses - assert_equal(legacy_addr, wmulti0.createmultisig(2, keys, 'bech32')['address']) - assert_equal(legacy_addr, wmulti0.createmultisig(2, keys, 'p2sh-segwit')['address']) + for addr_type in ['bech32', 'p2sh-segwit']: + result = wmulti0.createmultisig(2, keys, addr_type) + assert_equal(legacy_addr, result['address']) + assert_equal(result['warnings'], ["Unable to make chosen address type, please ensure no uncompressed public keys are present."]) + assert_equal(legacy_addr, wmulti0.addmultisigaddress(2, keys, '', 'bech32')['address']) assert_equal(legacy_addr, wmulti0.addmultisigaddress(2, keys, '', 'p2sh-segwit')['address']) |