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

Function json_to_listpeers_channel

plugins/libplugin.c:1781–1855  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1779}
1780
1781static struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx,
1782 const char *buffer,
1783 const jsmntok_t *tok)
1784{
1785 struct listpeers_channel *chan;
1786 const jsmntok_t *privtok = json_get_member(buffer, tok, "private"),
1787 *statetok = json_get_member(buffer, tok, "state"),
1788 *ftxidtok =
1789 json_get_member(buffer, tok, "funding_txid"),
1790 *scidtok =
1791 json_get_member(buffer, tok, "short_channel_id"),
1792 *dirtok = json_get_member(buffer, tok, "direction"),
1793 *tmsattok = json_get_member(buffer, tok, "total_msat"),
1794 *smsattok =
1795 json_get_member(buffer, tok, "spendable_msat"),
1796 *aliastok = json_get_member(buffer, tok, "alias");
1797
1798 if (privtok == NULL || privtok->type != JSMN_PRIMITIVE ||
1799 statetok == NULL || statetok->type != JSMN_STRING ||
1800 ftxidtok == NULL || ftxidtok->type != JSMN_STRING ||
1801 (scidtok != NULL && scidtok->type != JSMN_STRING) ||
1802 (dirtok != NULL && dirtok->type != JSMN_PRIMITIVE) ||
1803 tmsattok == NULL ||
1804 smsattok == NULL)
1805 return NULL;
1806
1807 chan = tal(ctx, struct listpeers_channel);
1808
1809 json_to_bool(buffer, privtok, &chan->private);
1810 chan->state = json_strdup(chan, buffer, statetok);
1811 json_to_txid(buffer, ftxidtok, &chan->funding_txid);
1812 if (scidtok != NULL) {
1813 assert(dirtok != NULL);
1814 chan->scid = tal(chan, struct short_channel_id);
1815 json_to_short_channel_id(buffer, scidtok, chan->scid);
1816 } else {
1817 chan->scid = NULL;
1818 chan->direction = NULL;
1819 }
1820
1821 if (dirtok != NULL) {
1822 chan->direction = tal(chan, int);
1823 json_to_int(buffer, dirtok, chan->direction);
1824 } else {
1825 chan->direction = NULL;
1826 }
1827
1828 if (aliastok != NULL) {
1829 const jsmntok_t *loctok =
1830 json_get_member(buffer, aliastok, "local"),
1831 *remtok =
1832 json_get_member(buffer, aliastok, "remote");
1833 if (loctok) {
1834 chan->alias[LOCAL] = tal(chan, struct short_channel_id);
1835 json_to_short_channel_id(buffer, loctok,
1836 chan->alias[LOCAL]);
1837 } else
1838 chan->alias[LOCAL] = NULL;

Callers 1

json_to_listpeers_peerFunction · 0.85

Calls 7

json_get_memberFunction · 0.50
json_to_boolFunction · 0.50
json_strdupFunction · 0.50
json_to_txidFunction · 0.50
json_to_short_channel_idFunction · 0.50
json_to_intFunction · 0.50
json_to_msatFunction · 0.50

Tested by

no test coverage detected