[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.
This commit is contained in:
Sjors Provoost committed 2020-09-07 20:33:16 +02:00
1 parent 2583966130
commit 1bc8d0fd59
3 files changed
+12 -4

No files matched your search

+8 -3
View File
@@ -21,10 +21,15 @@
CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, bool rbf) CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, bool rbf)
{ {
if (inputs_in.isNull() || outputs_in.isNull()) if (outputs_in.isNull())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, arguments 1 and 2 must be non-null"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, output argument must be non-null");
UniValue inputs;
if (inputs_in.isNull())
inputs = UniValue::VARR;
else
inputs = inputs_in.get_array();
UniValue inputs = inputs_in.get_array();
const bool outputs_is_obj = outputs_in.isObject(); const bool outputs_is_obj = outputs_in.isObject();
UniValue outputs = outputs_is_obj ? outputs_in.get_obj() : outputs_in.get_array(); UniValue outputs = outputs_is_obj ? outputs_in.get_obj() : outputs_in.get_array();
+1 -1
View File
@@ -3997,7 +3997,7 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request)
"\nCreates and funds a transaction in the Partially Signed Transaction format.\n" "\nCreates and funds a transaction in the Partially Signed Transaction format.\n"
"Implements the Creator and Updater roles.\n", "Implements the Creator and Updater roles.\n",
{ {
{"inputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "The inputs. Leave empty to add inputs automatically. See add_inputs option.", {"inputs", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "Leave empty to add inputs automatically. See add_inputs option.",
{ {
{"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",
{ {
+3
View File
@@ -94,6 +94,9 @@ class PSBTTest(BitcoinTestFramework):
psbtx1 = self.nodes[0].walletcreatefundedpsbt([{"txid": utxo1['txid'], "vout": utxo1['vout']}], {self.nodes[2].getnewaddress():90}, 0, {"add_inputs": True})['psbt'] psbtx1 = self.nodes[0].walletcreatefundedpsbt([{"txid": utxo1['txid'], "vout": utxo1['vout']}], {self.nodes[2].getnewaddress():90}, 0, {"add_inputs": True})['psbt']
assert_equal(len(self.nodes[0].decodepsbt(psbtx1)['tx']['vin']), 2) assert_equal(len(self.nodes[0].decodepsbt(psbtx1)['tx']['vin']), 2)
# Inputs argument can be null
self.nodes[0].walletcreatefundedpsbt(None, {self.nodes[2].getnewaddress():10})
# Node 1 should not be able to add anything to it but still return the psbtx same as before # Node 1 should not be able to add anything to it but still return the psbtx same as before
psbtx = self.nodes[1].walletprocesspsbt(psbtx1)['psbt'] psbtx = self.nodes[1].walletprocesspsbt(psbtx1)['psbt']
assert_equal(psbtx1, psbtx) assert_equal(psbtx1, psbtx)