MCPcopy Create free account
hub / github.com/ElementsProject/lightning / check_offer_payable

Function check_offer_payable

plugins/xpay/xpay.c:2150–2186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2148}
2149
2150static 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
2188static struct command_result *
2189check_offer_sendamount_payable(struct command *cmd, const char *offerstr)

Callers 2

bip353_fetchedFunction · 0.85
json_xpay_paramsFunction · 0.85

Calls 8

offer_decodeFunction · 0.85
tal_bytelenFunction · 0.85
offer_recurrenceFunction · 0.85
amount_msatClass · 0.70
plugin_feature_setFunction · 0.50
command_failFunction · 0.50
amount_msat_eqFunction · 0.50
fmt_amount_msatFunction · 0.50

Tested by

no test coverage detected