diff --git a/doc/lightning-fundchannel.7 b/doc/lightning-fundchannel.7 index 9a5547704..246104615 100644 --- a/doc/lightning-fundchannel.7 +++ b/doc/lightning-fundchannel.7 @@ -69,6 +69,7 @@ unrecoverable once pushed\. .SH RETURN VALUE On success, the \fItx\fR and \fItxid\fR of the transaction is returned, as well +as the \fIoutnum\fR indicating the output index which creates the channel, as well as the \fIchannel_id\fR of the newly created channel\. On failure, an error is reported and the channel is not funded\. diff --git a/doc/lightning-fundchannel.7.md b/doc/lightning-fundchannel.7.md index 879e58998..f9809f26f 100644 --- a/doc/lightning-fundchannel.7.md +++ b/doc/lightning-fundchannel.7.md @@ -64,6 +64,7 @@ RETURN VALUE ------------ On success, the *tx* and *txid* of the transaction is returned, as well +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 is reported and the channel is not funded. diff --git a/plugins/fundchannel.c b/plugins/fundchannel.c index 06b733088..a794dbe9b 100644 --- a/plugins/fundchannel.c +++ b/plugins/fundchannel.c @@ -34,6 +34,7 @@ struct funding_req { /* The prepared tx id */ struct bitcoin_txid tx_id; + u32 outnum; const char *chanstr; const u8 *out_script; @@ -86,6 +87,7 @@ static struct command_result *finish(struct command *cmd, json_add_tok(out, "tx", json_get_member(buf, result, "tx"), buf); json_add_string(out, "txid", type_to_string(tmpctx, struct bitcoin_txid, &fr->tx_id)); + json_add_u32(out, "outnum", fr->outnum); json_add_string(out, "channel_id", fr->chanstr); return command_finished(cmd, out); @@ -130,7 +132,6 @@ static struct command_result *tx_prepare_done(struct command *cmd, struct out_req *req; const struct bitcoin_tx *tx; const char *hex; - u32 outnum; bool outnum_found; txid_tok = json_get_member(buf, result, "txid"); @@ -151,7 +152,7 @@ static struct command_result *tx_prepare_done(struct command *cmd, for (size_t i = 0; i < tx->wtx->num_outputs; i++) { const u8 *output_script = bitcoin_tx_output_get_script(fr, tx, i); if (scripteq(output_script, fr->out_script)) { - outnum = i; + fr->outnum = i; outnum_found = true; break; } @@ -171,7 +172,7 @@ static struct command_result *tx_prepare_done(struct command *cmd, json_add_string(req->js, "id", node_id_to_hexstr(tmpctx, fr->id)); /* Note that hex is reused from above */ json_add_string(req->js, "txid", hex); - json_add_u32(req->js, "txout", outnum); + json_add_u32(req->js, "txout", fr->outnum); return send_outreq(cmd->plugin, req); } diff --git a/tests/test_plugin.py b/tests/test_plugin.py index effe22091..13e8b8289 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -1211,13 +1211,16 @@ def test_bcli(node_factory, bitcoind, chainparams): l1.fundwallet(10**5) l1.connect(l2) - txid = l1.rpc.fundchannel(l2.info["id"], 10**4)["txid"] - txo = l1.rpc.call("getutxout", {"txid": txid, "vout": 0}) + fc = l1.rpc.fundchannel(l2.info["id"], 10**4) + txo = l1.rpc.call("getutxout", {"txid": fc['txid'], "vout": fc['outnum']}) assert (Millisatoshi(txo["amount"]) == Millisatoshi(10**4 * 10**3) and txo["script"].startswith("0020")) l1.rpc.close(l2.info["id"]) # When output is spent, it should give us null ! - wait_for(lambda: l1.rpc.call("getutxout", {"txid": txid, "vout": 0})['amount'] is None) + wait_for(lambda: l1.rpc.call("getutxout", { + "txid": fc['txid'], + "vout": fc['outnum'] + })['amount'] is None) resp = l1.rpc.call("sendrawtransaction", {"tx": "dummy"}) assert not resp["success"] and "decode failed" in resp["errmsg"]