| 1115 | } |
| 1116 | |
| 1117 | UniValue gettxout(const UniValue& params, bool fHelp) |
| 1118 | { |
| 1119 | if (fHelp || params.size() < 2 || params.size() > 3) |
| 1120 | throw runtime_error( |
| 1121 | "gettxout \"txid\" n ( includemempool )\n" |
| 1122 | "\nReturns details about an unspent transaction output.\n" |
| 1123 | "\nArguments:\n" |
| 1124 | "1. \"txid\" (string, required) The transaction id\n" |
| 1125 | "2. n (numeric, required) vout value\n" |
| 1126 | "3. includemempool (boolean, optional) Whether to included the mem pool\n" |
| 1127 | "\nResult:\n" |
| 1128 | "{\n" |
| 1129 | " \"bestblock\" : \"hash\", (string) the block hash\n" |
| 1130 | " \"confirmations\" : n, (numeric) The number of confirmations\n" |
| 1131 | " \"value\" : x.xxx, (numeric) The transaction value in btc\n" |
| 1132 | " \"scriptPubKey\" : { (json object)\n" |
| 1133 | " \"asm\" : \"code\", (string) \n" |
| 1134 | " \"hex\" : \"hex\", (string) \n" |
| 1135 | " \"reqSigs\" : n, (numeric) Number of required signatures\n" |
| 1136 | " \"type\" : \"pubkeyhash\", (string) The type, eg pubkeyhash\n" |
| 1137 | " \"addresses\" : [ (array of string) array of lux addresses\n" |
| 1138 | " \"luxaddress\" (string) lux address\n" |
| 1139 | " ,...\n" |
| 1140 | " ]\n" |
| 1141 | " },\n" |
| 1142 | " \"version\" : n, (numeric) The version\n" |
| 1143 | " \"coinbase\" : true|false (boolean) Coinbase or not\n" |
| 1144 | "}\n" |
| 1145 | |
| 1146 | "\nExamples:\n" |
| 1147 | "\nGet unspent transactions\n" + |
| 1148 | HelpExampleCli("listunspent", "") + |
| 1149 | "\nView the details\n" + HelpExampleCli("gettxout", "\"txid\" 1") + |
| 1150 | "\nAs a json rpc call\n" + HelpExampleRpc("gettxout", "\"txid\", 1")); |
| 1151 | |
| 1152 | LOCK(cs_main); |
| 1153 | |
| 1154 | UniValue ret(UniValue::VOBJ); |
| 1155 | |
| 1156 | std::string strHash = params[0].get_str(); |
| 1157 | uint256 hash(strHash); |
| 1158 | int n = params[1].get_int(); |
| 1159 | COutPoint out(hash, n); |
| 1160 | bool fMempool = true; |
| 1161 | if (params.size() > 2) |
| 1162 | fMempool = params[2].get_bool(); |
| 1163 | |
| 1164 | CCoins coins; |
| 1165 | if (fMempool) { |
| 1166 | //LOCK(mempool.cs); |
| 1167 | CCoinsViewMemPool view(pcoinsTip, mempool); |
| 1168 | if (!view.GetCoin(out, coins) || mempool.isSpent(out)) { // TODO: filtering spent coins should be done by the CCoinsViewMemPool |
| 1169 | return NullUniValue; |
| 1170 | } |
| 1171 | } else { |
| 1172 | if (!pcoinsTip->GetCoins(hash, coins)) { |
| 1173 | return NullUniValue; |
| 1174 | } |
nothing calls this directly
no test coverage detected