Skip to content

Commit

Permalink
[Wallet] unset change position when there is no change on exact match
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs authored and random-zebra committed Jun 2, 2021
1 parent 7d977ac commit 2394083
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3176,8 +3176,10 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend,
txNew.vout.insert(position, newTxOut);
}
}
} else
} else {
reservekey.ReturnKey();
nChangePosInOut = -1;
}

// Fill vin
for (const std::pair<const CWalletTx*, unsigned int>& coin : setCoins) {
Expand Down
6 changes: 6 additions & 0 deletions test/functional/rpc_fundrawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ def run_test(self):
self.nodes[0].generate(121)
self.sync_all()

# ensure that setting changePosition in fundraw with an exact match is handled properly
out_no_change = 250.0 - 0.0000374 # one coinbase input minus min fee
rawmatch = self.nodes[0].createrawtransaction([], {self.nodes[2].getnewaddress(): DecimalAmt(out_no_change)})
rawmatch = self.nodes[0].fundrawtransaction(rawmatch, {"changePosition": 1})
assert_equal(rawmatch["changepos"], -1)

watchonly_address = self.nodes[0].getnewaddress()
watchonly_pubkey = self.nodes[0].validateaddress(watchonly_address)["pubkey"]
self.watchonly_amount = DecimalAmt(200.0)
Expand Down

0 comments on commit 2394083

Please sign in to comment.