mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 22:31:48 +01:00
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.
This commit is contained in:
parent
d2bd1f0fa9
commit
6b39731c6a
4 changed files with 12 additions and 6 deletions
1
doc/lightning-fundchannel.7
generated
1
doc/lightning-fundchannel.7
generated
|
@ -69,6 +69,7 @@ unrecoverable once pushed\.
|
||||||
.SH RETURN VALUE
|
.SH RETURN VALUE
|
||||||
|
|
||||||
On success, the \fItx\fR and \fItxid\fR of the transaction is returned, as well
|
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
|
as the \fIchannel_id\fR of the newly created channel\. On failure, an error
|
||||||
is reported and the channel is not funded\.
|
is reported and the channel is not funded\.
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,7 @@ RETURN VALUE
|
||||||
------------
|
------------
|
||||||
|
|
||||||
On success, the *tx* and *txid* of the transaction is returned, as well
|
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
|
as the *channel\_id* of the newly created channel. On failure, an error
|
||||||
is reported and the channel is not funded.
|
is reported and the channel is not funded.
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ struct funding_req {
|
||||||
|
|
||||||
/* The prepared tx id */
|
/* The prepared tx id */
|
||||||
struct bitcoin_txid tx_id;
|
struct bitcoin_txid tx_id;
|
||||||
|
u32 outnum;
|
||||||
|
|
||||||
const char *chanstr;
|
const char *chanstr;
|
||||||
const u8 *out_script;
|
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_tok(out, "tx", json_get_member(buf, result, "tx"), buf);
|
||||||
json_add_string(out, "txid",
|
json_add_string(out, "txid",
|
||||||
type_to_string(tmpctx, struct bitcoin_txid, &fr->tx_id));
|
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);
|
json_add_string(out, "channel_id", fr->chanstr);
|
||||||
|
|
||||||
return command_finished(cmd, out);
|
return command_finished(cmd, out);
|
||||||
|
@ -130,7 +132,6 @@ static struct command_result *tx_prepare_done(struct command *cmd,
|
||||||
struct out_req *req;
|
struct out_req *req;
|
||||||
const struct bitcoin_tx *tx;
|
const struct bitcoin_tx *tx;
|
||||||
const char *hex;
|
const char *hex;
|
||||||
u32 outnum;
|
|
||||||
bool outnum_found;
|
bool outnum_found;
|
||||||
|
|
||||||
txid_tok = json_get_member(buf, result, "txid");
|
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++) {
|
for (size_t i = 0; i < tx->wtx->num_outputs; i++) {
|
||||||
const u8 *output_script = bitcoin_tx_output_get_script(fr, tx, i);
|
const u8 *output_script = bitcoin_tx_output_get_script(fr, tx, i);
|
||||||
if (scripteq(output_script, fr->out_script)) {
|
if (scripteq(output_script, fr->out_script)) {
|
||||||
outnum = i;
|
fr->outnum = i;
|
||||||
outnum_found = true;
|
outnum_found = true;
|
||||||
break;
|
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));
|
json_add_string(req->js, "id", node_id_to_hexstr(tmpctx, fr->id));
|
||||||
/* Note that hex is reused from above */
|
/* Note that hex is reused from above */
|
||||||
json_add_string(req->js, "txid", hex);
|
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);
|
return send_outreq(cmd->plugin, req);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1211,13 +1211,16 @@ def test_bcli(node_factory, bitcoind, chainparams):
|
||||||
|
|
||||||
l1.fundwallet(10**5)
|
l1.fundwallet(10**5)
|
||||||
l1.connect(l2)
|
l1.connect(l2)
|
||||||
txid = l1.rpc.fundchannel(l2.info["id"], 10**4)["txid"]
|
fc = l1.rpc.fundchannel(l2.info["id"], 10**4)
|
||||||
txo = l1.rpc.call("getutxout", {"txid": txid, "vout": 0})
|
txo = l1.rpc.call("getutxout", {"txid": fc['txid'], "vout": fc['outnum']})
|
||||||
assert (Millisatoshi(txo["amount"]) == Millisatoshi(10**4 * 10**3)
|
assert (Millisatoshi(txo["amount"]) == Millisatoshi(10**4 * 10**3)
|
||||||
and txo["script"].startswith("0020"))
|
and txo["script"].startswith("0020"))
|
||||||
l1.rpc.close(l2.info["id"])
|
l1.rpc.close(l2.info["id"])
|
||||||
# When output is spent, it should give us null !
|
# 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"})
|
resp = l1.rpc.call("sendrawtransaction", {"tx": "dummy"})
|
||||||
assert not resp["success"] and "decode failed" in resp["errmsg"]
|
assert not resp["success"] and "decode failed" in resp["errmsg"]
|
||||||
|
|
Loading…
Add table
Reference in a new issue