diff --git a/common/json_tok.c b/common/json_tok.c index e0e3c83b4..17d094032 100644 --- a/common/json_tok.c +++ b/common/json_tok.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -499,3 +500,17 @@ struct command_result *param_bitcoin_address(struct command *cmd, } abort(); } + +struct command_result *param_psbt(struct command *cmd, + const char *name, + const char *buffer, + const jsmntok_t *tok, + struct wally_psbt **psbt) +{ + *psbt = psbt_from_b64(cmd, buffer + tok->start, tok->end - tok->start); + if (*psbt) + return NULL; + + return command_fail_badparam(cmd, name, buffer, tok, + "Expected a PSBT"); +} diff --git a/common/json_tok.h b/common/json_tok.h index e814dc615..1b918ccd1 100644 --- a/common/json_tok.h +++ b/common/json_tok.h @@ -16,6 +16,7 @@ struct command; struct command_result; struct json_escape; struct sha256; +struct wally_psbt; /* Extract json array token */ struct command_result *param_array(struct command *cmd, const char *name, @@ -165,4 +166,10 @@ struct command_result *param_bitcoin_address(struct command *cmd, const char *buffer, const jsmntok_t *tok, const u8 **scriptpubkey); + +struct command_result *param_psbt(struct command *cmd, + const char *name, + const char *buffer, + const jsmntok_t *tok, + struct wally_psbt **psbt); #endif /* LIGHTNING_COMMON_JSON_TOK_H */ diff --git a/tests/test_wallet.py b/tests/test_wallet.py index 6e0b3be91..9ff295ee5 100644 --- a/tests/test_wallet.py +++ b/tests/test_wallet.py @@ -789,14 +789,14 @@ def test_sign_and_send_psbt(node_factory, bitcoind, chainparams): bitcoind.rpc.sendrawtransaction(broadcast_tx['tx']) # Try an empty PSBT - with pytest.raises(RpcError, match=r"should be a PSBT, not"): + with pytest.raises(RpcError, match=r"psbt: Expected a PSBT: invalid token"): l1.rpc.signpsbt('') - with pytest.raises(RpcError, match=r"should be a PSBT, not"): + with pytest.raises(RpcError, match=r"psbt: Expected a PSBT: invalid token"): l1.rpc.sendpsbt('') # Try an invalid PSBT string invalid_psbt = 'cHNidP8BAM0CAAAABJ9446mTRp/ml8OxSLC1hEvrcxG1L02AG7YZ4syHon2sAQAAAAD9////JFJH/NjKwjwrP9myuU68G7t8Q4VIChH0KUkZ5hSAyqcAAAAAAP3///8Uhrj0XDRhGRno8V7qEe4hHvZcmEjt3LQSIXWc+QU2tAEAAAAA/f///wstLikuBrgZJI83VPaY8aM7aPe5U6TMb06+jvGYzQLEAQAAAAD9////AcDGLQAAAAAAFgAUyQltQ/QI6lJgICYsza18hRa5KoEAAAAAAAEBH0BCDwAAAAAAFgAUqc1Qh7Q5kY1noDksmj7cJmHaIbQAAQEfQEIPAAAAAAAWABS3bdYeQbXvBSryHNoyYIiMBwu5rwABASBAQg8AAAAAABepFD1r0NuqAA+R7zDiXrlP7J+/PcNZhwEEFgAUKvGgVL/ThjWE/P1oORVXh/ObucYAAQEgQEIPAAAAAAAXqRRsrE5ugA1VJnAith5+msRMUTwl8ocBBBYAFMrfGCiLi0ZnOCY83ERKJ1sLYMY8A=' - with pytest.raises(RpcError, match=r"should be a PSBT, not"): + with pytest.raises(RpcError, match=r"psbt: Expected a PSBT: invalid token"): l1.rpc.signpsbt(invalid_psbt) wallet_coin_mvts = [ diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 07b239972..3d069ff54 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -594,22 +594,6 @@ static const struct json_command listtransactions_command = { }; AUTODATA(json_command, &listtransactions_command); -struct command_result *param_psbt(struct command *cmd, - const char *name, - const char *buffer, - const jsmntok_t *tok, - struct wally_psbt **psbt) -{ - *psbt = psbt_from_b64(cmd, buffer + tok->start, tok->end - tok->start); - if (*psbt) - return NULL; - - return command_fail(cmd, JSONRPC2_INVALID_PARAMS, - "'%s' should be a PSBT, not '%.*s'", - name, json_tok_full_len(tok), - json_tok_full(buffer, tok)); -} - static bool in_only_inputs(const u32 *only_inputs, u32 this) { for (size_t i = 0; i < tal_count(only_inputs); i++) diff --git a/wallet/walletrpc.h b/wallet/walletrpc.h index c7f8e16af..25af4a0a5 100644 --- a/wallet/walletrpc.h +++ b/wallet/walletrpc.h @@ -6,7 +6,6 @@ struct command; struct json_stream; struct utxo; -struct wally_psbt; void json_add_utxos(struct json_stream *response, struct wallet *wallet, @@ -15,9 +14,4 @@ void json_add_utxos(struct json_stream *response, /* We evaluate reserved timeouts lazily, so use this. */ bool is_reserved(const struct utxo *utxo, u32 current_height); -struct command_result *param_psbt(struct command *cmd, - const char *name, - const char *buffer, - const jsmntok_t *tok, - struct wally_psbt **psbt); #endif /* LIGHTNING_WALLET_WALLETRPC_H */