main: index unspent outputs by address
This commit is contained in:
committed by
Braydon Fuller
parent
8597289d8b
commit
0b42ba227a
@@ -435,6 +435,56 @@ bool getAddressesFromParams(const UniValue& params, std::vector<std::pair<uint16
|
||||
|
||||
}
|
||||
|
||||
UniValue getaddressutxos(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 1 || !params[0].isObject())
|
||||
throw runtime_error(
|
||||
"getaddressutxos\n"
|
||||
"\nReturns all unspent outputs for an address (requires addressindex to be enabled).\n"
|
||||
"\nResult\n"
|
||||
"[\n"
|
||||
" {\n"
|
||||
" \"address\" (string) The address base58check encoded\n"
|
||||
" \"txid\" (string) The output txid\n"
|
||||
" \"height\" (number) The block height\n"
|
||||
" \"outputIndex\" (number) The output index\n"
|
||||
" \"script\" (strin) The script hex encoded\n"
|
||||
" \"satoshis\" (number) The number of satoshis of the output\n"
|
||||
" }\n"
|
||||
"]\n"
|
||||
);
|
||||
|
||||
std::vector<std::pair<uint160, int> > addresses;
|
||||
|
||||
if (!getAddressesFromParams(params, addresses)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
|
||||
}
|
||||
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
|
||||
for (std::vector<std::pair<uint160, int> >::iterator it = addresses.begin(); it != addresses.end(); it++) {
|
||||
if (!GetAddressUnspent((*it).first, (*it).second, unspentOutputs)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for address");
|
||||
}
|
||||
}
|
||||
|
||||
UniValue result(UniValue::VARR);
|
||||
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) {
|
||||
UniValue output(UniValue::VOBJ);
|
||||
output.push_back(Pair("addressType", (int)it->first.type));
|
||||
output.push_back(Pair("addressHash", it->first.hashBytes.GetHex()));
|
||||
output.push_back(Pair("txid", it->first.txhash.GetHex()));
|
||||
output.push_back(Pair("height", it->first.blockHeight));
|
||||
output.push_back(Pair("outputIndex", it->first.index));
|
||||
output.push_back(Pair("script", HexStr(it->second.script.begin(), it->second.script.end())));
|
||||
output.push_back(Pair("satoshis", it->second.satoshis));
|
||||
result.push_back(output);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
UniValue getaddressdeltas(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 1 || !params[0].isObject())
|
||||
|
||||
Reference in New Issue
Block a user