message: Port getspentinfo RPC
diff: @@ -590,6 +590,53 @@ UniValue getblockhashes(const JSONRPCRequest& request)
  return result;
  }
  +UniValue getspentinfo(const JSONRPCRequest& request)
  +{
  + if (request.fHelp || request.params.size() != 1 || !request.params[0].isObject())
  + throw std::runtime_error(
  + "getspentinfo\n"
  + "\nReturns the txid and index where an output is spent.\n"
  + "\nArguments:\n"
  + "{\n"
  + " \"txid\" (string) The hex string of the txid\n"
  + " \"index\" (number) The start block height\n"
  + "}\n"
  + "\nResult:\n"
  + "{\n"
  + " \"txid\" (string) The transaction id\n"
  + " \"index\" (number) The spending input index\n"
  + " ,...\n"
  + "}\n"
  + "\nExamples:\n"
  + + HelpExampleCli("getspentinfo", "'{\"txid\": \"0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9\", \"index\": 0}'")
  + + HelpExampleRpc("getspentinfo", "{\"txid\": \"0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9\", \"index\": 0}")
  + );
  +
  + UniValue txidValue = find_value(request.params[0].get_obj(), "txid");
  + UniValue indexValue = find_value(request.params[0].get_obj(), "index");
  +
  + if (!txidValue.isStr() || !indexValue.isNum()) {
  + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid txid or index");
  + }
  +
  + uint256 txid = ParseHashV(txidValue, "txid");
  + int outputIndex = indexValue.get_int();
  +
  + CSpentIndexKey key(txid, outputIndex);
  + CSpentIndexValue value;
  +
  + if (!GetSpentIndex(key, value)) {
  + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to get spent info");
  + }
  +
  + UniValue obj(UniValue::VOBJ);
  + obj.pushKV("txid", value.txid.GetHex());
  + obj.pushKV("index", (int)value.inputIndex);
  + obj.pushKV("height", value.blockHeight);
  +
  + return obj;
  +}
  +
  // Needed even with !ENABLE_WALLET, to pass (ignored) pointers around
  class CWallet;
  