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

Function json_setleaserates

lightningd/gossip_control.c:349–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

347}
348
349static struct command_result *json_setleaserates(struct command *cmd,
350 const char *buffer,
351 const jsmntok_t *obj UNNEEDED,
352 const jsmntok_t *params)
353{
354 struct json_stream *res;
355 struct lease_rates *rates;
356 struct amount_msat *channel_fee_base_msat, *lease_base_msat;
357 u32 *lease_basis, *channel_fee_max_ppt, *funding_weight;
358
359 if (!param_check(cmd, buffer, params,
360 p_req("lease_fee_base_msat", param_msat, &lease_base_msat),
361 p_req("lease_fee_basis", param_number, &lease_basis),
362 p_req("funding_weight", param_number, &funding_weight),
363 p_req("channel_fee_max_base_msat", param_msat,
364 &channel_fee_base_msat),
365 p_req("channel_fee_max_proportional_thousandths",
366 param_number, &channel_fee_max_ppt),
367 NULL))
368 return command_param_failed();
369
370 rates = tal(tmpctx, struct lease_rates);
371 rates->lease_fee_basis = *lease_basis;
372 rates->lease_fee_base_sat = lease_base_msat->millisatoshis / 1000; /* Raw: conversion */
373 rates->channel_fee_max_base_msat = channel_fee_base_msat->millisatoshis; /* Raw: conversion */
374
375 rates->funding_weight = *funding_weight;
376 rates->channel_fee_max_proportional_thousandths
377 = *channel_fee_max_ppt;
378
379 /* Gotta check that we didn't overflow */
380 if (lease_base_msat->millisatoshis != rates->lease_fee_base_sat * (u64)1000) /* Raw: comparison */
381 return command_fail_badparam(cmd, "lease_fee_base_msat",
382 buffer, params, "Overflow");
383
384 if (channel_fee_base_msat->millisatoshis > rates->channel_fee_max_base_msat) /* Raw: comparison */
385 return command_fail_badparam(cmd, "channel_fee_max_base_msat",
386 buffer, params, "Overflow");
387
388 if (command_check_only(cmd))
389 return command_check_done(cmd);
390
391 /* Save them for node_announcement generation */
392 cmd->ld->lease_rates = tal_free(cmd->ld->lease_rates);
393 if (!lease_rates_empty(rates))
394 cmd->ld->lease_rates = tal_steal(cmd->ld, rates);
395
396 /* This may generate a new node_announcement */
397 channel_gossip_node_announce(cmd->ld);
398
399 res = json_stream_success(cmd);
400 json_add_amount_sat_msat(res, "lease_fee_base_msat",
401 amount_sat(rates->lease_fee_base_sat));
402 json_add_num(res, "lease_fee_basis", rates->lease_fee_basis);
403 json_add_num(res, "funding_weight", rates->funding_weight);
404 json_add_amount_msat(res, "channel_fee_max_base_msat",
405 amount_msat(rates->channel_fee_max_base_msat));
406 json_add_num(res, "channel_fee_max_proportional_thousandths",

Callers

nothing calls this directly

Calls 15

param_checkFunction · 0.85
tal_freeFunction · 0.85
lease_rates_emptyFunction · 0.85
json_add_amount_sat_msatFunction · 0.85
json_add_numFunction · 0.85
json_add_amount_msatFunction · 0.85
command_param_failedFunction · 0.70
command_check_onlyFunction · 0.70
command_check_doneFunction · 0.70
json_stream_successFunction · 0.70
amount_satClass · 0.70

Tested by

no test coverage detected