diff --git a/doc/Makefile b/doc/Makefile index 66d40dcb4..976a891c8 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -86,6 +86,7 @@ MANPAGES := doc/lightning-cli.1 \ doc/lightning-sendonionmessage.7 \ doc/lightning-sendpay.7 \ doc/lightning-setchannel.7 \ + doc/lightning-setpsbtversion.7 \ doc/lightning-sendcustommsg.7 \ doc/lightning-signinvoice.7 \ doc/lightning-signmessage.7 \ diff --git a/doc/index.rst b/doc/index.rst index 428ff8273..26b78a6f9 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -119,6 +119,7 @@ Core Lightning Documentation lightning-sendpay lightning-sendpsbt lightning-setchannel + lightning-setpsbtversion lightning-signinvoice lightning-signmessage lightning-signpsbt diff --git a/doc/lightning-setpsbtversion.7.md b/doc/lightning-setpsbtversion.7.md new file mode 100644 index 000000000..753e1b77a --- /dev/null +++ b/doc/lightning-setpsbtversion.7.md @@ -0,0 +1,63 @@ +lightning-setpsbtversion -- Command for setting PSBT version +============================================================ + +SYNOPSIS +-------- + +**setpsbtversion** *psbt* *version* + +DESCRIPTION +----------- + +The **setpsbtversion** RPC command converts the provided PSBT to the given version, and returns the base64 result of the conversion. Returns an error if version is invalid. + +- *psbt*: The PSBT to change versions. +- *version*: The version to set. + +EXAMPLE JSON REQUEST +------------ +```json +{ + "id": 82, + "method": "setpsbtversion", + "params": { + "psbt": "cHNidP8BAAoCAAAAAAAAAAAAAA==", + "version": "2" + } +} +``` + +RETURN VALUE +------------ + +If successful the command returns a converted PSBT of the requested version. + +On failure, an error is returned. + +The following error codes may occur: + +- -32602: Parameter missed or malformed; + +EXAMPLE JSON RESPONSE +----- +```json +{ + "psbt": "cHNidP8BAgQCAAAAAQQBAAEFAQABBgEDAfsEAgAAAAA=" +} +``` + + +AUTHOR +------ + +Gregory Sanders <> is mainly responsible. + +SEE ALSO +-------- + +lightning-fundpsbt(7), lightning-utxopsbt(7), lightning-signpsbt(7). + +RESOURCES +--------- + +Main web site: diff --git a/tests/test_wallet.py b/tests/test_wallet.py index 707afb233..883d4aef7 100644 --- a/tests/test_wallet.py +++ b/tests/test_wallet.py @@ -813,6 +813,7 @@ def test_psbt_version(node_factory, bitcoind, chainparams): with pytest.raises(RpcError, match=r"Could not set PSBT version"): l1.rpc.setpsbtversion(v2_funding, i) + @unittest.skipIf(TEST_NETWORK == 'liquid-regtest', 'Core/Elements need joinpsbt support for v2') def test_sign_and_send_psbt(node_factory, bitcoind, chainparams): """ diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 0f6ccab73..a04613bda 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -813,6 +813,42 @@ static const struct json_command signpsbt_command = { AUTODATA(json_command, &signpsbt_command); +static struct command_result *json_setpsbtversion(struct command *cmd, + const char *buffer, + const jsmntok_t *obj UNNEEDED, + const jsmntok_t *params) +{ + struct json_stream *response; + unsigned int *version; + struct wally_psbt *psbt; + + if (!param(cmd, buffer, params, + p_req("psbt", param_psbt, &psbt), + p_req("version", param_number, &version), + NULL)) + return command_param_failed(); + + if (!psbt_set_version(psbt, *version)) { + return command_fail(cmd, JSONRPC2_INVALID_PARAMS, + "Could not set PSBT version"); + } + + response = json_stream_success(cmd); + json_add_psbt(response, "psbt", psbt); + + return command_success(cmd, response); +} + +static const struct json_command setpsbtversion_command = { + "setpsbtversion", + "bitcoin", + json_setpsbtversion, + "Convert a given PSBT to the {version} requested (v0 or v2)", + false +}; + +AUTODATA(json_command, &setpsbtversion_command); + struct sending_psbt { struct command *cmd; struct utxo **utxos;