Files
thehub/hub-qt/walletmodeltransaction.cpp
T

114 lines
3.1 KiB
C++
Raw Permalink Normal View History

2017-11-09 19:34:51 +01:00
/*
* This file is part of the Flowee project
* Copyright (C) 2011-2015 The Bitcoin Core developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2013-11-04 16:20:43 +01:00
#include "walletmodeltransaction.h"
#include "wallet/wallet.h"
2013-04-13 00:13:08 -05:00
WalletModelTransaction::WalletModelTransaction(const QList<SendCoinsRecipient> &recipients) :
recipients(recipients),
walletTransaction(0),
keyChange(0),
fee(0)
{
walletTransaction = new CWalletTx();
}
WalletModelTransaction::~WalletModelTransaction()
{
delete keyChange;
delete walletTransaction;
}
QList<SendCoinsRecipient> WalletModelTransaction::getRecipients()
{
return recipients;
}
CWalletTx *WalletModelTransaction::getTransaction()
{
return walletTransaction;
}
2014-11-02 00:14:47 +01:00
unsigned int WalletModelTransaction::getTransactionSize()
{
return (!walletTransaction ? 0 : (::GetSerializeSize(*(CTransaction*)walletTransaction, SER_NETWORK, PROTOCOL_VERSION)));
}
2021-01-20 19:21:53 +01:00
int64_t WalletModelTransaction::getTransactionFee()
{
return fee;
}
2021-01-20 19:21:53 +01:00
void WalletModelTransaction::setTransactionFee(const int64_t& newFee)
{
2013-09-28 19:29:44 +02:00
fee = newFee;
}
2014-07-23 14:34:36 +02:00
void WalletModelTransaction::reassignAmounts(int nChangePosRet)
{
int i = 0;
for (QList<SendCoinsRecipient>::iterator it = recipients.begin(); it != recipients.end(); ++it)
{
SendCoinsRecipient& rcp = (*it);
if (rcp.paymentRequest.IsInitialized())
{
2021-01-20 19:21:53 +01:00
int64_t subtotal = 0;
2014-07-23 14:34:36 +02:00
const payments::PaymentDetails& details = rcp.paymentRequest.getDetails();
for (int j = 0; j < details.outputs_size(); j++)
{
const payments::Output& out = details.outputs(j);
if (out.amount() <= 0) continue;
if (i == nChangePosRet)
i++;
subtotal += walletTransaction->vout[i].nValue;
i++;
}
rcp.amount = subtotal;
}
else // normal recipient (no payment request)
{
if (i == nChangePosRet)
i++;
rcp.amount = walletTransaction->vout[i].nValue;
i++;
}
}
}
2021-01-20 19:21:53 +01:00
int64_t WalletModelTransaction::getTotalTransactionAmount()
{
2021-01-20 19:21:53 +01:00
int64_t totalTransactionAmount = 0;
2015-07-14 13:59:05 +02:00
Q_FOREACH(const SendCoinsRecipient &rcp, recipients)
{
2013-09-28 19:29:44 +02:00
totalTransactionAmount += rcp.amount;
}
return totalTransactionAmount;
}
void WalletModelTransaction::newPossibleKeyChange(CWallet *wallet)
{
keyChange = new CReserveKey(wallet);
}
CReserveKey *WalletModelTransaction::getPossibleKeyChange()
{
return keyChange;
}