Skip to content

Commit

Permalink
listfunds: also list reserved outputs
Browse files Browse the repository at this point in the history
Currently 'listfunds' lies, a teensy eeinsy bit, in that it doesn't list
all of the funds in a wallet (it omits reserved wallet UTXOs). This
change makes the reserved outputs visible by listing them in the
'outputs' section along with a new field, 'reserved', which denotes the
UTXO's state

Changelog-Changed: JSON-RPC: `listfunds` 'outputs' now includes reserved outputs, designated as 'reserved' = true
  • Loading branch information
niftynei authored and cdecker committed Jun 16, 2020
1 parent 5bb1fd4 commit 431463b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
6 changes: 6 additions & 0 deletions doc/lightning-listfunds.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions doc/lightning-listfunds.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Each entry in *outputs* will include:
appended)
- *address*
- *status* (whether *unconfirmed*, *confirmed*, or *spent*)
- *reserved* (whether this is UTXO is currently reserved for an in-flight tx)

Each entry in *channels* will include:
- *peer\_id* - the peer with which the channel is opened.
Expand Down
46 changes: 33 additions & 13 deletions wallet/walletrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,23 +797,13 @@ static const struct json_command listaddrs_command = {
};
AUTODATA(json_command, &listaddrs_command);

static struct command_result *json_listfunds(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
static struct command_result *json_outputs(struct command *cmd,
struct json_stream *response,
struct utxo **utxos)
{
struct json_stream *response;
struct peer *p;
struct utxo **utxos;
char* out;
struct pubkey funding_pubkey;

if (!param(cmd, buffer, params, NULL))
return command_param_failed();

utxos = wallet_get_utxos(cmd, cmd->ld->wallet, output_state_available);
response = json_stream_success(cmd);
json_array_start(response, "outputs");
for (size_t i = 0; i < tal_count(utxos); i++) {
json_object_start(response, NULL);
json_add_txid(response, "txid", &utxos[i]->txid);
Expand Down Expand Up @@ -850,8 +840,38 @@ static struct command_result *json_listfunds(struct command *cmd,
} else
json_add_string(response, "status", "unconfirmed");

json_add_bool(response, "reserved",
utxos[i]->status == output_state_reserved);
json_object_end(response);
}

return NULL;
}

static struct command_result *json_listfunds(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct json_stream *response;
struct peer *p;
struct utxo **utxos, **reserved_utxos;
struct command_result *ret;

if (!param(cmd, buffer, params, NULL))
return command_param_failed();

response = json_stream_success(cmd);

utxos = wallet_get_utxos(cmd, cmd->ld->wallet, output_state_available);
reserved_utxos = wallet_get_utxos(cmd, cmd->ld->wallet, output_state_reserved);
json_array_start(response, "outputs");
ret = json_outputs(cmd, response, utxos);
if (ret)
return ret;
ret = json_outputs(cmd, response, reserved_utxos);
if (ret)
return ret;
json_array_end(response);

/* Add funds that are allocated to channels */
Expand Down

0 comments on commit 431463b

Please sign in to comment.