-
Notifications
You must be signed in to change notification settings - Fork 38.7k
RPC: Add parameter to addmultisigaddress / createmultisig to sort public keys #8751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5a2da09
RPC: addmultisigaddress / createmultisig: parameterize _createmultisi…
afk11 ee9110a
script: GetScriptForRawPubKey: More efficient key-encoding loop
luke-jr fcbf6cc
doc/bips: Add BIP 67
luke-jr 6fbcf50
Ensure whilst sorting only compressed public keys are used
e11cb50
Add more tests to sort_multisigs.py / wallet-accounts.py
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1139,7 +1139,7 @@ UniValue sendmany(const JSONRPCRequest& request) | |
| } | ||
|
|
||
| // Defined in rpc/misc.cpp | ||
| extern CScript _createmultisig_redeemScript(CWallet * const pwallet, const UniValue& params); | ||
| extern CScript _createmultisig_redeemScript(CWallet * const pwallet, const UniValue& params, bool fSorted); | ||
|
|
||
| UniValue addmultisigaddress(const JSONRPCRequest& request) | ||
| { | ||
|
|
@@ -1148,21 +1148,24 @@ UniValue addmultisigaddress(const JSONRPCRequest& request) | |
| return NullUniValue; | ||
| } | ||
|
|
||
| if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) | ||
| if (request.fHelp || request.params.size() < 2 || request.params.size() > 4) | ||
| { | ||
| std::string msg = "addmultisigaddress nrequired [\"key\",...] ( \"account\" )\n" | ||
| std::string msg = "addmultisigaddress nrequired [\"key\",...] ( \"account\" ) ( sort )\n" | ||
| "\nAdd a nrequired-to-sign multisignature address to the wallet. Requires a new wallet backup.\n" | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This blank line won't be in the actual help, so has no purpose here. |
||
| "Each key is a Bitcoin address or hex-encoded public key.\n" | ||
| "If 'account' is specified (DEPRECATED), assign address to that account.\n" | ||
| "Public keys can be sorted according to BIP67 during the request if required.\n" | ||
|
|
||
| "\nArguments:\n" | ||
| "1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n" | ||
| "1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n" | ||
| "2. \"keys\" (string, required) A json array of bitcoin addresses or hex-encoded public keys\n" | ||
| " [\n" | ||
| " \"address\" (string) bitcoin address or hex-encoded public key\n" | ||
| " ...,\n" | ||
| " ]\n" | ||
| "3. \"account\" (string, optional) DEPRECATED. An account to assign the addresses to.\n" | ||
| "4. sort (bool, optional) Whether to sort public keys according to BIP67. Default setting is false.\n" | ||
|
|
||
| "\nResult:\n" | ||
| "\"address\" (string) A bitcoin address associated with the keys.\n" | ||
|
|
@@ -1182,8 +1185,10 @@ UniValue addmultisigaddress(const JSONRPCRequest& request) | |
| if (!request.params[2].isNull()) | ||
| strAccount = AccountFromValue(request.params[2]); | ||
|
|
||
| bool fSorted = request.params.size() > 3 && request.params[3].get_bool(); | ||
|
|
||
| // Construct using pay-to-script-hash: | ||
| CScript inner = _createmultisig_redeemScript(pwallet, request.params); | ||
| CScript inner = _createmultisig_redeemScript(pwallet, request.params, fSorted); | ||
| CScriptID innerID(inner); | ||
| pwallet->AddCScript(inner); | ||
|
|
||
|
|
@@ -3445,7 +3450,7 @@ static const CRPCCommand commands[] = | |
| { "hidden", "resendwallettransactions", &resendwallettransactions, {} }, | ||
| { "wallet", "abandontransaction", &abandontransaction, {"txid"} }, | ||
| { "wallet", "abortrescan", &abortrescan, {} }, | ||
| { "wallet", "addmultisigaddress", &addmultisigaddress, {"nrequired","keys","account"} }, | ||
| { "wallet", "addmultisigaddress", &addmultisigaddress, {"nrequired","keys","account","sort"} }, | ||
| { "wallet", "addwitnessaddress", &addwitnessaddress, {"address","p2sh"} }, | ||
| { "wallet", "backupwallet", &backupwallet, {"destination"} }, | ||
| { "wallet", "bumpfee", &bumpfee, {"txid", "options"} }, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright (c) 2014-2016 The Bitcoin Core developers | ||
| # Distributed under the MIT software license, see the accompanying | ||
| # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
|
||
| # Exercise the createmultisig API | ||
|
|
||
| from test_framework.test_framework import BitcoinTestFramework | ||
| from test_framework.util import * | ||
|
|
||
| class SortMultisigTest(BitcoinTestFramework): | ||
| def set_test_params(self): | ||
| self.num_nodes = 1 | ||
| self.extra_args = [[]] | ||
| self.setup_clean_chain = True | ||
|
|
||
| def run_simple_test(self): | ||
| pub1 = "022df8750480ad5b26950b25c7ba79d3e37d75f640f8e5d9bcd5b150a0f85014da" | ||
| pub2 = "03e3818b65bcc73a7d64064106a859cc1a5a728c4345ff0b641209fba0d90de6e9" | ||
| pub3 = "021f2f6e1e50cb6a953935c3601284925decd3fd21bc445712576873fb8c6ebc18" | ||
|
|
||
| pubs = [pub1,pub2,pub3] | ||
|
|
||
| default = self.nodes[0].createmultisig(2, pubs) | ||
| unsorted = self.nodes[0].createmultisig(2, pubs, False) | ||
|
|
||
| assert_equal("2N2BchzwfyuqJep7sKmFfBucfopHZQuPnpt", unsorted["address"]) | ||
| assert_equal("5221022df8750480ad5b26950b25c7ba79d3e37d75f640f8e5d9bcd5b150a0f85014da2103e3818b65bcc73a7d64064106a859cc1a5a728c4345ff0b641209fba0d90de6e921021f2f6e1e50cb6a953935c3601284925decd3fd21bc445712576873fb8c6ebc1853ae", unsorted["redeemScript"]) | ||
| assert_equal(default["address"], unsorted["address"]) | ||
| assert_equal(default["redeemScript"], unsorted["redeemScript"]) | ||
|
|
||
| sorted = self.nodes[0].createmultisig(2, pubs, True) | ||
| assert_equal("2NFd5JqpwmQNz3gevZJ3rz9ofuHvqaP9Cye", sorted["address"]) | ||
| assert_equal("5221021f2f6e1e50cb6a953935c3601284925decd3fd21bc445712576873fb8c6ebc1821022df8750480ad5b26950b25c7ba79d3e37d75f640f8e5d9bcd5b150a0f85014da2103e3818b65bcc73a7d64064106a859cc1a5a728c4345ff0b641209fba0d90de6e953ae", sorted["redeemScript"]) | ||
|
|
||
| def run_demonstrate_sorting(self): | ||
| pub1 = "022df8750480ad5b26950b25c7ba79d3e37d75f640f8e5d9bcd5b150a0f85014da" | ||
| pub2 = "03e3818b65bcc73a7d64064106a859cc1a5a728c4345ff0b641209fba0d90de6e9" | ||
| pub3 = "021f2f6e1e50cb6a953935c3601284925decd3fd21bc445712576873fb8c6ebc18" | ||
|
|
||
| sorted = self.nodes[0].createmultisig(2, [pub3,pub1,pub2,]) | ||
|
|
||
| self.test_if_result_matches(2, [pub1,pub2,pub3], True, sorted["address"]) | ||
| self.test_if_result_matches(2, [pub1,pub3,pub2], True, sorted["address"]) | ||
| self.test_if_result_matches(2, [pub2,pub3,pub1], True, sorted["address"]) | ||
| self.test_if_result_matches(2, [pub2,pub1,pub3], True, sorted["address"]) | ||
| self.test_if_result_matches(2, [pub3,pub1,pub2], True, sorted["address"]) | ||
| self.test_if_result_matches(2, [pub3,pub2,pub1], True, sorted["address"]) | ||
|
|
||
| self.test_if_result_matches(2, [pub1,pub2,pub3], False, sorted["address"]) | ||
| self.test_if_result_matches(2, [pub1,pub3,pub2], False, sorted["address"]) | ||
| self.test_if_result_matches(2, [pub2,pub3,pub1], False, sorted["address"]) | ||
| self.test_if_result_matches(2, [pub2,pub1,pub3], False, sorted["address"]) | ||
| self.test_if_result_matches(2, [pub3,pub2,pub1], False, sorted["address"]) | ||
|
|
||
| def test_if_result_matches(self, m, keys, sort, against): | ||
| result = self.nodes[0].createmultisig(m, keys, sort) | ||
| assert_equal(sort, result["address"] == against) | ||
|
|
||
| def test_compressed_keys_forbidden(self): | ||
| pub1 = "02fdf7e1b65a477a7815effde996a03a7d94cbc46f7d14c05ef38425156fc92e22" | ||
| pub2 = "04823336da95f0b4cf745839dff26992cef239ad2f08f494e5b57c209e4f3602d5526bc251d480e3284d129f736441560e17f3a7eb7ed665fdf0158f44550b926c" | ||
| rs = "522102fdf7e1b65a477a7815effde996a03a7d94cbc46f7d14c05ef38425156fc92e224104823336da95f0b4cf745839dff26992cef239ad2f08f494e5b57c209e4f3602d5526bc251d480e3284d129f736441560e17f3a7eb7ed665fdf0158f44550b926c52ae" | ||
| pubs = [pub1,pub2] | ||
|
|
||
| default = self.nodes[0].createmultisig(2, pubs) | ||
| assert_equal(rs, default["redeemScript"]) | ||
|
|
||
| unsorted = self.nodes[0].createmultisig(2, pubs, False) | ||
| assert_equal(rs, unsorted["redeemScript"]) | ||
| assert_equal(default["address"], unsorted["address"]) | ||
| assert_equal(default["redeemScript"], unsorted["redeemScript"]) | ||
|
|
||
| assert_raises_rpc_error(-1, "Compressed key required for BIP67: 04823336da95f0b4cf745839dff26992cef239ad2f08f494e5b57c209e4f3602d5526bc251d480e3284d129f736441560e17f3a7eb7ed665fdf0158f44550b926c", self.nodes[0].createmultisig, 2, pubs, True) | ||
|
|
||
| def run_test(self): | ||
| self.run_simple_test() | ||
| self.run_demonstrate_sorting() | ||
| self.test_compressed_keys_forbidden() | ||
|
|
||
| if __name__ == '__main__': | ||
| SortMultisigTest().main() | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please switch back to an options object for this.