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

Function param_destinations_array

plugins/spender/multifundchannel.c:1826–1946  ·  view source on GitHub ↗

Validates the destinations input argument. Returns NULL if checking of destinations array worked, or non-NULL if it failed (and this function has already executed mfc_fail). */

Source from the content-addressed store, hash-verified

1824executed mfc_fail).
1825*/
1826static struct command_result *
1827param_destinations_array(struct command *cmd, const char *name,
1828 const char *buffer, const jsmntok_t *tok,
1829 struct multifundchannel_destination **dests)
1830{
1831 size_t i;
1832 const jsmntok_t *json_dest;
1833 bool has_all = false;
1834
1835 if (tok->type != JSMN_ARRAY)
1836 return command_fail_badparam(cmd, name, buffer, tok,
1837 "must be an array");
1838 if (tok->size < 1)
1839 return command_fail_badparam(cmd, name, buffer, tok,
1840 "must have at least one entry");
1841
1842 *dests = tal_arr(cmd, struct multifundchannel_destination, tok->size);
1843 for (i = 0; i < tal_count(*dests); ++i)
1844 (*dests)[i].state = MULTIFUNDCHANNEL_START_NOT_YET;
1845
1846 json_for_each_arr(i, json_dest, tok) {
1847 struct multifundchannel_destination *dest;
1848 const char *id;
1849 char *addrhint;
1850 struct amount_sat *amount, *request_amt;
1851 bool *announce;
1852 struct amount_msat *push_msat;
1853 struct lease_rates *rates;
1854
1855 dest = &(*dests)[i];
1856
1857 if (!param(cmd, buffer, json_dest,
1858 p_req("id", param_string, &id),
1859 p_req("amount", param_sat_or_all, &amount),
1860 p_opt_def("announce", param_bool, &announce, true),
1861 p_opt_def("push_msat", param_msat, &push_msat,
1862 AMOUNT_MSAT(0)),
1863 /* FIXME: do address validation here?
1864 * Note that it will fail eventually (when
1865 * passed in to fundchannel_start) if invalid*/
1866 p_opt("close_to", param_string,
1867 &dest->close_to_str),
1868 p_opt_def("request_amt", param_sat, &request_amt,
1869 AMOUNT_SAT(0)),
1870 p_opt("compact_lease", param_lease_hex, &rates),
1871 p_opt("mindepth", param_u32, &dest->mindepth),
1872 p_opt("reserve", param_sat, &dest->reserve),
1873 p_opt("channel_type", param_channel_type, &dest->channel_type),
1874 NULL))
1875 return command_param_failed();
1876
1877 addrhint = strchr(id, '@');
1878 if (addrhint) {
1879 /* Split at @. */
1880 size_t idlen = (size_t) (addrhint - id);
1881 addrhint = tal_strdup(*dests, addrhint + 1);
1882 id = tal_strndup(*dests, take(id), idlen);
1883 }

Callers

nothing calls this directly

Calls 9

amount_sat_lessFunction · 0.85
amount_sat_is_zeroFunction · 0.85
tal_freeFunction · 0.85
node_id_eqFunction · 0.85
command_fail_badparamFunction · 0.50
paramFunction · 0.50
command_param_failedFunction · 0.50
node_id_from_hexstrFunction · 0.50
amount_sat_eqFunction · 0.50

Tested by

no test coverage detected