mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-08 08:34:31 +01:00
offers: make it a runtime option.
The fetchinvoice and offers plugins disable themselves if the option isn't enabled (it's enabled by default on EXPERIMENTAL_FEATURES). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Added: `experimental-offers` enables fetch, payment and creation of (early draft) offers.
This commit is contained in:
committed by
Christian Decker
parent
a4bc3e5673
commit
001b5d6416
@@ -1,10 +1,6 @@
|
||||
PLUGIN_PAY_SRC := plugins/pay.c
|
||||
PLUGIN_PAY_OBJS := $(PLUGIN_PAY_SRC:.c=.o)
|
||||
|
||||
ifeq ($(EXPERIMENTAL_FEATURES),1)
|
||||
PLUGIN_PAY_EXPERIMENTAL_OBJS := common/bolt12.o common/bolt12_merkle.o wire/bolt12$(EXP)_wiregen.o bitcoin/block.o
|
||||
endif
|
||||
|
||||
PLUGIN_AUTOCLEAN_SRC := plugins/autoclean.c
|
||||
PLUGIN_AUTOCLEAN_OBJS := $(PLUGIN_AUTOCLEAN_SRC:.c=.o)
|
||||
|
||||
@@ -50,18 +46,15 @@ PLUGIN_SPENDER_OBJS := $(PLUGIN_SPENDER_SRC:.c=.o)
|
||||
PLUGIN_ALL_SRC := \
|
||||
$(PLUGIN_AUTOCLEAN_SRC) \
|
||||
$(PLUGIN_BCLI_SRC) \
|
||||
$(PLUGIN_FETCHINVOICE_SRC) \
|
||||
$(PLUGIN_KEYSEND_SRC) \
|
||||
$(PLUGIN_TXPREPARE_SRC) \
|
||||
$(PLUGIN_LIB_SRC) \
|
||||
$(PLUGIN_OFFERS_SRC) \
|
||||
$(PLUGIN_PAY_LIB_SRC) \
|
||||
$(PLUGIN_PAY_SRC) \
|
||||
$(PLUGIN_SPENDER_SRC)
|
||||
|
||||
ifeq ($(EXPERIMENTAL_FEATURES),1)
|
||||
PLUGIN_ALL_SRC += $(PLUGIN_OFFERS_SRC)
|
||||
PLUGIN_ALL_SRC += $(PLUGIN_FETCHINVOICE_SRC)
|
||||
endif
|
||||
|
||||
PLUGIN_ALL_HEADER := \
|
||||
$(PLUGIN_LIB_HEADER) \
|
||||
$(PLUGIN_PAY_LIB_HEADER) \
|
||||
@@ -72,15 +65,13 @@ PLUGIN_ALL_OBJS := $(PLUGIN_ALL_SRC:.c=.o)
|
||||
PLUGINS := \
|
||||
plugins/autoclean \
|
||||
plugins/bcli \
|
||||
plugins/fetchinvoice \
|
||||
plugins/keysend \
|
||||
plugins/offers \
|
||||
plugins/pay \
|
||||
plugins/txprepare \
|
||||
plugins/spenderp
|
||||
|
||||
ifeq ($(EXPERIMENTAL_FEATURES),1)
|
||||
PLUGINS += plugins/offers plugins/fetchinvoice
|
||||
endif
|
||||
|
||||
# Make sure these depend on everything.
|
||||
ALL_C_SOURCES += $(PLUGIN_ALL_SRC)
|
||||
ALL_C_HEADERS += $(PLUGIN_ALL_HEADER)
|
||||
@@ -127,7 +118,7 @@ PLUGIN_COMMON_OBJS := \
|
||||
wire/tlvstream.o \
|
||||
wire/towire.o
|
||||
|
||||
plugins/pay: bitcoin/chainparams.o $(PLUGIN_PAY_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_PAY_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS) common/gossmap.o common/route.o common/dijkstra.o $(PLUGIN_PAY_EXPERIMENTAL_OBJS)
|
||||
plugins/pay: bitcoin/chainparams.o $(PLUGIN_PAY_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_PAY_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS) common/gossmap.o common/route.o common/dijkstra.o common/bolt12.o common/bolt12_merkle.o wire/bolt12$(EXP)_wiregen.o bitcoin/block.o
|
||||
$(PLUGIN_PAY_OBJS): $(PLUGIN_PAY_LIB_HEADER)
|
||||
|
||||
plugins/autoclean: bitcoin/chainparams.o $(PLUGIN_AUTOCLEAN_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)
|
||||
@@ -141,9 +132,9 @@ $(PLUGIN_KEYSEND_OBJS): $(PLUGIN_PAY_LIB_HEADER)
|
||||
|
||||
plugins/spenderp: bitcoin/chainparams.o bitcoin/psbt.o common/psbt_open.o $(PLUGIN_SPENDER_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)
|
||||
|
||||
plugins/offers: bitcoin/chainparams.o $(PLUGIN_OFFERS_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) common/bolt12.o common/bolt12_merkle.o common/bolt11_json.o common/iso4217.o wire/bolt12_exp_wiregen.o $(WIRE_OBJS) bitcoin/block.o common/channel_id.o bitcoin/preimage.o $(JSMN_OBJS) $(CCAN_OBJS)
|
||||
plugins/offers: bitcoin/chainparams.o $(PLUGIN_OFFERS_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) common/bolt12.o common/bolt12_merkle.o common/bolt11_json.o common/iso4217.o $(WIRE_OBJS) bitcoin/block.o common/channel_id.o bitcoin/preimage.o $(JSMN_OBJS) $(CCAN_OBJS)
|
||||
|
||||
plugins/fetchinvoice: bitcoin/chainparams.o $(PLUGIN_FETCHINVOICE_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) common/bolt12.o common/bolt12_merkle.o common/iso4217.o wire/bolt12_exp_wiregen.o $(WIRE_OBJS) bitcoin/block.o common/channel_id.o bitcoin/preimage.o $(JSMN_OBJS) $(CCAN_OBJS) common/gossmap.o common/dijkstra.o common/route.o common/blindedpath.o common/hmac.o common/blinding.o
|
||||
plugins/fetchinvoice: bitcoin/chainparams.o $(PLUGIN_FETCHINVOICE_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) common/bolt12.o common/bolt12_merkle.o common/iso4217.o $(WIRE_OBJS) bitcoin/block.o common/channel_id.o bitcoin/preimage.o $(JSMN_OBJS) $(CCAN_OBJS) common/gossmap.o common/dijkstra.o common/route.o common/blindedpath.o common/hmac.o common/blinding.o
|
||||
|
||||
$(PLUGIN_ALL_OBJS): $(PLUGIN_LIB_HEADER)
|
||||
|
||||
|
||||
@@ -1349,10 +1349,19 @@ static const struct plugin_command commands[] = {
|
||||
static const char *init(struct plugin *p, const char *buf UNUSED,
|
||||
const jsmntok_t *config UNUSED)
|
||||
{
|
||||
bool exp_offers;
|
||||
|
||||
rpc_scan(p, "getinfo",
|
||||
take(json_out_obj(NULL, NULL, NULL)),
|
||||
"{id:%}", JSON_SCAN(json_to_node_id, &local_id));
|
||||
|
||||
rpc_scan(p, "listconfigs",
|
||||
take(json_out_obj(NULL, "config", "experimental-offers")),
|
||||
"{experimental-offers:%}",
|
||||
JSON_SCAN(json_to_bool, &exp_offers));
|
||||
|
||||
if (!exp_offers)
|
||||
return "offers not enabled in config";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -670,6 +670,7 @@ static const char *init(struct plugin *p,
|
||||
const jsmntok_t *config UNUSED)
|
||||
{
|
||||
struct pubkey k;
|
||||
bool exp_offers;
|
||||
|
||||
rpc_scan(p, "getinfo",
|
||||
take(json_out_obj(NULL, NULL, NULL)),
|
||||
@@ -679,9 +680,13 @@ static const char *init(struct plugin *p,
|
||||
abort();
|
||||
|
||||
rpc_scan(p, "listconfigs",
|
||||
take(json_out_obj(NULL, "config", "cltv-final")),
|
||||
"{cltv-final:%}", JSON_SCAN(json_to_number, &cltv_final));
|
||||
take(json_out_obj(NULL, NULL, NULL)),
|
||||
"{cltv-final:%,experimental-offers:%}",
|
||||
JSON_SCAN(json_to_number, &cltv_final),
|
||||
JSON_SCAN(json_to_bool, &exp_offers));
|
||||
|
||||
if (!exp_offers)
|
||||
return "offers not enabled in config";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,10 +9,8 @@
|
||||
#include <ccan/tal/str/str.h>
|
||||
#include <common/amount.h>
|
||||
#include <common/bolt11.h>
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
#include <common/bolt12.h>
|
||||
#include <common/bolt12_merkle.h>
|
||||
#endif
|
||||
#include <common/errcode.h>
|
||||
#include <common/features.h>
|
||||
#include <common/gossip_constants.h>
|
||||
@@ -31,6 +29,7 @@
|
||||
/* Public key of this node. */
|
||||
static struct node_id my_id;
|
||||
static unsigned int maxdelay_default;
|
||||
static bool exp_offers;
|
||||
static bool disablempp = false;
|
||||
|
||||
static LIST_HEAD(pay_status);
|
||||
@@ -1804,10 +1803,8 @@ static struct command_result *listsendpays_done(struct command *cmd,
|
||||
u32 created_at;
|
||||
|
||||
invstrtok = json_get_member(buf, t, "bolt11");
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
if (!invstrtok)
|
||||
invstrtok = json_get_member(buf, t, "bolt12");
|
||||
#endif
|
||||
hashtok = json_get_member(buf, t, "payment_hash");
|
||||
createdtok = json_get_member(buf, t, "created_at");
|
||||
assert(hashtok != NULL);
|
||||
@@ -1909,9 +1906,10 @@ static const char *init(struct plugin *p,
|
||||
"{id:%}", JSON_SCAN(json_to_node_id, &my_id));
|
||||
|
||||
rpc_scan(p, "listconfigs",
|
||||
take(json_out_obj(NULL, "config", "max-locktime-blocks")),
|
||||
"{max-locktime-blocks:%}",
|
||||
JSON_SCAN(json_to_number, &maxdelay_default));
|
||||
take(json_out_obj(NULL, NULL, NULL)),
|
||||
"{max-locktime-blocks:%,experimental-offers:%}",
|
||||
JSON_SCAN(json_to_number, &maxdelay_default),
|
||||
JSON_SCAN(json_to_bool, &exp_offers));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -1964,10 +1962,8 @@ static struct command_result *json_paymod(struct command *cmd,
|
||||
struct shadow_route_data *shadow_route;
|
||||
struct amount_msat *invmsat;
|
||||
u64 invexpiry;
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
struct sha256 *local_offer_id;
|
||||
const struct tlv_invoice *b12;
|
||||
#endif
|
||||
#if DEVELOPER
|
||||
bool *use_shadow;
|
||||
#endif
|
||||
@@ -1988,9 +1984,7 @@ static struct command_result *json_paymod(struct command *cmd,
|
||||
p_opt_def("maxdelay", param_number, &maxdelay,
|
||||
maxdelay_default),
|
||||
p_opt_def("exemptfee", param_msat, &exemptfee, AMOUNT_MSAT(5000)),
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
p_opt("localofferid", param_sha256, &local_offer_id),
|
||||
#endif
|
||||
#if DEVELOPER
|
||||
p_opt_def("use_shadow", param_bool, &use_shadow, true),
|
||||
#endif
|
||||
@@ -2022,10 +2016,13 @@ static struct command_result *json_paymod(struct command *cmd,
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"Invalid bolt11:"
|
||||
" sets feature var_onion with no secret");
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
} else if ((b12 = invoice_decode(cmd, b11str, strlen(b11str),
|
||||
plugin_feature_set(cmd->plugin),
|
||||
chainparams, &fail)) != NULL) {
|
||||
if (!exp_offers)
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"experimental-offers disabled");
|
||||
|
||||
p->features = tal_steal(p, b12->features);
|
||||
|
||||
if (!b12->node_id)
|
||||
@@ -2082,7 +2079,6 @@ static struct command_result *json_paymod(struct command *cmd,
|
||||
else
|
||||
invexpiry = *b12->timestamp + BOLT12_DEFAULT_REL_EXPIRY;
|
||||
p->local_offer_id = tal_steal(p, local_offer_id);
|
||||
#endif /* EXPERIMENTAL_FEATURES */
|
||||
} else
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"Invalid bolt11: %s", fail);
|
||||
|
||||
Reference in New Issue
Block a user