Skip to content

Commit 1bc8d0f

Browse files
committed
[rpc] walletcreatefundedpsbt: allow inputs to be null
This is of neglible use here, but it allows new RPC methods to take outputs as their first argument and make inputs optional.
1 parent 2583966 commit 1bc8d0f

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/rpc/rawtransaction_util.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@
2121

2222
CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, bool rbf)
2323
{
24-
if (inputs_in.isNull() || outputs_in.isNull())
25-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, arguments 1 and 2 must be non-null");
24+
if (outputs_in.isNull())
25+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, output argument must be non-null");
26+
27+
UniValue inputs;
28+
if (inputs_in.isNull())
29+
inputs = UniValue::VARR;
30+
else
31+
inputs = inputs_in.get_array();
2632

27-
UniValue inputs = inputs_in.get_array();
2833
const bool outputs_is_obj = outputs_in.isObject();
2934
UniValue outputs = outputs_is_obj ? outputs_in.get_obj() : outputs_in.get_array();
3035

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3997,7 +3997,7 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request)
39973997
"\nCreates and funds a transaction in the Partially Signed Transaction format.\n"
39983998
"Implements the Creator and Updater roles.\n",
39993999
{
4000-
{"inputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "The inputs. Leave empty to add inputs automatically. See add_inputs option.",
4000+
{"inputs", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "Leave empty to add inputs automatically. See add_inputs option.",
40014001
{
40024002
{"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",
40034003
{

test/functional/rpc_psbt.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ def run_test(self):
9494
psbtx1 = self.nodes[0].walletcreatefundedpsbt([{"txid": utxo1['txid'], "vout": utxo1['vout']}], {self.nodes[2].getnewaddress():90}, 0, {"add_inputs": True})['psbt']
9595
assert_equal(len(self.nodes[0].decodepsbt(psbtx1)['tx']['vin']), 2)
9696

97+
# Inputs argument can be null
98+
self.nodes[0].walletcreatefundedpsbt(None, {self.nodes[2].getnewaddress():10})
99+
97100
# Node 1 should not be able to add anything to it but still return the psbtx same as before
98101
psbtx = self.nodes[1].walletprocesspsbt(psbtx1)['psbt']
99102
assert_equal(psbtx1, psbtx)

0 commit comments

Comments
 (0)