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

Function json_add_channel

lightningd/peer_control.c:682–1044  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

680}
681
682static void json_add_channel(struct lightningd *ld,
683 struct json_stream *response, const char *key,
684 const struct channel *channel)
685{
686 struct channel_stats channel_stats;
687 struct amount_msat funding_msat;
688 struct amount_sat peer_funded_sats;
689 struct state_change_entry *state_changes;
690 u32 feerate;
691
692 json_object_start(response, key);
693 json_add_string(response, "state", channel_state_name(channel));
694 if (channel->last_tx && !invalid_last_tx(channel->last_tx)) {
695 struct bitcoin_txid txid;
696 bitcoin_txid(channel->last_tx, &txid);
697
698 json_add_txid(response, "scratch_txid", &txid);
699 json_add_amount_sat_msat(response, "last_tx_fee_msat",
700 bitcoin_tx_compute_fee(channel->last_tx));
701 }
702
703 json_object_start(response, "feerate");
704 feerate = get_feerate(channel->fee_states, channel->opener, LOCAL);
705 json_add_u32(response, feerate_style_name(FEERATE_PER_KSIPA), feerate);
706 json_add_u32(response, feerate_style_name(FEERATE_PER_KBYTE),
707 feerate_to_style(feerate, FEERATE_PER_KBYTE));
708 json_object_end(response);
709
710 if (channel->owner)
711 json_add_string(response, "owner", channel->owner->name);
712
713 if (channel->scid)
714 json_add_short_channel_id(response, "short_channel_id",
715 channel->scid);
716
717 /* If there is any way we can use the channel we'd better have
718 * a direction attached. Technically we could always add it,
719 * as it's just the lexicographic order between node_ids, but
720 * why bother if we can't use it? */
721 if (channel->scid || channel->alias[LOCAL] || channel->alias[REMOTE])
722 json_add_num(response, "direction",
723 node_id_idx(&ld->id, &channel->peer->id));
724
725 json_add_string(response, "channel_id",
726 type_to_string(tmpctx, struct channel_id, &channel->cid));
727 json_add_txid(response, "funding_txid", &channel->funding.txid);
728 json_add_num(response, "funding_outnum", channel->funding.n);
729
730 if (!list_empty(&channel->inflights)) {
731 struct channel_inflight *initial, *inflight;
732 u32 last_feerate, next_feerate;
733
734 initial = list_top(&channel->inflights,
735 struct channel_inflight, list);
736 json_add_string(response, "initial_feerate",
737 tal_fmt(tmpctx, "%d%s",
738 initial->funding->feerate,
739 feerate_style_name(FEERATE_PER_KSIPA)));

Callers 1

json_add_peerFunction · 0.85

Calls 15

invalid_last_txFunction · 0.85
bitcoin_tx_compute_feeFunction · 0.85
feerate_style_nameFunction · 0.85
feerate_to_styleFunction · 0.85
node_id_idxFunction · 0.85
json_add_sat_onlyFunction · 0.85
amount_msat_to_satFunction · 0.85
channel_amount_spendableFunction · 0.85
json_add_htlcsFunction · 0.85
channel_state_nameFunction · 0.70
bitcoin_txidClass · 0.70

Tested by

no test coverage detected