Fix missing handling for imported transparent multisig addresses.

This commit is contained in:
Kris Nuttycombe 2022-05-06 13:24:58 -06:00
parent b900c4827b
commit 66fad22873
2 changed files with 30 additions and 16 deletions

View File

@ -1,15 +1,10 @@
#!/usr/bin/env python3
# Copyright (c) 2014-2016 The Bitcoin Core developers
# Copyright (c) 2022 The Zcash developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://www.opensource.org/licenses/mit-license.php .
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, assert_greater_than, \
start_nodes, connect_nodes_bi, stop_nodes, wait_and_assert_operationid_status, \
wait_bitcoinds
from decimal import Decimal
from test_framework.util import start_nodes, connect_nodes_bi
class ThreeOfThreeRestoreTest(BitcoinTestFramework):
@ -43,22 +38,22 @@ class ThreeOfThreeRestoreTest(BitcoinTestFramework):
key2 = self.nodes[2].dumpprivkey(addr2)
key3 = self.nodes[2].dumpprivkey(addr3)
self.nodes[3].importprivkey(key1, "", True) # TODO
self.nodes[3].importprivkey(key1, "", True)
self.nodes[3].importprivkey(key2, "", True)
self.nodes[3].importprivkey(key3, "", True)
mSigObj = self.nodes[3].addmultisigaddress(3, [addr1Obj['pubkey'], addr2Obj['pubkey'], addr3Obj['pubkey']])
validateObj = self.nodes[3].validateaddress(mSigObj)
print(validateObj)
# Causes the node to crash
obj = self.nodes[3].listaddresses()
print(obj)
assert(validateObj["isvalid"])
assert(validateObj["ismine"])
# Ensure that the multisig address is returned
list_result = self.nodes[3].listaddresses()
assert('imported' in obj['source'] for obj in list_result)
for obj in list_result:
if obj['source'] == 'imported':
assert(validateObj['address'] in obj['transparent']['addresses'])
if __name__ == '__main__':
ThreeOfThreeRestoreTest().main()

View File

@ -408,12 +408,14 @@ UniValue listaddresses(const UniValue& params, bool fHelp)
// Split transparent addresses into several categories:
// - Generated randomly.
// - Imported
// - Imported watchonly.
// - Derived from mnemonic seed.
std::set<CTxDestination> t_generated_dests;
std::set<CTxDestination> t_generated_change_dests;
std::set<CTxDestination> t_mnemonic_dests;
std::set<CTxDestination> t_mnemonic_change_dests;
std::set<CTxDestination> t_imported_dests;
std::set<CTxDestination> t_watchonly_dests;
// Get the CTxDestination values for all the entries in the transparent address book.
// This will include any address that has been generated by this wallet.
@ -433,6 +435,9 @@ UniValue listaddresses(const UniValue& params, bool fHelp)
case PaymentAddressSource::Random:
t_generated_dests.insert(item.first);
break;
case PaymentAddressSource::Imported:
t_imported_dests.insert(item.first);
break;
case PaymentAddressSource::ImportedWatchOnly:
t_watchonly_dests.insert(item.first);
break;
@ -453,6 +458,7 @@ UniValue listaddresses(const UniValue& params, bool fHelp)
for (const std::pair<CTxDestination, CAmount>& item : pwalletMain->GetAddressBalances()) {
if (t_generated_dests.count(item.first) == 0 &&
t_mnemonic_dests.count(item.first) == 0 &&
t_imported_dests.count(item.first) == 0 &&
t_watchonly_dests.count(item.first) == 0)
{
std::optional<PaymentAddressSource> source;
@ -607,6 +613,19 @@ UniValue listaddresses(const UniValue& params, bool fHelp)
bool hasData = false;
if (!t_imported_dests.empty()) {
UniValue t_imported_addrs(UniValue::VARR);
for (const CTxDestination& dest: t_imported_dests) {
t_imported_addrs.push_back(keyIO.EncodeDestination(dest));
}
UniValue imported_t(UniValue::VOBJ);
imported_t.pushKV("addresses", t_imported_addrs);
entry.pushKV("transparent", imported_t);
hasData = true;
}
{
UniValue imported_sprout_addrs(UniValue::VARR);
for (const SproutPaymentAddress& addr : sproutAddresses) {