| 1279 | } |
| 1280 | |
| 1281 | static struct command_result * |
| 1282 | parse_lease_rates(struct command *cmd, const char *buffer, |
| 1283 | const jsmntok_t *tok, |
| 1284 | struct funder_policy *policy, |
| 1285 | struct funder_policy *current_policy, |
| 1286 | u32 *lease_fee_basis, |
| 1287 | struct amount_sat *lease_fee_sats, |
| 1288 | u32 *funding_weight, |
| 1289 | u32 *channel_fee_max_proportional_thousandths, |
| 1290 | struct amount_msat *chan_fee_msats) |
| 1291 | |
| 1292 | { |
| 1293 | /* If there's already rates set, we start with those */ |
| 1294 | if (!lease_rates_empty(current_policy->rates)) |
| 1295 | policy->rates = tal_dup(policy, struct lease_rates, |
| 1296 | current_policy->rates); |
| 1297 | else if (lease_fee_basis |
| 1298 | || lease_fee_sats |
| 1299 | || funding_weight |
| 1300 | || channel_fee_max_proportional_thousandths |
| 1301 | || chan_fee_msats) |
| 1302 | policy->rates = default_lease_rates(policy); |
| 1303 | else |
| 1304 | policy->rates = NULL; |
| 1305 | |
| 1306 | /* Sometimes a local macro is neater than the alternative */ |
| 1307 | #define ASSIGN_OR_RETURN_FAIL(type, member) \ |
| 1308 | do { \ |
| 1309 | if (member && \ |
| 1310 | !assign_overflow_##type(&policy->rates->member, *member)) \ |
| 1311 | return command_fail_badparam(cmd, #member, \ |
| 1312 | buffer, tok, "overflow"); \ |
| 1313 | } while(0) |
| 1314 | |
| 1315 | ASSIGN_OR_RETURN_FAIL(u16, lease_fee_basis); |
| 1316 | ASSIGN_OR_RETURN_FAIL(u16, funding_weight); |
| 1317 | ASSIGN_OR_RETURN_FAIL(u16, channel_fee_max_proportional_thousandths); |
| 1318 | #undef ASSIGN_OR_RETURN_FAIL |
| 1319 | |
| 1320 | if (chan_fee_msats |
| 1321 | && !assign_overflow_u32(&policy->rates->channel_fee_max_base_msat, |
| 1322 | chan_fee_msats->millisatoshis /* Raw: conversion */)) { |
| 1323 | return command_fail_badparam(cmd, "channel_fee_max_base_msat", |
| 1324 | buffer, tok, "overflow"); |
| 1325 | } |
| 1326 | if (lease_fee_sats |
| 1327 | && !assign_overflow_u32(&policy->rates->lease_fee_base_sat, |
| 1328 | lease_fee_sats->satoshis /* Raw: conversion */)) { |
| 1329 | return command_fail_badparam(cmd, "lease_fee_base_sat", |
| 1330 | buffer, tok, "overflow"); |
| 1331 | } |
| 1332 | |
| 1333 | return NULL; |
| 1334 | } |
| 1335 | |
| 1336 | static struct command_result * |
| 1337 | leaserates_set(struct command *cmd, |
no test coverage detected