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
This commit is contained in:
Wladimir J. van der Laan 2017-05-01 15:19:47 +02:00
commit e2b99b1313
No known key found for this signature in database
GPG key ID: 74810B012346C9A6
2 changed files with 8 additions and 2 deletions

View file

@ -2563,9 +2563,10 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
std::vector<CTxOut>::iterator position = txNew.vout.begin()+nChangePosInOut; std::vector<CTxOut>::iterator position = txNew.vout.begin()+nChangePosInOut;
txNew.vout.insert(position, newTxOut); txNew.vout.insert(position, newTxOut);
} }
} } else {
else
reservekey.ReturnKey(); reservekey.ReturnKey();
nChangePosInOut = -1;
}
// Fill vin // Fill vin
// //

View file

@ -53,6 +53,11 @@ class RawTransactionsTest(BitcoinTestFramework):
self.nodes[0].generate(121) self.nodes[0].generate(121)
self.sync_all() 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_address = self.nodes[0].getnewaddress()
watchonly_pubkey = self.nodes[0].validateaddress(watchonly_address)["pubkey"] watchonly_pubkey = self.nodes[0].validateaddress(watchonly_address)["pubkey"]
watchonly_amount = Decimal(200) watchonly_amount = Decimal(200)