diff --git a/qa/rpc-tests/addressindex.py b/qa/rpc-tests/addressindex.py index a985735f8..2e15348d6 100755 --- a/qa/rpc-tests/addressindex.py +++ b/qa/rpc-tests/addressindex.py @@ -48,14 +48,20 @@ class AddressIndexTest(BitcoinTestFramework): print "Testing p2pkh and p2sh address index..." txid0 = self.nodes[0].sendtoaddress("mo9ncXisMeAoXwqcV5EWuyncbmCcQN4rVs", 10) + self.nodes[0].generate(1) + txidb0 = self.nodes[0].sendtoaddress("2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br", 10) self.nodes[0].generate(1) txid1 = self.nodes[0].sendtoaddress("mo9ncXisMeAoXwqcV5EWuyncbmCcQN4rVs", 15) + self.nodes[0].generate(1) + txidb1 = self.nodes[0].sendtoaddress("2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br", 15) self.nodes[0].generate(1) txid2 = self.nodes[0].sendtoaddress("mo9ncXisMeAoXwqcV5EWuyncbmCcQN4rVs", 20) + self.nodes[0].generate(1) + txidb2 = self.nodes[0].sendtoaddress("2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br", 20) self.nodes[0].generate(1) @@ -76,6 +82,12 @@ class AddressIndexTest(BitcoinTestFramework): # Check that multiple addresses works multitxids = self.nodes[1].getaddresstxids({"addresses": ["2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br", "mo9ncXisMeAoXwqcV5EWuyncbmCcQN4rVs"]}); assert_equal(len(multitxids), 6); + assert_equal(multitxids[0], txid0); + assert_equal(multitxids[1], txidb0); + assert_equal(multitxids[2], txid1); + assert_equal(multitxids[3], txidb1); + assert_equal(multitxids[4], txid2); + assert_equal(multitxids[5], txidb2); # Check that outputs with the same address will only return one txid print "Testing for txid uniqueness..." diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 2a76619d0..97366d755 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -561,17 +561,24 @@ UniValue getaddresstxids(const UniValue& params, bool fHelp) } } - // TODO sort by height std::set txids; + std::vector > vtxids; - UniValue result(UniValue::VARR); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) { + int height = it->first.blockHeight; std::string txid = it->first.txhash.GetHex(); if (txids.insert(txid).second) { - result.push_back(txid); + vtxids.push_back(std::make_pair(height, txid)); } } + std::sort(vtxids.begin(), vtxids.end()); + + UniValue result(UniValue::VARR); + for (std::vector >::const_iterator it=vtxids.begin(); it!=vtxids.end(); it++) { + result.push_back(it->second); + } + return result; }