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 committed May 1, 2017
1 parent 4c92401 commit 7c58863
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2563,9 +2563,10 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
std::vector<CTxOut>::iterator position = txNew.vout.begin()+nChangePosInOut;
txNew.vout.insert(position, newTxOut);
}
}
else
} else {
reservekey.ReturnKey();
nChangePosInOut = -1;
}

// Fill vin
//
Expand Down
5 changes: 5 additions & 0 deletions test/functional/fundrawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ 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
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(200)
Expand Down

0 comments on commit 7c58863

Please sign in to comment.