Browse Source

fundchannel: take a 'close_to' address

Finally, extends the 'close_to' functionality up to the flagship 'open a
channel' command.

Changelog-Added: JSON-API `fundchannel` now accepts an optional 'close_to' param, a bitcoin address that the channel funding should be sent to on close. Requires `opt_upfront_shutdownscript`
travis-experimental
niftynei 4 years ago
committed by Rusty Russell
parent
commit
4926c25bb5
  1. 6
      contrib/pyln-client/pyln/client/lightning.py
  2. 14
      doc/lightning-fundchannel.7
  3. 10
      doc/lightning-fundchannel.7.md
  4. 11
      plugins/spender/fundchannel.c

6
contrib/pyln-client/pyln/client/lightning.py

@ -657,12 +657,13 @@ class LightningRpc(UnixDomainSocketRpc):
Only select outputs with {minconf} confirmations. Only select outputs with {minconf} confirmations.
If {utxos} is specified (as a list of 'txid:vout' strings), If {utxos} is specified (as a list of 'txid:vout' strings),
fund a channel from these specifics utxos. fund a channel from these specifics utxos.
{close_to} is a valid Bitcoin address.
""" """
if 'satoshi' in kwargs: if 'satoshi' in kwargs:
return self._deprecated_fundchannel(node_id, *args, **kwargs) return self._deprecated_fundchannel(node_id, *args, **kwargs)
def _fundchannel(node_id, amount, feerate=None, announce=True, minconf=None, utxos=None, push_msat=None): def _fundchannel(node_id, amount, feerate=None, announce=True, minconf=None, utxos=None, push_msat=None, close_to=None):
payload = { payload = {
"id": node_id, "id": node_id,
"amount": amount, "amount": amount,
@ -670,7 +671,8 @@ class LightningRpc(UnixDomainSocketRpc):
"announce": announce, "announce": announce,
"minconf": minconf, "minconf": minconf,
"utxos": utxos, "utxos": utxos,
"push_msat": push_msat "push_msat": push_msat,
"close_to": close_to,
} }
return self.call("fundchannel", payload) return self.call("fundchannel", payload)

14
doc/lightning-fundchannel.7

@ -4,7 +4,7 @@ lightning-fundchannel - Command for establishing a lightning channel
.SH SYNOPSIS .SH SYNOPSIS
\fBfundchannel\fR \fIid\fR \fIamount\fR [\fIfeerate\fR \fIannounce\fR] [\fIminconf\fR] \fBfundchannel\fR \fIid\fR \fIamount\fR [\fIfeerate\fR \fIannounce\fR] [\fIminconf\fR]
[\fIutxos\fR] [\fIpush_msat\fR] [\fIutxos\fR] [\fIpush_msat\fR] [\fIclose_to\fR]
.SH DESCRIPTION .SH DESCRIPTION
@ -66,6 +66,11 @@ open\. Note that this is a gift to the peer -- these satoshis are
added to the initial balance of the peer at channel start and are largely added to the initial balance of the peer at channel start and are largely
unrecoverable once pushed\. unrecoverable once pushed\.
\fIclose_to\fR is a Bitcoin address to which the channel funds should be sent to
on close\. Only valid if both peers have negotiated \fBoption_upfront_shutdown_script\fR\.
Returns \fBclose_to\fR set to closing script iff is negotiated\.
.SH RETURN VALUE .SH RETURN VALUE
On success, the \fItx\fR and \fItxid\fR of the transaction is returned, as well On success, the \fItx\fR and \fItxid\fR of the transaction is returned, as well
@ -74,6 +79,11 @@ as the \fIchannel_id\fR of the newly created channel\. On failure, an error
is reported and the channel is not funded\. is reported and the channel is not funded\.
If a \fBclose_to\fR address was provided, will close to this address
iff the \fBclose_to\fR script is returned in the response\. Otherwise,
the peer does not support \fBoption_upfront_shutdownscript\fR\.
The following error codes may occur: The following error codes may occur:
.RS .RS
@ -102,4 +112,4 @@ channel parameters (funding limits, channel reserves, fees, etc\.)\.
Main web site: \fIhttps://github.com/ElementsProject/lightning\fR Main web site: \fIhttps://github.com/ElementsProject/lightning\fR
\" SHA256STAMP:f885008c6e60738b1ec9c5def19cc0877b0f9a72498ffa60e9fb3277ed9d9919 \" SHA256STAMP:05dff04e52740da20760c2501ed7958d646750284f6a55904ca39c4ca69c46fc

10
doc/lightning-fundchannel.7.md

@ -5,7 +5,7 @@ SYNOPSIS
-------- --------
**fundchannel** *id* *amount* \[*feerate* *announce*\] \[*minconf*\] **fundchannel** *id* *amount* \[*feerate* *announce*\] \[*minconf*\]
\[*utxos*\] \[*push_msat*\] \[*utxos*\] \[*push_msat*\] \[*close_to*\]
DESCRIPTION DESCRIPTION
----------- -----------
@ -60,6 +60,10 @@ open. Note that this is a gift to the peer -- these satoshis are
added to the initial balance of the peer at channel start and are largely added to the initial balance of the peer at channel start and are largely
unrecoverable once pushed. unrecoverable once pushed.
*close_to* is a Bitcoin address to which the channel funds should be sent to
on close. Only valid if both peers have negotiated `option_upfront_shutdown_script`.
Returns `close_to` set to closing script iff is negotiated.
RETURN VALUE RETURN VALUE
------------ ------------
@ -68,6 +72,10 @@ as the *outnum* indicating the output index which creates the channel, as well
as the *channel\_id* of the newly created channel. On failure, an error as the *channel\_id* of the newly created channel. On failure, an error
is reported and the channel is not funded. is reported and the channel is not funded.
If a `close_to` address was provided, will close to this address
iff the `close_to` script is returned in the response. Otherwise,
the peer does not support `option_upfront_shutdownscript`.
The following error codes may occur: The following error codes may occur:
- -1: Catchall nonspecific error. - -1: Catchall nonspecific error.
- 300: The maximum allowed funding amount is exceeded. - 300: The maximum allowed funding amount is exceeded.

11
plugins/spender/fundchannel.c

@ -41,6 +41,7 @@ json_fundchannel(struct command *cmd,
const jsmntok_t *minconf; const jsmntok_t *minconf;
const jsmntok_t *utxos; const jsmntok_t *utxos;
const jsmntok_t *push_msat; const jsmntok_t *push_msat;
const jsmntok_t *close_to;
struct out_req *req; struct out_req *req;
@ -52,6 +53,7 @@ json_fundchannel(struct command *cmd,
p_opt("minconf", param_tok, &minconf), p_opt("minconf", param_tok, &minconf),
p_opt("utxos", param_tok, &utxos), p_opt("utxos", param_tok, &utxos),
p_opt("push_msat", param_tok, &push_msat), p_opt("push_msat", param_tok, &push_msat),
p_opt("close_to", param_tok, &close_to),
NULL)) NULL))
return command_param_failed(); return command_param_failed();
@ -67,6 +69,8 @@ json_fundchannel(struct command *cmd,
json_add_tok(req->js, "announce", announce, buf); json_add_tok(req->js, "announce", announce, buf);
if (push_msat) if (push_msat)
json_add_tok(req->js, "push_msat", push_msat, buf); json_add_tok(req->js, "push_msat", push_msat, buf);
if (close_to)
json_add_tok(req->js, "close_to", close_to, buf);
json_object_end(req->js); json_object_end(req->js);
json_array_end(req->js); json_array_end(req->js);
if (feerate) if (feerate)
@ -92,6 +96,7 @@ fundchannel_get_result(struct command *cmd,
const jsmntok_t *channel_ids_obj; const jsmntok_t *channel_ids_obj;
const jsmntok_t *channel_id; const jsmntok_t *channel_id;
const jsmntok_t *outnum; const jsmntok_t *outnum;
const jsmntok_t *close_to_script;
struct json_stream *out; struct json_stream *out;
@ -108,6 +113,10 @@ fundchannel_get_result(struct command *cmd,
ok = ok && channel_id; ok = ok && channel_id;
outnum = ok ? json_get_member(buf, channel_ids_obj, "outnum") : NULL; outnum = ok ? json_get_member(buf, channel_ids_obj, "outnum") : NULL;
ok = ok && outnum; ok = ok && outnum;
close_to_script = ok ? json_get_member(buf, channel_ids_obj,
"close_to")
: NULL;
if (!ok) if (!ok)
plugin_err(cmd->plugin, plugin_err(cmd->plugin,
@ -120,5 +129,7 @@ fundchannel_get_result(struct command *cmd,
json_add_tok(out, "txid", txid, buf); json_add_tok(out, "txid", txid, buf);
json_add_tok(out, "channel_id", channel_id, buf); json_add_tok(out, "channel_id", channel_id, buf);
json_add_tok(out, "outnum", outnum, buf); json_add_tok(out, "outnum", outnum, buf);
if (close_to_script)
json_add_tok(out, "close_to", close_to_script, buf);
return command_finished(cmd, out); return command_finished(cmd, out);
} }

Loading…
Cancel
Save