| 224 | } |
| 225 | |
| 226 | static struct command_result *json_inspect(struct command *cmd, |
| 227 | const char *buf, |
| 228 | const jsmntok_t *params) |
| 229 | { |
| 230 | struct json_stream *res; |
| 231 | struct account *acct; |
| 232 | const char *acct_name; |
| 233 | struct fee_sum **fee_sums; |
| 234 | struct txo_set **txos; |
| 235 | |
| 236 | /* Only available for channel accounts? */ |
| 237 | if (!param(cmd, buf, params, |
| 238 | p_req("account", param_string, &acct_name), |
| 239 | NULL)) |
| 240 | return command_param_failed(); |
| 241 | |
| 242 | if (streq(acct_name, WALLET_ACCT) |
| 243 | || streq(acct_name, EXTERNAL_ACCT)) |
| 244 | return command_fail(cmd, PLUGIN_ERROR, |
| 245 | "`inspect` not supported for" |
| 246 | " non-channel accounts"); |
| 247 | |
| 248 | db_begin_transaction(db); |
| 249 | acct = find_account(cmd, db, acct_name); |
| 250 | db_commit_transaction(db); |
| 251 | |
| 252 | if (!acct) |
| 253 | return command_fail(cmd, PLUGIN_ERROR, |
| 254 | "Account %s not found", |
| 255 | acct_name); |
| 256 | |
| 257 | db_begin_transaction(db); |
| 258 | find_txo_chain(cmd, db, acct, &txos); |
| 259 | fee_sums = find_account_onchain_fees(cmd, db, acct); |
| 260 | db_commit_transaction(db); |
| 261 | |
| 262 | res = jsonrpc_stream_success(cmd); |
| 263 | json_array_start(res, "txs"); |
| 264 | for (size_t i = 0; i < tal_count(txos); i++) { |
| 265 | struct txo_set *set = txos[i]; |
| 266 | struct fee_sum *fee_sum; |
| 267 | |
| 268 | json_object_start(res, NULL); |
| 269 | json_add_txid(res, "txid", set->txid); |
| 270 | |
| 271 | /* annoyting, but we can only add the block height |
| 272 | * if we have a txo for it */ |
| 273 | for (size_t j = 0; j < tal_count(set->pairs); j++) { |
| 274 | if (set->pairs[j]->txo |
| 275 | && set->pairs[j]->txo->blockheight > 0) { |
| 276 | json_add_num(res, "blockheight", |
| 277 | set->pairs[j]->txo->blockheight); |
| 278 | break; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | fee_sum = find_sum_for_txid(fee_sums, set->txid); |
| 283 | if (fee_sum) |
nothing calls this directly
no test coverage detected