| 186 | } |
| 187 | |
| 188 | static bool print_recurrence(const char *fieldname, |
| 189 | const struct recurrence *recurrence, |
| 190 | const struct recurrence_paywindow *paywindow, |
| 191 | const u32 *limit, |
| 192 | const struct recurrence_base *base) |
| 193 | { |
| 194 | const char *unit; |
| 195 | bool ok = true; |
| 196 | |
| 197 | /* BOLT-recurrence #12: |
| 198 | * Thus, each offer containing a recurring payment has: |
| 199 | * 1. A `time_unit` defining 0 (seconds), 1 (days), 2 (months). |
| 200 | * 2. A `period`, defining how often (in `time_unit`) it has to be paid. |
| 201 | * 3. An optional `offer_recurrence_limit` of total payments to be paid. |
| 202 | * 4. An optional `offer_recurrence_base`: |
| 203 | * * `basetime`, defining when the first period starts |
| 204 | * in seconds since 1970-01-01 UTC. |
| 205 | * * The payer uses `invreq_recurrence_start` to indicate what period |
| 206 | * they are starting at. If you don't want them to start at arbitrary |
| 207 | * periods, use `offer_absolute_expiry`. |
| 208 | * * A `proportional_amount` flag: if set indicating that a payment made |
| 209 | * during the period itself will be charged proportionally to the |
| 210 | * remaining time in the period (e.g. 150 seconds into a 1500 second |
| 211 | * period gives a 10% discount). |
| 212 | * 5. An optional `offer_recurrence_paywindow`: |
| 213 | * * `seconds_before`, defining how many seconds prior to the start of |
| 214 | * the period a payment will be accepted. |
| 215 | * * `seconds_after`, defining how many seconds after the start of the |
| 216 | * period a payment will be accepted. |
| 217 | * If this field is missing, payment will be accepted during the prior |
| 218 | * period and the paid-for period. |
| 219 | */ |
| 220 | switch (recurrence->time_unit) { |
| 221 | case 0: |
| 222 | unit = "seconds"; |
| 223 | break; |
| 224 | case 1: |
| 225 | unit = "days"; |
| 226 | break; |
| 227 | case 2: |
| 228 | unit = "months"; |
| 229 | break; |
| 230 | default: |
| 231 | fprintf(stderr, "%s: unknown time_unit %u", fieldname, recurrence->time_unit); |
| 232 | unit = ""; |
| 233 | ok = false; |
| 234 | } |
| 235 | printf("%s: every %u %s", |
| 236 | fieldname, recurrence->period, unit); |
| 237 | if (limit) |
| 238 | printf(" limit %u", *limit); |
| 239 | if (base) { |
| 240 | printf(" start %"PRIu64" (%s)", |
| 241 | base->basetime, |
| 242 | fmt_time(tmpctx, base->basetime)); |
| 243 | if (base->proportional_amount) |
| 244 | printf(" (pay proportional)"); |
| 245 | } |