main: start of address index
Adds a configuration option for addressindex to search for txids by address. Includes an additional rpc method for getting the txids for an address.
This commit is contained in:
committed by
Braydon Fuller
parent
075b416f56
commit
9babc7ff9f
@@ -396,3 +396,39 @@ UniValue setmocktime(const UniValue& params, bool fHelp)
|
||||
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
UniValue getaddresstxids(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error(
|
||||
"getaddresstxids\n"
|
||||
"\nReturns the txids for an address (requires addressindex to be enabled).\n"
|
||||
"\nResult\n"
|
||||
"[\n"
|
||||
" \"transactionid\" (string) The transaction id\n"
|
||||
" ,...\n"
|
||||
"]\n"
|
||||
);
|
||||
|
||||
CBitcoinAddress address(params[0].get_str());
|
||||
if (!address.IsValid())
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
|
||||
|
||||
CKeyID keyID;
|
||||
address.GetKeyID(keyID);
|
||||
|
||||
int type = 1; // TODO
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
if (!GetAddressIndex(keyID, type, addressIndex))
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address");
|
||||
|
||||
UniValue result(UniValue::VARR);
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++)
|
||||
result.push_back(it->first.txhash.GetHex());
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user