| 2148 | } |
| 2149 | |
| 2150 | static struct command_result *check_offer_payable(struct command *cmd, |
| 2151 | const char *offerstr, |
| 2152 | const struct amount_msat *msat) |
| 2153 | { |
| 2154 | const char *err; |
| 2155 | struct tlv_offer *b12offer = offer_decode(tmpctx, |
| 2156 | offerstr, |
| 2157 | strlen(offerstr), |
| 2158 | plugin_feature_set(cmd->plugin), |
| 2159 | chainparams, &err); |
| 2160 | if (!b12offer) |
| 2161 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 2162 | "Invalid bolt12 offer: %s", err); |
| 2163 | /* We will only one-shot if we know amount! (FIXME: Convert!) */ |
| 2164 | if (b12offer->offer_currency) |
| 2165 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 2166 | "Cannot pay offer in different currency %.*s", |
| 2167 | (int)tal_bytelen(b12offer->offer_currency), |
| 2168 | b12offer->offer_currency); |
| 2169 | if (b12offer->offer_amount) { |
| 2170 | if (msat && !amount_msat_eq(amount_msat(*b12offer->offer_amount), *msat)) { |
| 2171 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 2172 | "Offer amount is %s, you tried to pay %s", |
| 2173 | fmt_amount_msat(tmpctx, amount_msat(*b12offer->offer_amount)), |
| 2174 | fmt_amount_msat(tmpctx, *msat)); |
| 2175 | } |
| 2176 | } else { |
| 2177 | if (!msat) |
| 2178 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 2179 | "Must specify amount for this offer"); |
| 2180 | } |
| 2181 | if (offer_recurrence(b12offer)) |
| 2182 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 2183 | "Cannot xpay recurring offers"); |
| 2184 | |
| 2185 | return NULL; |
| 2186 | } |
| 2187 | |
| 2188 | static struct command_result * |
| 2189 | check_offer_sendamount_payable(struct command *cmd, const char *offerstr) |
no test coverage detected