Skip to content

Commit 93b6c6f

Browse files
cdeckerrustyrussell
authored andcommitted
keysend: Add extra-tlvs option to keysend
Changelog-Added: keysend: You can now add extra TLVs to a payment sent via `keysend`
1 parent aba9af9 commit 93b6c6f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

plugins/keysend.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static struct node_id my_id;
2828

2929
struct keysend_data {
3030
struct preimage preimage;
31+
struct tlv_field *extra_tlvs;
3132
};
3233

3334
REGISTER_PAYMENT_MODIFIER_HEADER(keysend, struct keysend_data);
@@ -44,6 +45,9 @@ static struct keysend_data *keysend_init(struct payment *p)
4445
randombytes_buf(&d->preimage, sizeof(d->preimage));
4546
ccan_sha256(&payment_hash, &d->preimage, sizeof(d->preimage));
4647
p->payment_hash = tal_dup(p, struct sha256, &payment_hash);
48+
#if EXPERIMENTAL_FEATURES
49+
d->extra_tlvs = NULL;
50+
#endif
4751
return d;
4852
} else {
4953
/* If we are a child payment (retry or split) we copy the
@@ -91,6 +95,16 @@ static void keysend_cb(struct keysend_data *d, struct payment *p) {
9195
tlvstream_set_raw(&last_payload->tlv_payload->fields, PREIMAGE_TLV_TYPE,
9296
&d->preimage, sizeof(struct preimage));
9397

98+
#if EXPERIMENTAL_FEATURES
99+
if (d->extra_tlvs != NULL) {
100+
for (size_t i = 0; i < tal_count(d->extra_tlvs); i++) {
101+
struct tlv_field *f = &d->extra_tlvs[i];
102+
tlvstream_set_raw(&last_payload->tlv_payload->fields,
103+
f->numtype, f->value, f->length);
104+
}
105+
}
106+
#endif
107+
94108
return payment_continue(p);
95109
}
96110

@@ -135,6 +149,10 @@ static struct command_result *json_keysend(struct command *cmd, const char *buf,
135149
u64 *maxfee_pct_millionths;
136150
u32 *maxdelay;
137151
unsigned int *retryfor;
152+
#if EXPERIMENTAL_FEATURES
153+
struct tlv_field *extra_fields;
154+
#endif
155+
138156
#if DEVELOPER
139157
bool *use_shadow;
140158
#endif
@@ -150,6 +168,9 @@ static struct command_result *json_keysend(struct command *cmd, const char *buf,
150168
p_opt_def("exemptfee", param_msat, &exemptfee, AMOUNT_MSAT(5000)),
151169
#if DEVELOPER
152170
p_opt_def("use_shadow", param_bool, &use_shadow, true),
171+
#endif
172+
#if EXPERIMENTAL_FEATURES
173+
p_opt("extratlvs", param_extra_tlvs, &extra_fields),
153174
#endif
154175
NULL))
155176
return command_param_failed();
@@ -187,6 +208,11 @@ static struct command_result *json_keysend(struct command *cmd, const char *buf,
187208

188209
p->constraints.cltv_budget = *maxdelay;
189210

211+
#if EXPERIMENTAL_FEATURES
212+
payment_mod_keysend_get_data(p)->extra_tlvs =
213+
tal_steal(p, extra_fields);
214+
#endif
215+
190216
payment_mod_exemptfee_get_data(p)->amount = *exemptfee;
191217
#if DEVELOPER
192218
payment_mod_shadowroute_get_data(p)->use_shadow = *use_shadow;

0 commit comments

Comments
 (0)