Skip to content

Commit e82d179

Browse files
committed
wallet: Force distinct destinations in CWallet::CreateTransaction
Check that all transaction destinations, including change address if specified, are distinct.
1 parent c997f88 commit e82d179

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/wallet/wallet.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,8 +2701,21 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
27012701
CAmount nValue = 0;
27022702
int nChangePosRequest = nChangePosInOut;
27032703
unsigned int nSubtractFeeFromAmount = 0;
2704+
std::set<CTxDestination> destinations;
2705+
2706+
if (!boost::get<CNoDestination>(&coin_control.destChange)) {
2707+
destinations.insert(coin_control.destChange);
2708+
}
2709+
27042710
for (const auto& recipient : vecSend)
27052711
{
2712+
CTxDestination destination;
2713+
if (ExtractDestination(recipient.scriptPubKey, destination) &&
2714+
!destinations.insert(destination).second) {
2715+
strFailReason = _("Transaction destinations must be distinct");
2716+
return false;
2717+
}
2718+
27062719
if (nValue < 0 || recipient.nAmount < 0)
27072720
{
27082721
strFailReason = _("Transaction amounts must not be negative");

test/functional/rpc_fundrawtransaction.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,14 @@ def run_test(self):
200200
utx = get_unspent(self.nodes[2].listunspent(), 5)
201201

202202
inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']} ]
203-
outputs = { self.nodes[0].getnewaddress() : Decimal(4.0) }
203+
address = self.nodes[0].getnewaddress()
204+
outputs = { address : Decimal(4.0) }
204205
rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
205206
dec_tx = self.nodes[2].decoderawtransaction(rawtx)
206207
assert_equal(utx['txid'], dec_tx['vin'][0]['txid'])
207208

209+
assert_raises_rpc_error(-4, "Transaction destinations must be distinct", self.nodes[2].fundrawtransaction, rawtx, {'changeAddress':address})
210+
208211
change = self.nodes[2].getnewaddress()
209212
assert_raises_rpc_error(-8, "changePosition out of bounds", self.nodes[2].fundrawtransaction, rawtx, {'changeAddress':change, 'changePosition':2})
210213
rawtxfund = self.nodes[2].fundrawtransaction(rawtx, {'changeAddress': change, 'changePosition': 0})

0 commit comments

Comments
 (0)