rpc: query for multiple addresses txids

This commit is contained in:
Braydon Fuller 2016-03-15 15:25:01 -04:00 committed by Simon
parent fd09de01f0
commit 73858d5450
2 changed files with 42 additions and 8 deletions

View File

@ -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")

View File

@ -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<std::pair<uint160, int> > 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<UniValue> values = addressValues.getValues();
for (std::vector<UniValue>::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<std::pair<CAddressIndexKey, CAmount> > addressIndex;
LOCK(cs_main);
if (!GetAddressIndex(hashBytes, type, addressIndex))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address");
for (std::vector<std::pair<uint160, int> >::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<std::string> txids;
UniValue result(UniValue::VARR);