Add PSBT version setting RPC to aid with debugging and compatibility

PSBTv2 support is quite low in the ecosystem, so having a call to convert
log messages and the like should be useful since they'll often be in v2.

Changelog-Added: Added setpsbtversion RPC to aid debugging and compatibility
This commit is contained in:
Greg Sanders 2023-03-02 15:45:40 -05:00 committed by Rusty Russell
parent cb7caa3139
commit 887c6f71cf
5 changed files with 102 additions and 0 deletions

View file

@ -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 \

View file

@ -119,6 +119,7 @@ Core Lightning Documentation
lightning-sendpay <lightning-sendpay.7.md>
lightning-sendpsbt <lightning-sendpsbt.7.md>
lightning-setchannel <lightning-setchannel.7.md>
lightning-setpsbtversion <lightning-setpsbtversion.7.md>
lightning-signinvoice <lightning-signinvoice.7.md>
lightning-signmessage <lightning-signmessage.7.md>
lightning-signpsbt <lightning-signpsbt.7.md>

View file

@ -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 <<gsanders87@gmail.com>> is mainly responsible.
SEE ALSO
--------
lightning-fundpsbt(7), lightning-utxopsbt(7), lightning-signpsbt(7).
RESOURCES
---------
Main web site: <https://github.com/ElementsProject/lightning>

View file

@ -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):
"""

View file

@ -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;