Browse Source

Added spent option to listfunds

Changelog-Added: JSON-RPC: The `listfunds` method now includes spent outputs if the `spent` parameter is set to true.
ppa
Karol Hosiawa 4 years ago
committed by Christian Decker
parent
commit
a2c208e121
  1. 8
      doc/lightning-listfunds.7
  2. 5
      doc/lightning-listfunds.7.md
  3. 19
      wallet/walletrpc.c

8
doc/lightning-listfunds.7

@ -3,7 +3,7 @@
lightning-listfunds - Command showing all funds currently managed by the c-lightning node lightning-listfunds - Command showing all funds currently managed by the c-lightning node
.SH SYNOPSIS .SH SYNOPSIS
\fBlistfunds\fR \fBlistfunds\fR [\fIspent\fR]
.SH DESCRIPTION .SH DESCRIPTION
@ -11,6 +11,10 @@ The \fBlistfunds\fR RPC command displays all funds available, either in
unspent outputs (UTXOs) in the internal wallet or funds locked in unspent outputs (UTXOs) in the internal wallet or funds locked in
currently open channels\. currently open channels\.
\fIspent\fR is a boolean: if true, then the \fIoutputs\fR will include spent outputs
in addition to the unspent ones\. Default is false\.
.SH RETURN VALUE .SH RETURN VALUE
On success two arrays will be returned: \fIoutputs\fR with funds currently On success two arrays will be returned: \fIoutputs\fR with funds currently
@ -88,4 +92,4 @@ Felix \fI<fixone@gmail.com\fR> is mainly responsible\.
Main web site: \fIhttps://github.com/ElementsProject/lightning\fR Main web site: \fIhttps://github.com/ElementsProject/lightning\fR
\" SHA256STAMP:d7b4a30a1ca19e772529fbe517fb73e8c0d5c07ec3c05969ab614a4abc1865a4 \" SHA256STAMP:b59a2bed131c291e9650a6e330526b890f1e18182ccacd33aef60311f6ce2caa

5
doc/lightning-listfunds.7.md

@ -4,7 +4,7 @@ lightning-listfunds -- Command showing all funds currently managed by the c-ligh
SYNOPSIS SYNOPSIS
-------- --------
**listfunds** **listfunds** \[*spent*\]
DESCRIPTION DESCRIPTION
----------- -----------
@ -13,6 +13,9 @@ The **listfunds** RPC command displays all funds available, either in
unspent outputs (UTXOs) in the internal wallet or funds locked in unspent outputs (UTXOs) in the internal wallet or funds locked in
currently open channels. currently open channels.
*spent* is a boolean: if true, then the *outputs* will include spent outputs
in addition to the unspent ones. Default is false.
RETURN VALUE RETURN VALUE
------------ ------------

19
wallet/walletrpc.c

@ -308,18 +308,28 @@ static struct command_result *json_listfunds(struct command *cmd,
{ {
struct json_stream *response; struct json_stream *response;
struct peer *p; struct peer *p;
struct utxo **utxos, **reserved_utxos; struct utxo **utxos, **reserved_utxos, **spent_utxos;
bool *spent;
if (!param(cmd, buffer, params, NULL)) if (!param(cmd, buffer, params,
p_opt_def("spent", param_bool, &spent, false),
NULL))
return command_param_failed(); return command_param_failed();
response = json_stream_success(cmd); response = json_stream_success(cmd);
utxos = wallet_get_utxos(cmd, cmd->ld->wallet, OUTPUT_STATE_AVAILABLE); utxos = wallet_get_utxos(cmd, cmd->ld->wallet, OUTPUT_STATE_AVAILABLE);
reserved_utxos = wallet_get_utxos(cmd, cmd->ld->wallet, OUTPUT_STATE_RESERVED); reserved_utxos = wallet_get_utxos(cmd, cmd->ld->wallet, OUTPUT_STATE_RESERVED);
json_array_start(response, "outputs"); json_array_start(response, "outputs");
json_add_utxos(response, cmd->ld->wallet, utxos); json_add_utxos(response, cmd->ld->wallet, utxos);
json_add_utxos(response, cmd->ld->wallet, reserved_utxos); json_add_utxos(response, cmd->ld->wallet, reserved_utxos);
if (*spent) {
spent_utxos = wallet_get_utxos(cmd, cmd->ld->wallet, OUTPUT_STATE_SPENT);
json_add_utxos(response, cmd->ld->wallet, spent_utxos);
}
json_array_end(response); json_array_end(response);
/* Add funds that are allocated to channels */ /* Add funds that are allocated to channels */
@ -364,7 +374,10 @@ static const struct json_command listfunds_command = {
json_listfunds, json_listfunds,
"Show available funds from the internal wallet", "Show available funds from the internal wallet",
false, false,
"Returns a list of funds (outputs) that can be used by the internal wallet to open new channels or can be withdrawn, using the `withdraw` command, to another wallet." "Returns a list of funds (outputs) that can be used "
"by the internal wallet to open new channels "
"or can be withdrawn, using the `withdraw` command, to another wallet. "
"Includes spent outputs if {spent} is set to true."
}; };
AUTODATA(json_command, &listfunds_command); AUTODATA(json_command, &listfunds_command);

Loading…
Cancel
Save