MCPcopy Create free account
hub / github.com/LUX-Core/lux / getspentinfo

Function getspentinfo

src/rpcmisc.cpp:1081–1140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1079}
1080
1081UniValue getspentinfo(const UniValue& params, bool fHelp)
1082{
1083 if (fHelp || params.size() < 1) {
1084 throw runtime_error(
1085 "getspentinfo\n"
1086 "\nReturns the transaction where an output is spent. (-spentindex required)\n"
1087 "\nArguments: {\n"
1088 " \"txid\": \"...\", (string) The hash of the transaction\n"
1089 " \"index\": 1 (number) The transaction output index to check\n"
1090 "}\n"
1091 "\nResult: {\n"
1092 " \"txid\", (string) The spent transaction hash\n"
1093 " \"index\", (number) The transaction input index\n"
1094 " \"height\" (number) The block height\n"
1095 "}\n"
1096 "\nExamples:\n"
1097 + HelpExampleCli("getspentinfo", "\"9e941e62e07c41e78dad34deab979fb49b4ef9f9c11113f0758b504f313d40a2\" 2")
1098 + HelpExampleCli("getspentinfo",
1099 "'{\"txhash\": \"9e941e62e07c41e78dad34deab979fb49b4ef9f9c11113f0758b504f313d40a2\", \"index\": 2}'")
1100 + HelpExampleRpc("getspentinfo",
1101 "{\"txhash\": \"9e941e62e07c41e78dad34deab979fb49b4ef9f9c11113f0758b504f313d40a2\", \"index\": 2}")
1102 );
1103 }
1104
1105 uint256 txhash;
1106 int outputIndex = 0;
1107 if (params[0].isObject()) {
1108 // json rpc
1109 UniValue txhValue = find_value(params[0].get_obj(), "txid");
1110 UniValue indexValue = find_value(params[0].get_obj(), "index");
1111 if (!txhValue.isStr())
1112 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid tx");
1113 txhash = ParseHashV(txhValue, "txid");
1114 outputIndex = indexValue.isNum() ? indexValue.get_int() : 0;
1115 } else {
1116 // debug console compatible
1117 UniValue txhValue = params[0];
1118 if (!txhValue.isStr())
1119 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid tx");
1120 txhash = ParseHashV(txhValue, "txid");
1121 if (params.size() > 1) {
1122 UniValue indexValue = params[1];
1123 outputIndex = indexValue.isNum() ? indexValue.get_int() : 0;
1124 }
1125 }
1126
1127 CSpentIndexKey key(txhash, outputIndex);
1128 CSpentIndexValue value;
1129
1130 if (!GetSpentIndex(key, value)) {
1131 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to get spent info");
1132 }
1133
1134 UniValue obj(UniValue::VOBJ);
1135 obj.push_back(Pair("txid", value.txhash.GetHex()));
1136 obj.push_back(Pair("index", (int)value.inputIndex));
1137 obj.push_back(Pair("height", value.blockHeight));
1138

Callers

nothing calls this directly

Calls 13

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
JSONRPCErrorFunction · 0.85
ParseHashVFunction · 0.85
GetSpentIndexFunction · 0.85
PairFunction · 0.85
isObjectMethod · 0.80
isStrMethod · 0.80
isNumMethod · 0.80
sizeMethod · 0.45
get_intMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected