| 946 | } |
| 947 | |
| 948 | static struct command_result *invreq_done(struct command *cmd, |
| 949 | const char *buf, |
| 950 | const jsmntok_t *result, |
| 951 | struct sent *sent) |
| 952 | { |
| 953 | const jsmntok_t *t; |
| 954 | char *fail; |
| 955 | enum nodeid_parity parity; |
| 956 | |
| 957 | /* Get invoice request */ |
| 958 | t = json_get_member(buf, result, "bolt12"); |
| 959 | if (!t) |
| 960 | return command_fail(cmd, LIGHTNINGD, |
| 961 | "Missing bolt12 %.*s", |
| 962 | json_tok_full_len(result), |
| 963 | json_tok_full(buf, result)); |
| 964 | |
| 965 | plugin_log(cmd->plugin, LOG_DBG, |
| 966 | "invoice_request: %.*s", |
| 967 | json_tok_full_len(t), |
| 968 | json_tok_full(buf, t)); |
| 969 | |
| 970 | sent->inv = NULL; |
| 971 | sent->invreq = invrequest_decode(sent, |
| 972 | buf + t->start, |
| 973 | t->end - t->start, |
| 974 | plugin_feature_set(cmd->plugin), |
| 975 | chainparams, |
| 976 | &fail); |
| 977 | if (!sent->invreq) |
| 978 | return command_fail(cmd, LIGHTNINGD, |
| 979 | "Invalid invoice_request %.*s: %s", |
| 980 | json_tok_full_len(t), |
| 981 | json_tok_full(buf, t), |
| 982 | fail); |
| 983 | |
| 984 | /* Now that's given us the previous base, check this is an OK time |
| 985 | * to request an invoice. */ |
| 986 | if (sent->invreq->recurrence_counter) { |
| 987 | u64 *base; |
| 988 | const jsmntok_t *pbtok; |
| 989 | u64 period_idx = *sent->invreq->recurrence_counter; |
| 990 | |
| 991 | if (sent->invreq->recurrence_start) |
| 992 | period_idx += *sent->invreq->recurrence_start; |
| 993 | |
| 994 | /* BOLT-offers-recurrence #12: |
| 995 | * - if the offer contained `recurrence_limit`: |
| 996 | * - MUST NOT send an `invoice_request` for a period greater |
| 997 | * than `max_period` |
| 998 | */ |
| 999 | if (sent->offer->recurrence_limit |
| 1000 | && period_idx > *sent->offer->recurrence_limit) |
| 1001 | return command_fail(cmd, LIGHTNINGD, |
| 1002 | "Can't send invreq for period %" |
| 1003 | PRIu64" (limit %u)", |
| 1004 | period_idx, |
| 1005 | *sent->offer->recurrence_limit); |
nothing calls this directly
no test coverage detected