message: Fix Subtract fee from amount
diff: @@ -3504,7 +3504,7 @@ bool CWallet::CreateTransaction(const vector <CRecipient> &vecSend, CWalletTx &w
  wtxNew.fFromMe = true;
  wtxNew.changes.clear();
  -
  + bool fFirst = true;
  CAmount nValueToSelect = nValue;
  if (nSubtractFeeFromAmount == 0)
  nValueToSelect += nFeeRet;
  @@ -3514,6 +3514,17 @@ bool CWallet::CreateTransaction(const vector <CRecipient> &vecSend, CWalletTx &w
  {
  CTxOut txout(recipient.nAmount, recipient.scriptPubKey);
  + if (recipient.fSubtractFeeFromAmount)
  + {
  + txout.nValue -= nFeeRet / nSubtractFeeFromAmount; // Subtract fee equally from each selected recipient
  +
  + if (fFirst) // first receiver pays the remainder not divisible by output count
  + {
  + fFirst = false;
  + txout.nValue -= nFeeRet % nSubtractFeeFromAmount;
  + }
  + }
  +
  if (txout.IsDust(::minRelayTxFee)) {
  if (recipient.fSubtractFeeFromAmount && nFeeRet > 0) {
  if (txout.nValue < 0)
  @@ -3558,7 +3569,9 @@ bool CWallet::CreateTransaction(const vector <CRecipient> &vecSend, CWalletTx &w
  dPriority += (double) nCredit * age;
  }
  - const CAmount nChange = nValueIn - nValueToSelect;
  + CAmount nChange = nValueIn - nValueToSelect;
  + if (nSubtractFeeFromAmount == 0)
  + nChange -= nFeeRet;
  if (nChange > 0) {
  //over pay for denominated transactions
  if (nCoinType == ONLY_DENOMINATED) {
  