Skip to content

Commit 887c6f7

Browse files
instagibbsrustyrussell
authored andcommitted
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
1 parent cb7caa3 commit 887c6f7

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-0
lines changed

doc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ MANPAGES := doc/lightning-cli.1 \
8686
doc/lightning-sendonionmessage.7 \
8787
doc/lightning-sendpay.7 \
8888
doc/lightning-setchannel.7 \
89+
doc/lightning-setpsbtversion.7 \
8990
doc/lightning-sendcustommsg.7 \
9091
doc/lightning-signinvoice.7 \
9192
doc/lightning-signmessage.7 \

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ Core Lightning Documentation
119119
lightning-sendpay <lightning-sendpay.7.md>
120120
lightning-sendpsbt <lightning-sendpsbt.7.md>
121121
lightning-setchannel <lightning-setchannel.7.md>
122+
lightning-setpsbtversion <lightning-setpsbtversion.7.md>
122123
lightning-signinvoice <lightning-signinvoice.7.md>
123124
lightning-signmessage <lightning-signmessage.7.md>
124125
lightning-signpsbt <lightning-signpsbt.7.md>

doc/lightning-setpsbtversion.7.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
lightning-setpsbtversion -- Command for setting PSBT version
2+
============================================================
3+
4+
SYNOPSIS
5+
--------
6+
7+
**setpsbtversion** *psbt* *version*
8+
9+
DESCRIPTION
10+
-----------
11+
12+
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.
13+
14+
- *psbt*: The PSBT to change versions.
15+
- *version*: The version to set.
16+
17+
EXAMPLE JSON REQUEST
18+
------------
19+
```json
20+
{
21+
"id": 82,
22+
"method": "setpsbtversion",
23+
"params": {
24+
"psbt": "cHNidP8BAAoCAAAAAAAAAAAAAA==",
25+
"version": "2"
26+
}
27+
}
28+
```
29+
30+
RETURN VALUE
31+
------------
32+
33+
If successful the command returns a converted PSBT of the requested version.
34+
35+
On failure, an error is returned.
36+
37+
The following error codes may occur:
38+
39+
- -32602: Parameter missed or malformed;
40+
41+
EXAMPLE JSON RESPONSE
42+
-----
43+
```json
44+
{
45+
"psbt": "cHNidP8BAgQCAAAAAQQBAAEFAQABBgEDAfsEAgAAAAA="
46+
}
47+
```
48+
49+
50+
AUTHOR
51+
------
52+
53+
Gregory Sanders <<[email protected]>> is mainly responsible.
54+
55+
SEE ALSO
56+
--------
57+
58+
lightning-fundpsbt(7), lightning-utxopsbt(7), lightning-signpsbt(7).
59+
60+
RESOURCES
61+
---------
62+
63+
Main web site: <https://github.com/ElementsProject/lightning>

tests/test_wallet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ def test_psbt_version(node_factory, bitcoind, chainparams):
813813
with pytest.raises(RpcError, match=r"Could not set PSBT version"):
814814
l1.rpc.setpsbtversion(v2_funding, i)
815815

816+
816817
@unittest.skipIf(TEST_NETWORK == 'liquid-regtest', 'Core/Elements need joinpsbt support for v2')
817818
def test_sign_and_send_psbt(node_factory, bitcoind, chainparams):
818819
"""

wallet/walletrpc.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,42 @@ static const struct json_command signpsbt_command = {
813813

814814
AUTODATA(json_command, &signpsbt_command);
815815

816+
static struct command_result *json_setpsbtversion(struct command *cmd,
817+
const char *buffer,
818+
const jsmntok_t *obj UNNEEDED,
819+
const jsmntok_t *params)
820+
{
821+
struct json_stream *response;
822+
unsigned int *version;
823+
struct wally_psbt *psbt;
824+
825+
if (!param(cmd, buffer, params,
826+
p_req("psbt", param_psbt, &psbt),
827+
p_req("version", param_number, &version),
828+
NULL))
829+
return command_param_failed();
830+
831+
if (!psbt_set_version(psbt, *version)) {
832+
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
833+
"Could not set PSBT version");
834+
}
835+
836+
response = json_stream_success(cmd);
837+
json_add_psbt(response, "psbt", psbt);
838+
839+
return command_success(cmd, response);
840+
}
841+
842+
static const struct json_command setpsbtversion_command = {
843+
"setpsbtversion",
844+
"bitcoin",
845+
json_setpsbtversion,
846+
"Convert a given PSBT to the {version} requested (v0 or v2)",
847+
false
848+
};
849+
850+
AUTODATA(json_command, &setpsbtversion_command);
851+
816852
struct sending_psbt {
817853
struct command *cmd;
818854
struct utxo **utxos;

0 commit comments

Comments
 (0)