Skip to content

Commit e2b99b1

Browse files
committed
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
2 parents 492d22f + 7c58863 commit e2b99b1

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/wallet/wallet.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,9 +2563,10 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
25632563
std::vector<CTxOut>::iterator position = txNew.vout.begin()+nChangePosInOut;
25642564
txNew.vout.insert(position, newTxOut);
25652565
}
2566-
}
2567-
else
2566+
} else {
25682567
reservekey.ReturnKey();
2568+
nChangePosInOut = -1;
2569+
}
25692570

25702571
// Fill vin
25712572
//

test/functional/fundrawtransaction.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ def run_test(self):
5353
self.nodes[0].generate(121)
5454
self.sync_all()
5555

56+
# ensure that setting changePosition in fundraw with an exact match is handled properly
57+
rawmatch = self.nodes[2].createrawtransaction([], {self.nodes[2].getnewaddress():50})
58+
rawmatch = self.nodes[2].fundrawtransaction(rawmatch, {"changePosition":1, "subtractFeeFromOutputs":[0]})
59+
assert_equal(rawmatch["changepos"], -1)
60+
5661
watchonly_address = self.nodes[0].getnewaddress()
5762
watchonly_pubkey = self.nodes[0].validateaddress(watchonly_address)["pubkey"]
5863
watchonly_amount = Decimal(200)

0 commit comments

Comments
 (0)