| 1079 | } |
| 1080 | |
| 1081 | UniValue 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 |
nothing calls this directly
no test coverage detected