If it returns NULL, *authorized is the most we agreed to pay. */
| 2221 | |
| 2222 | /* If it returns NULL, *authorized is the most we agreed to pay. */ |
| 2223 | static struct command_result *check_offer_payable(struct command *cmd, |
| 2224 | const char *offerstr, |
| 2225 | const struct amount_msat *msat, |
| 2226 | struct amount_msat *authorized) |
| 2227 | { |
| 2228 | const char *err; |
| 2229 | struct tlv_offer *b12offer = offer_decode(tmpctx, |
| 2230 | offerstr, |
| 2231 | strlen(offerstr), |
| 2232 | plugin_feature_set(cmd->plugin), |
| 2233 | chainparams, &err); |
| 2234 | if (!b12offer) |
| 2235 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 2236 | "Invalid bolt12 offer: %s", err); |
| 2237 | /* BOLT #12: |
| 2238 | * - if `offer_amount` is not present: |
| 2239 | * - MUST specify `invreq_amount`. |
| 2240 | * - otherwise: |
| 2241 | * - MAY omit `invreq_amount`. |
| 2242 | * - if it sets `invreq_amount`: |
| 2243 | * - MUST specify `invreq_amount`.`msat` as greater or equal to amount expected by `offer_amount` (and, if present, `offer_currency` and `invreq_quantity`). |
| 2244 | */ |
| 2245 | /* We can't work out the expected amount without a conversion rate, so we |
| 2246 | * refuse currency offers here. We also require the exact offer amount, |
| 2247 | * which is stricter than the "greater or equal" the spec allows. */ |
| 2248 | /* We will only one-shot if we know amount! (FIXME: Convert!) */ |
| 2249 | if (b12offer->offer_currency) |
| 2250 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 2251 | "Cannot pay offer in different currency %.*s", |
| 2252 | (int)tal_bytelen(b12offer->offer_currency), |
| 2253 | b12offer->offer_currency); |
| 2254 | if (b12offer->offer_amount) { |
| 2255 | if (msat && !amount_msat_eq(amount_msat(*b12offer->offer_amount), *msat)) { |
| 2256 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 2257 | "Offer amount is %s, you tried to pay %s", |
| 2258 | fmt_amount_msat(tmpctx, amount_msat(*b12offer->offer_amount)), |
| 2259 | fmt_amount_msat(tmpctx, *msat)); |
| 2260 | } |
| 2261 | } else { |
| 2262 | if (!msat) |
| 2263 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 2264 | "Must specify amount for this offer"); |
| 2265 | } |
| 2266 | if (offer_recurrence(b12offer)) |
| 2267 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 2268 | "Cannot xpay recurring offers"); |
| 2269 | |
| 2270 | if (msat) |
| 2271 | *authorized = *msat; |
| 2272 | else |
| 2273 | *authorized = amount_msat(*b12offer->offer_amount); |
| 2274 | |
| 2275 | return NULL; |
| 2276 | } |
| 2277 | |
| 2278 | static struct command_result * |
| 2279 | check_offer_sendamount_payable(struct command *cmd, const char *offerstr) |
no test coverage detected