diff --git a/src/wallet/rpc/spend.cpp b/src/wallet/rpc/spend.cpp index e0fe73fbdd..8814809478 100644 --- a/src/wallet/rpc/spend.cpp +++ b/src/wallet/rpc/spend.cpp @@ -623,6 +623,7 @@ CreatedTransactionResult FundTransaction(CWallet& wallet, const CMutableTransact {"subtract_fee_from_outputs", UniValueType(UniValue::VARR)}, {"replaceable", UniValueType(UniValue::VBOOL)}, {"conf_target", UniValueType(UniValue::VNUM)}, + {"min_conf", UniValueType(UniValue::VNUM)}, {"estimate_mode", UniValueType(UniValue::VSTR)}, {"minconf", UniValueType(UniValue::VNUM)}, {"maxconf", UniValueType(UniValue::VNUM)}, @@ -705,6 +706,17 @@ CreatedTransactionResult FundTransaction(CWallet& wallet, const CMutableTransact throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative minconf"); } } + if (options.exists("min_conf")) { + if (options.exists("minconf")) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "min_conf and minconf options should not both be set. Use minconf (min_conf is deprecated)."); + } + + coinControl.m_min_depth = options["min_conf"].getInt(); + + if (coinControl.m_min_depth < 0) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative min_conf"); + } + } if (options.exists("maxconf")) { coinControl.m_max_depth = options["maxconf"].getInt(); diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py index bc19833d26..0a0a8f49e7 100755 --- a/test/functional/rpc_psbt.py +++ b/test/functional/rpc_psbt.py @@ -207,7 +207,8 @@ class PSBTTest(BitcoinTestFramework): def run_test(self): # Create and fund a raw tx for sending 10 BTC - psbtx1 = self.nodes[0].walletcreatefundedpsbt([], {self.nodes[2].getnewaddress():10})['psbt'] + assert_raises_rpc_error(-4, "Insufficient funds", self.nodes[0].walletcreatefundedpsbt, inputs=[], outputs={self.nodes[2].getnewaddress():1}, options={'min_conf': 201}) + psbtx1 = self.nodes[0].walletcreatefundedpsbt(inputs=[], outputs={self.nodes[2].getnewaddress():11}, options={'min_conf': 200})['psbt'] # If inputs are specified, do not automatically add more: utxo1 = self.nodes[0].listunspent()[0] diff --git a/test/functional/wallet_fundrawtransaction.py b/test/functional/wallet_fundrawtransaction.py index 0979a4f319..8dc26594bf 100755 --- a/test/functional/wallet_fundrawtransaction.py +++ b/test/functional/wallet_fundrawtransaction.py @@ -1042,6 +1042,16 @@ class RawTransactionsTest(BitcoinTestFramework): # The total subtracted from the outputs is equal to the fee. assert_equal(share[0] + share[2] + share[3], result[0]['fee']) + # test funding with custom min_conf + inputs = [] + outputs = {self.nodes[2].getnewaddress(): 1} + rawtx = self.nodes[3].createrawtransaction(inputs, outputs) + unspent = self.nodes[3].listunspent() + assert len(unspent) == 1 + input_confs = unspent[0]['confirmations'] + assert_raises_rpc_error(-4, "Insufficient funds", self.nodes[3].fundrawtransaction, rawtx, {'min_conf': input_confs + 1}) + result = self.nodes[3].fundrawtransaction(rawtx, {'min_conf': input_confs}) + def test_subtract_fee_with_presets(self): self.log.info("Test fundrawtxn subtract fee from outputs with preset inputs that are sufficient")