From c45c767f8ea7963c268670cee0880acf2303869b Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Mon, 1 May 2017 15:19:47 +0200 Subject: [PATCH] Merge #10294: [Wallet] unset change position when there is no change 7c58863 [Wallet] unset change position when there is no change on exact match (Gregory Sanders) Tree-SHA512: ce8b9337e4132e32d80f954258d50938052c833a48e39431649d6adb16e3d18626a0ae5d300827e7fa397927fba72a1f066cb31af9b0a3ef7f1feb6024461626 --- qa/rpc-tests/fundrawtransaction.py | 5 +++++ src/wallet/wallet.cpp | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/fundrawtransaction.py b/qa/rpc-tests/fundrawtransaction.py index 53c148e68..727006d66 100755 --- a/qa/rpc-tests/fundrawtransaction.py +++ b/qa/rpc-tests/fundrawtransaction.py @@ -54,6 +54,11 @@ class RawTransactionsTest(BitcoinTestFramework): self.nodes[0].generate(121) self.sync_all() + # ensure that setting changePosition in fundraw with an exact match is handled properly + rawmatch = self.nodes[2].createrawtransaction([], {self.nodes[2].getnewaddress():50}) + rawmatch = self.nodes[2].fundrawtransaction(rawmatch, {"changePosition":1, "subtractFeeFromOutputs":[0]}) + assert_equal(rawmatch["changepos"], -1) + watchonly_address = self.nodes[0].getnewaddress() watchonly_pubkey = self.nodes[0].validateaddress(watchonly_address)["pubkey"] watchonly_amount = Decimal(2000) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 979e6e8af..561773d94 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3597,9 +3597,10 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt txNew.vout.insert(position, newTxOut); } } - } - else + } else { reservekey.ReturnKey(); + nChangePosInOut = -1; + } // Fill vin //