Skip to content

Commit f1d1e72

Browse files
committed
BUG: fix correct fee/amount in decomposeShieldedDebitTransaction
1 parent 7ca4011 commit f1d1e72

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/qt/transactionrecord.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ bool TransactionRecord::decomposeSendToSelfTransaction(const CWalletTx& wtx, con
281281
return true;
282282
}
283283

284-
bool TransactionRecord::decomposeShieldedDebitTransaction(const CWallet* wallet, const CWalletTx& wtx,
284+
bool TransactionRecord::decomposeShieldedDebitTransaction(const CWallet* wallet, const CWalletTx& wtx, CAmount nTxFee,
285285
bool involvesWatchAddress, QList<TransactionRecord>& parts)
286286
{
287287
// Return early if there are no outputs.
@@ -291,7 +291,6 @@ bool TransactionRecord::decomposeShieldedDebitTransaction(const CWallet* wallet,
291291

292292
TransactionRecord sub(wtx.GetHash(), wtx.GetTxTime(), wtx.GetTotalSize());
293293
auto sspkm = wallet->GetSaplingScriptPubKeyMan();
294-
bool feeAdded = false;
295294
for (int i = 0; i < (int) wtx.sapData->vShieldedOutput.size(); ++i) {
296295
SaplingOutPoint out(sub.hash, i);
297296
auto opAddr = sspkm->GetOutPointAddress(wtx, out);
@@ -305,9 +304,9 @@ bool TransactionRecord::decomposeShieldedDebitTransaction(const CWallet* wallet,
305304
sub.address = KeyIO::EncodePaymentAddress(*opAddr);
306305
CAmount nValue = sspkm->GetOutPointValue(wtx, out);
307306
/* Add fee to first output */
308-
if (!feeAdded) { // future, move from the hardcoded fee.
309-
nValue += COIN;
310-
feeAdded = true;
307+
if (nTxFee > 0) {
308+
nValue += nTxFee;
309+
nTxFee = 0;
311310
}
312311
sub.debit = -nValue;
313312
parts.append(sub);
@@ -327,7 +326,9 @@ bool TransactionRecord::decomposeDebitTransaction(const CWallet* wallet, const C
327326
return false;
328327
}
329328

330-
CAmount nTxFee = nDebit - wtx.GetValueOut();
329+
// GetValueOut is the sum of transparent outs and negative sapValueBalance (shielded outs minus shielded spends).
330+
// Therefore to get the sum of the whole outputs of the tx, must re-add the shielded inputs spent to it
331+
CAmount nTxFee = nDebit - (wtx.GetValueOut() + wtx.GetDebit(ISMINE_SPENDABLE_SHIELDED | ISMINE_WATCH_ONLY_SHIELDED));
331332
unsigned int txSize = wtx.GetTotalSize();
332333
const uint256& txHash = wtx.GetHash();
333334
const int64_t txTime = wtx.GetTxTime();
@@ -377,7 +378,7 @@ bool TransactionRecord::decomposeDebitTransaction(const CWallet* wallet, const C
377378
}
378379

379380
// Decompose shielded debit
380-
return decomposeShieldedDebitTransaction(wallet, wtx, involvesWatchAddress, parts);
381+
return decomposeShieldedDebitTransaction(wallet, wtx, nTxFee, involvesWatchAddress, parts);
381382
}
382383

383384
// Check whether all the shielded inputs and outputs are from and send to this wallet

src/qt/transactionrecord.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class TransactionRecord
145145
const CAmount& nDebit, bool involvesWatchAddress,
146146
QList<TransactionRecord>& parts);
147147

148-
static bool decomposeShieldedDebitTransaction(const CWallet* wallet, const CWalletTx& wtx,
148+
static bool decomposeShieldedDebitTransaction(const CWallet* wallet, const CWalletTx& wtx, CAmount nTxFee,
149149
bool involvesWatchAddress, QList<TransactionRecord>& parts);
150150

151151
static std::string getValueOrReturnEmpty(const std::map<std::string, std::string>& mapValue, const std::string& key);

0 commit comments

Comments
 (0)