diff --git a/qa/rpc-tests/addressindex.py b/qa/rpc-tests/addressindex.py index fd750403f..a985735f8 100755 --- a/qa/rpc-tests/addressindex.py +++ b/qa/rpc-tests/addressindex.py @@ -73,6 +73,10 @@ class AddressIndexTest(BitcoinTestFramework): assert_equal(txidsb[1], txidb1); assert_equal(txidsb[2], txidb2); + # Check that multiple addresses works + multitxids = self.nodes[1].getaddresstxids({"addresses": ["2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br", "mo9ncXisMeAoXwqcV5EWuyncbmCcQN4rVs"]}); + assert_equal(len(multitxids), 6); + # Check that outputs with the same address will only return one txid print "Testing for txid uniqueness..." addressHash = "6349a418fc4578d10a372b54b45c280cc8c4382f".decode("hex") diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index b3c0c18f9..2a76619d0 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -518,20 +518,50 @@ UniValue getaddresstxids(const UniValue& params, bool fHelp) "]\n" ); - CBitcoinAddress address(params[0].get_str()); - uint160 hashBytes; - int type = 0; - if (!address.GetIndexKey(hashBytes, type)) { + std::vector > addresses; + + if (params[0].isStr()) { + + CBitcoinAddress address(params[0].get_str()); + uint160 hashBytes; + int type = 0; + if (!address.GetIndexKey(hashBytes, type)) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); + } + addresses.push_back(std::make_pair(hashBytes, type)); + + } else if (params[0].isObject()) { + + UniValue addressValues = find_value(params[0].get_obj(), "addresses"); + if (!addressValues.isArray()) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Addresses is expected to be an array"); + } + + std::vector values = addressValues.getValues(); + + for (std::vector::iterator it = values.begin(); it != values.end(); ++it) { + + CBitcoinAddress address(it->get_str()); + uint160 hashBytes; + int type = 0; + if (!address.GetIndexKey(hashBytes, type)) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); + } + addresses.push_back(std::make_pair(hashBytes, type)); + } + } else { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); } std::vector > addressIndex; - LOCK(cs_main); - - if (!GetAddressIndex(hashBytes, type, addressIndex)) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address"); + for (std::vector >::iterator it = addresses.begin(); it != addresses.end(); ++it) { + if (!GetAddressIndex((*it).first, (*it).second, addressIndex)) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address"); + } + } + // TODO sort by height std::set txids; UniValue result(UniValue::VARR);