Browse Source

fundchannel: provide outnum

It's currently always 0, but it won't be once we replace txprepare.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `fundchannel` has new `outnum` field indicating which output of the transaction funds the channel.
bump-pyln-proto
Rusty Russell 5 years ago
committed by neil saitug
parent
commit
6b39731c6a
  1. 1
      doc/lightning-fundchannel.7
  2. 1
      doc/lightning-fundchannel.7.md
  3. 7
      plugins/fundchannel.c
  4. 9
      tests/test_plugin.py

1
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\.

1
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.

7
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);
}

9
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"]

Loading…
Cancel
Save