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

Function getutxout

plugins/bcli.c:687–734  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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