From d02496b89b8d15f2390e1a93bc622148b47c1b2f Mon Sep 17 00:00:00 2001
From: Kristaps Kaupe <kristaps@blogiem.lv>
Date: Thu, 25 Jul 2019 22:48:36 +0300
Subject: [PATCH] Return output idx for a funding tx in a channel information
 in listfunds

---
 CHANGELOG.md                  |  1 +
 doc/lightning-listfunds.7     | 33 +++++++++++++++++++++++++--------
 doc/lightning-listfunds.7.txt |  2 ++
 wallet/walletrpc.c            |  2 ++
 4 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d4468f621..b2e3378bd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Added
 
 - Lightningd: add support for `signet` networks using the `--network=signet` or `--signet` startup option
+- JSON API: `listfunds` now returns also `funding_output` for `channels`
 
 ### Changed
 
diff --git a/doc/lightning-listfunds.7 b/doc/lightning-listfunds.7
index 52f0442f3..eac1e665b 100644
--- a/doc/lightning-listfunds.7
+++ b/doc/lightning-listfunds.7
@@ -2,12 +2,12 @@
 .\"     Title: lightning-listfunds
 .\"    Author: [see the "AUTHOR" section]
 .\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
-.\"      Date: 05/09/2019
+.\"      Date: 07/25/2019
 .\"    Manual: \ \&
 .\"    Source: \ \&
 .\"  Language: English
 .\"
-.TH "LIGHTNING\-LISTFUNDS" "7" "05/09/2019" "\ \&" "\ \&"
+.TH "LIGHTNING\-LISTFUNDS" "7" "07/25/2019" "\ \&" "\ \&"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
@@ -60,7 +60,8 @@ Each entry in \fIoutputs\fR will include:
 .sp -1
 .IP \(bu 2.3
 .\}
-\fIoutput\fR (the index of the output in the transaction)
+\fIoutput\fR
+(the index of the output in the transaction)
 .RE
 .sp
 .RS 4
@@ -71,7 +72,8 @@ Each entry in \fIoutputs\fR will include:
 .sp -1
 .IP \(bu 2.3
 .\}
-\fIvalue\fR (the output value in satoshis)
+\fIvalue\fR
+(the output value in satoshis)
 .RE
 .sp
 .RS 4
@@ -82,10 +84,9 @@ Each entry in \fIoutputs\fR will include:
 .sp -1
 .IP \(bu 2.3
 .\}
-\fIamount_sat\fR
+\fIamount_msat\fR
 (the same as
-\fIvalue\fR
-, but in millisatoshis with
+\fIvalue\fR, but in millisatoshi with
 \fImsat\fR
 appended)
 .RE
@@ -109,7 +110,11 @@ appended)
 .sp -1
 .IP \(bu 2.3
 .\}
-\fIstatus\fR (whether \fIunconfirmed\fR, \fIconfirmed\fR, or \fIspent\fR)
+\fIstatus\fR
+(whether
+\fIunconfirmed\fR,
+\fIconfirmed\fR, or
+\fIspent\fR)
 .RE
 .sp
 Each entry in \fIchannels\fR will include:
@@ -201,6 +206,18 @@ appended\&.
 \fIfunding_txid\fR
 \- funding transaction id\&.
 .RE
+.sp
+.RS 4
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+\fIfunding_output\fR
+\- the index of the output in the funding transaction\&.
+.RE
 .SH "AUTHOR"
 .sp
 Felix <fixone@gmail\&.com> is mainly responsible\&.
diff --git a/doc/lightning-listfunds.7.txt b/doc/lightning-listfunds.7.txt
index b9b19f4f6..65409a0a0 100644
--- a/doc/lightning-listfunds.7.txt
+++ b/doc/lightning-listfunds.7.txt
@@ -55,6 +55,8 @@ number and output index of the channel funding transaction).
 
 - 'funding_txid' - funding transaction id.
 
+- 'funding_output' - the index of the output in the funding transaction.
+
 AUTHOR
 ------
 Felix <fixone@gmail.com> is mainly responsible.
diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c
index 6fa59bda1..c1ced7038 100644
--- a/wallet/walletrpc.c
+++ b/wallet/walletrpc.c
@@ -657,6 +657,8 @@ static struct command_result *json_listfunds(struct command *cmd,
 						   "amount_msat");
 			json_add_txid(response, "funding_txid",
 				      &c->funding_txid);
+			json_add_num(response, "funding_output",
+				      c->funding_outnum);
 			json_object_end(response);
 		}
 	}