MCPcopy Create free account
hub / github.com/ElementsProject/lightning / getutxout

Function getutxout

plugins/bcli.c:680–727  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

678}
679
680static struct command_result *getutxout(struct command *cmd,
681 const char *buf,
682 const jsmntok_t *toks)
683{
684 const char *txid, *vout;
685 struct bcli_result *res;
686 const jsmntok_t *tokens;
687 struct json_stream *response;
688 struct bitcoin_tx_output output;
689 const char *err;
690
691 /* bitcoin-cli wants strings. */
692 if (!param(cmd, buf, toks,
693 p_req("txid", param_string, &txid),
694 p_req("vout", param_string, &vout),
695 NULL))
696 return command_param_failed();
697
698 res = run_bitcoin_cli(cmd, cmd->plugin, "gettxout", txid, vout, NULL);
699
700 /* As of at least v0.15.1.0, bitcoind returns "success" but an empty
701 string on a spent txout. */
702 if (res->exitstatus != 0 || res->output_len == 0) {
703 response = jsonrpc_stream_success(cmd);
704 json_add_null(response, "amount");
705 json_add_null(response, "script");
706 return command_finished(cmd, response);
707 }
708
709 tokens = json_parse_simple(res->output, res->output, res->output_len);
710 if (!tokens)
711 return command_err(cmd, res, "bad JSON: cannot parse");
712
713 err = json_scan(tmpctx, res->output, tokens,
714 "{value:%,scriptPubKey:{hex:%}}",
715 JSON_SCAN(json_to_bitcoin_amount,
716 &output.amount.satoshis), /* Raw: bitcoind */
717 JSON_SCAN_TAL(cmd, json_tok_bin_from_hex,
718 &output.script));
719 if (err)
720 return command_err(cmd, res, tal_fmt(tmpctx, "bad JSON: %s", err));
721
722 response = jsonrpc_stream_success(cmd);
723 json_add_sats(response, "amount", output.amount);
724 json_add_string(response, "script", tal_hex(response, output.script));
725
726 return command_finished(cmd, response);
727}
728
729static void bitcoind_failure(struct plugin *p, const char *error_message)
730{

Callers

nothing calls this directly

Calls 12

run_bitcoin_cliFunction · 0.85
json_parse_simpleFunction · 0.85
command_errFunction · 0.85
json_add_satsFunction · 0.85
tal_hexFunction · 0.85
command_param_failedFunction · 0.70
jsonrpc_stream_successFunction · 0.70
json_add_nullFunction · 0.70
command_finishedFunction · 0.70
paramFunction · 0.50
json_scanFunction · 0.50
json_add_stringFunction · 0.50

Tested by

no test coverage detected