dash/src/qt/walletmodeltransaction.cpp
xdustinface cee8c151fa scripted-diff: Merge #12906: Avoid interface keyword to fix windows gitian build
17780d6f35 scripted-diff: Avoid `interface` keyword to fix windows gitian build (Russell Yanofsky)

Pull request description:

  Rename `interface` to `interfaces`

  Build failure reported by ken2812221 in https://github.com/bitcoin/bitcoin/pull/10244#issuecomment-379434756

Tree-SHA512: e02c97c728540f344202c13b036f9f63af23bd25e25ed7a5cfe9e2c2f201a12ff232cc94a93fbe37ef6fb6bf9e036fe62210ba798ecd30de191d09338754a8d0

-BEGIN VERIFY SCRIPT-
git mv src/interface src/interfaces
ren() { git grep -l "$1" | xargs sed -i "s,$1,$2,g"; }
ren interface/            interfaces/
ren interface::           interfaces::
ren BITCOIN_INTERFACE_    BITCOIN_INTERFACES_
ren "namespace interface" "namespace interfaces"
-END VERIFY SCRIPT-
2020-10-14 12:10:12 +01:00

88 lines
2.7 KiB
C++

// Copyright (c) 2011-2015 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <qt/walletmodeltransaction.h>
#include <interfaces/node.h>
WalletModelTransaction::WalletModelTransaction(const QList<SendCoinsRecipient> &_recipients) :
recipients(_recipients),
fee(0)
{
}
QList<SendCoinsRecipient> WalletModelTransaction::getRecipients() const
{
return recipients;
}
std::unique_ptr<interfaces::PendingWalletTx>& WalletModelTransaction::getWtx()
{
return wtx;
}
unsigned int WalletModelTransaction::getTransactionSize()
{
return wtx != nullptr ? ::GetSerializeSize(wtx->get(), SER_NETWORK, PROTOCOL_VERSION) : 0;
}
CAmount WalletModelTransaction::getTransactionFee() const
{
return fee;
}
void WalletModelTransaction::setTransactionFee(const CAmount& newFee)
{
fee = newFee;
}
void WalletModelTransaction::reassignAmounts()
{
// For each recipient look for a matching CTxOut in walletTransaction and reassign amounts
for (QList<SendCoinsRecipient>::iterator it = recipients.begin(); it != recipients.end(); ++it)
{
SendCoinsRecipient& rcp = (*it);
if (rcp.paymentRequest.IsInitialized())
{
CAmount subtotal = 0;
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;
const unsigned char* scriptStr = (const unsigned char*)out.script().data();
CScript scriptPubKey(scriptStr, scriptStr+out.script().size());
for (const auto& txout : wtx->get().vout) {
if (txout.scriptPubKey == scriptPubKey) {
subtotal += txout.nValue;
break;
}
}
}
rcp.amount = subtotal;
}
else // normal recipient (no payment request)
{
for (const auto& txout : wtx->get().vout) {
CScript scriptPubKey = GetScriptForDestination(DecodeDestination(rcp.address.toStdString()));
if (txout.scriptPubKey == scriptPubKey) {
rcp.amount = txout.nValue;
break;
}
}
}
}
}
CAmount WalletModelTransaction::getTotalTransactionAmount() const
{
CAmount totalTransactionAmount = 0;
for (const SendCoinsRecipient &rcp : recipients)
{
totalTransactionAmount += rcp.amount;
}
return totalTransactionAmount;
}