| 389 | } |
| 390 | |
| 391 | static struct command_result *json_setleaserates(struct command *cmd, |
| 392 | const char *buffer, |
| 393 | const jsmntok_t *obj UNNEEDED, |
| 394 | const jsmntok_t *params) |
| 395 | { |
| 396 | struct json_stream *res; |
| 397 | struct lease_rates *rates; |
| 398 | struct amount_msat *channel_fee_base_msat, *lease_base_msat; |
| 399 | u32 *lease_basis, *channel_fee_max_ppt, *funding_weight; |
| 400 | |
| 401 | if (!param(cmd, buffer, params, |
| 402 | p_req("lease_fee_base_msat", param_msat, &lease_base_msat), |
| 403 | p_req("lease_fee_basis", param_number, &lease_basis), |
| 404 | p_req("funding_weight", param_number, &funding_weight), |
| 405 | p_req("channel_fee_max_base_msat", param_msat, |
| 406 | &channel_fee_base_msat), |
| 407 | p_req("channel_fee_max_proportional_thousandths", |
| 408 | param_number, &channel_fee_max_ppt), |
| 409 | NULL)) |
| 410 | return command_param_failed(); |
| 411 | |
| 412 | rates = tal(tmpctx, struct lease_rates); |
| 413 | rates->lease_fee_basis = *lease_basis; |
| 414 | rates->lease_fee_base_sat = lease_base_msat->millisatoshis / 1000; /* Raw: conversion */ |
| 415 | rates->channel_fee_max_base_msat = channel_fee_base_msat->millisatoshis; /* Raw: conversion */ |
| 416 | |
| 417 | rates->funding_weight = *funding_weight; |
| 418 | rates->channel_fee_max_proportional_thousandths |
| 419 | = *channel_fee_max_ppt; |
| 420 | |
| 421 | /* Gotta check that we didn't overflow */ |
| 422 | if (lease_base_msat->millisatoshis != rates->lease_fee_base_sat * (u64)1000) /* Raw: comparison */ |
| 423 | return command_fail_badparam(cmd, "lease_fee_base_msat", |
| 424 | buffer, params, "Overflow"); |
| 425 | |
| 426 | if (channel_fee_base_msat->millisatoshis > rates->channel_fee_max_base_msat) /* Raw: comparison */ |
| 427 | return command_fail_badparam(cmd, "channel_fee_max_base_msat", |
| 428 | buffer, params, "Overflow"); |
| 429 | |
| 430 | /* Call gossipd, let them know we've got new rates */ |
| 431 | subd_send_msg(cmd->ld->gossip, |
| 432 | take(towire_gossipd_new_lease_rates(NULL, rates))); |
| 433 | |
| 434 | res = json_stream_success(cmd); |
| 435 | json_add_amount_sat_msat(res, "lease_fee_base_msat", |
| 436 | amount_sat(rates->lease_fee_base_sat)); |
| 437 | json_add_num(res, "lease_fee_basis", rates->lease_fee_basis); |
| 438 | json_add_num(res, "funding_weight", rates->funding_weight); |
| 439 | json_add_amount_msat_only(res, "channel_fee_max_base_msat", |
| 440 | amount_msat(rates->channel_fee_max_base_msat)); |
| 441 | json_add_num(res, "channel_fee_max_proportional_thousandths", |
| 442 | rates->channel_fee_max_proportional_thousandths); |
| 443 | |
| 444 | return command_success(cmd, res); |
| 445 | } |
| 446 | |
| 447 | static const struct json_command setleaserates_command = { |
| 448 | "setleaserates", |
nothing calls this directly
no test coverage detected