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

Function parse_lease_rates

plugins/funder.c:863–916  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

861}
862
863static struct command_result *
864parse_lease_rates(struct command *cmd, const char *buffer,
865 const jsmntok_t *tok,
866 struct funder_policy *policy,
867 struct funder_policy *current_policy,
868 u32 *lease_fee_basis,
869 struct amount_sat *lease_fee_sats,
870 u32 *funding_weight,
871 u32 *channel_fee_max_proportional_thousandths,
872 struct amount_msat *chan_fee_msats)
873
874{
875 /* If there's already rates set, we start with those */
876 if (!lease_rates_empty(current_policy->rates))
877 policy->rates = tal_dup(policy, struct lease_rates,
878 current_policy->rates);
879 else if (lease_fee_basis
880 || lease_fee_sats
881 || funding_weight
882 || channel_fee_max_proportional_thousandths
883 || chan_fee_msats)
884 policy->rates = default_lease_rates(policy);
885 else
886 policy->rates = NULL;
887
888 /* Sometimes a local macro is neater than the alternative */
889#define ASSIGN_OR_RETURN_FAIL(type, member) \
890 do { \
891 if (member && \
892 !assign_overflow_##type(&policy->rates->member, *member)) \
893 return command_fail_badparam(cmd, #member, \
894 buffer, tok, "overflow"); \
895} while(0)
896
897 ASSIGN_OR_RETURN_FAIL(u16, lease_fee_basis);
898 ASSIGN_OR_RETURN_FAIL(u16, funding_weight);
899 ASSIGN_OR_RETURN_FAIL(u16, channel_fee_max_proportional_thousandths);
900#undef ASSIGN_OR_RETURN_FAIL
901
902 if (chan_fee_msats
903 && !assign_overflow_u32(&policy->rates->channel_fee_max_base_msat,
904 chan_fee_msats->millisatoshis /* Raw: conversion */)) {
905 return command_fail_badparam(cmd, "channel_fee_max_base_msat",
906 buffer, tok, "overflow");
907 }
908 if (lease_fee_sats
909 && !assign_overflow_u32(&policy->rates->lease_fee_base_sat,
910 lease_fee_sats->satoshis /* Raw: conversion */)) {
911 return command_fail_badparam(cmd, "lease_fee_base_sat",
912 buffer, tok, "overflow");
913 }
914
915 return NULL;
916}
917
918static struct command_result *
919leaserates_set(struct command *cmd, const char *buf,

Callers 1

json_funderupdateFunction · 0.85

Calls 4

lease_rates_emptyFunction · 0.85
default_lease_ratesFunction · 0.85
assign_overflow_u32Function · 0.85
command_fail_badparamFunction · 0.85

Tested by

no test coverage detected