From 7eccce4e44a5d64f08146637103dbd293622efc7 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 6 Feb 2017 14:14:28 -0800 Subject: [PATCH 1/2] Closes #2045 by allowing z_sendmany with 0 fee --- src/wallet/asyncrpcoperation_sendmany.cpp | 2 +- src/wallet/rpcwallet.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index f0600c7f0..c01d7d0c2 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -55,7 +55,7 @@ AsyncRPCOperation_sendmany::AsyncRPCOperation_sendmany( Value contextInfo) : fromaddress_(fromAddress), t_outputs_(tOutputs), z_outputs_(zOutputs), mindepth_(minDepth), fee_(fee), contextinfo_(contextInfo) { - assert(fee_ > 0); + assert(fee_ >= 0); if (minDepth < 0) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Minconf cannot be negative"); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1a329227a..3240fc972 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3383,7 +3383,12 @@ Value z_sendmany(const Array& params, bool fHelp) // Fee in Zatoshis, not currency format) CAmount nFee = ASYNC_RPC_OPERATION_DEFAULT_MINERS_FEE; if (params.size() > 3) { - nFee = AmountFromValue( params[3] ); + if (params[3].get_real() == 0.0) { + nFee = 0; + } else { + nFee = AmountFromValue( params[3] ); + } + // Check that the user specified fee is sane. if (nFee > nTotalOut) { throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Fee %s is greater than the sum of outputs %s", FormatMoney(nFee), FormatMoney(nTotalOut))); From 75bb764bb85aaf3e2ad9deb06f7d3aa52e6d0e84 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 8 Feb 2017 15:26:33 -0800 Subject: [PATCH 2/2] Add test for z_sendmany with fee of 0 --- qa/rpc-tests/wallet_protectcoinbase.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/qa/rpc-tests/wallet_protectcoinbase.py b/qa/rpc-tests/wallet_protectcoinbase.py index e99a4943b..630be7bde 100755 --- a/qa/rpc-tests/wallet_protectcoinbase.py +++ b/qa/rpc-tests/wallet_protectcoinbase.py @@ -139,6 +139,19 @@ class WalletProtectCoinbaseTest (BitcoinTestFramework): assert_equal(Decimal(resp["private"]), Decimal('19.9999')) assert_equal(Decimal(resp["total"]), Decimal('39.9999')) + # A custom fee of 0 is okay. Here the node will send the note value back to itself. + recipients = [] + recipients.append({"address":myzaddr, "amount": Decimal('19.9999')}) + myopid = self.nodes[0].z_sendmany(myzaddr, recipients, 1, Decimal('0.0')) + mytxid = self.wait_and_assert_operationid_status(myopid) + self.sync_all() + self.nodes[1].generate(1) + self.sync_all() + resp = self.nodes[0].z_gettotalbalance() + assert_equal(Decimal(resp["transparent"]), Decimal('20.0')) + assert_equal(Decimal(resp["private"]), Decimal('19.9999')) + assert_equal(Decimal(resp["total"]), Decimal('39.9999')) + # convert note to transparent funds recipients = [] recipients.append({"address":mytaddr, "amount":Decimal('10.0')})