Skip to content

Commit

Permalink
Making conditions look better
Browse files Browse the repository at this point in the history
  • Loading branch information
levonpetrosyan93 committed Aug 13, 2023
1 parent e36b3ac commit 1a8a4f0
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/coins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ unsigned int CCoinsViewCache::GetCacheSize() const {

CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const
{
if (tx.IsCoinBase() || tx.IsZerocoinSpend() || tx.IsSigmaSpend() || tx.IsZerocoinRemint() || tx.IsLelantusJoinSplit() || tx.IsSparkSpend())
if (tx.IsCoinBase() || tx.HasNoRegularInputs())
return 0;

CAmount nResult = 0;
Expand All @@ -228,7 +228,7 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const

bool CCoinsViewCache::HaveInputs(const CTransaction& tx) const
{
if (!tx.IsCoinBase() && !tx.IsZerocoinSpend() && !tx.IsSigmaSpend() && !tx.IsZerocoinRemint() && !tx.IsLelantusJoinSplit() && !tx.IsSparkSpend()) {
if (!tx.IsCoinBase() && !tx.HasNoRegularInputs()) {
for (unsigned int i = 0; i < tx.vin.size(); i++) {
if (!HaveCoin(tx.vin[i].prevout)) {
return false;
Expand Down
4 changes: 4 additions & 0 deletions src/primitives/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ bool CTransaction::HasNoRegularInputs() const {
return IsZerocoinSpend() || IsSigmaSpend() || IsZerocoinRemint() || IsLelantusJoinSplit() || IsSparkSpend();
}

bool CTransaction::HasPrivateInputs() const {
return IsSigmaSpend() || IsLelantusJoinSplit() || IsSparkSpend();
}

unsigned int CTransaction::CalculateModifiedSize(unsigned int nTxSize) const
{
// In order to avoid disincentivizing cleaning up the UTXO set we don't count
Expand Down
1 change: 1 addition & 0 deletions src/primitives/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ class CTransaction
bool IsSparkMint() const;

bool HasNoRegularInputs() const;
bool HasPrivateInputs() const;

/**
* Get the total transaction size in bytes, including witness data.
Expand Down
4 changes: 2 additions & 2 deletions src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ void handleOutput(const CTxOut &out, size_t outNo, uint256 const & txHash, int h
void CDbIndexHelper::ConnectTransaction(CTransaction const & tx, int height, int txNumber, CCoinsViewCache const & view)
{
size_t no = 0;
if(!tx.IsCoinBase() && !tx.IsZerocoinSpend() && !tx.IsSigmaSpend() && !tx.IsZerocoinRemint() && !tx.IsLelantusJoinSplit() && !tx.IsSparkSpend()) {
if(!tx.IsCoinBase() && !tx.HasNoRegularInputs()) {
for (CTxIn const & input : tx.vin) {
handleInput(input, no++, tx.GetHash(), height, txNumber, view, addressIndex, addressUnspentIndex, spentIndex);
}
Expand Down Expand Up @@ -679,7 +679,7 @@ void CDbIndexHelper::DisconnectTransactionInputs(CTransaction const & tx, int he

size_t no = 0;

if(!tx.IsCoinBase() && !tx.IsZerocoinSpend() && !tx.IsSigmaSpend() && !tx.IsZerocoinRemint() && !tx.IsLelantusJoinSplit() && !tx.IsSparkSpend())
if(!tx.IsCoinBase() && !tx.HasNoRegularInputs())
for (CTxIn const & input : tx.vin) {
handleInput(input, no++, tx.GetHash(), height, txNumber, view, addressIndex, addressUnspentIndex, spentIndex);
}
Expand Down
20 changes: 10 additions & 10 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFe
nSizeWithDescendants = GetTxSize();
nModFeesWithDescendants = nFee;
CAmount nValueIn = tx->GetValueOut()+nFee;
if (!tx->IsZerocoinSpend() && !tx->IsSigmaSpend() && !tx->IsZerocoinRemint() && !tx->IsLelantusJoinSplit() && !tx->IsSparkSpend()) {
if (!tx->HasNoRegularInputs()) {
assert(inChainInputValue <= nValueIn);
}

Expand Down Expand Up @@ -417,7 +417,7 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,

const CTransaction& tx = newit->GetTx();
std::set<uint256> setParentTransactions;
if (!entry.GetTx().IsSigmaSpend() && !entry.GetTx().IsLelantusJoinSplit() && !entry.GetTx().IsSparkSpend()) {
if (!entry.GetTx().HasPrivateInputs()) {
for (unsigned int i = 0; i < tx.vin.size(); i++) {
mapNextTx.insert(std::make_pair(&tx.vin[i].prevout, &tx));
setParentTransactions.insert(tx.vin[i].prevout.hash);
Expand Down Expand Up @@ -518,8 +518,8 @@ void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
{
NotifyEntryRemoved(it->GetSharedTx(), reason);
const uint256 hash = it->GetTx().GetHash();
if (!it->GetTx().IsSigmaSpend() && !it->GetTx().IsLelantusJoinSplit() && !it->GetTx().IsSparkSpend()) {
LogPrintf("removeUnchecked txHash=%s, IsSpend()=%s\n", hash.ToString(), it->GetTx().IsSigmaSpend() || it->GetTx().IsLelantusJoinSplit() || it->GetTx().IsSparkSpend());
if (!it->GetTx().HasPrivateInputs()) {
LogPrintf("removeUnchecked txHash=%s, IsSpend()=%s\n", hash.ToString(), it->GetTx().HasPrivateInputs());
BOOST_FOREACH(const CTxIn& txin, it->GetTx().vin)
mapNextTx.erase(txin.prevout);
}
Expand Down Expand Up @@ -658,7 +658,7 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC
uint256 txhash = tx.GetHash();
for (unsigned int j = 0; j < tx.vin.size(); j++) {
const CTxIn input = tx.vin[j];
if (input.IsSigmaSpend() || input.IsLelantusJoinSplit() || tx.IsSparkSpend()) {
if (tx.HasPrivateInputs()) {
continue;
}

Expand Down Expand Up @@ -737,7 +737,7 @@ void CTxMemPool::addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCac
uint256 txhash = tx.GetHash();
for (unsigned int j = 0; j < tx.vin.size(); j++) {
const CTxIn input = tx.vin[j];
if (input.IsSigmaSpend() || input.IsLelantusJoinSplit() || tx.IsSparkSpend()) {
if (tx.HasPrivateInputs()) {
continue;
}

Expand Down Expand Up @@ -1140,13 +1140,13 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
assert(linksiter != mapLinks.end());
const TxLinks &links = linksiter->second;
innerUsage += memusage::DynamicUsage(links.children);
if (!tx.IsSigmaSpend() && !tx.IsLelantusJoinSplit() && !tx.IsSparkSpend())
if (!tx.HasPrivateInputs())
innerUsage += memusage::DynamicUsage(links.parents);
bool fDependsWait = false;
setEntries setParentCheck;
int64_t parentSizes = 0;
int64_t parentSigOpCost = 0;
if (!tx.IsSigmaSpend() && !tx.IsLelantusJoinSplit() && !tx.IsSparkSpend()) {
if (!tx.HasPrivateInputs()) {
BOOST_FOREACH(const CTxIn &txin, tx.vin) {
// Check that every mempool transaction's inputs refer to available coins, or other mempool tx's.
indexed_transaction_set::const_iterator it2 = mapTx.find(txin.prevout.hash);
Expand Down Expand Up @@ -1211,7 +1211,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
waitingOnDependants.push_back(&(*it));
else {
CValidationState state;
bool fCheckResult = tx.IsCoinBase() || tx.IsSigmaSpend() || tx.IsLelantusJoinSplit() || tx.IsSparkSpend() ||
bool fCheckResult = tx.IsCoinBase() || tx.HasPrivateInputs() ||
Consensus::CheckTxInputs(tx, state, mempoolDuplicate, nSpendHeight);

assert(fCheckResult);
Expand All @@ -1229,7 +1229,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
assert(stepsSinceLastRemove < waitingOnDependants.size());
} else {
const CTransaction &tx = entry->GetTx();
bool fCheckResult = tx.IsCoinBase() || tx.IsSigmaSpend() || tx.IsLelantusJoinSplit() || tx.IsSparkSpend() ||
bool fCheckResult = tx.IsCoinBase() || tx.HasPrivateInputs() ||
Consensus::CheckTxInputs(entry->GetTx(), state, mempoolDuplicate, nSpendHeight);
assert(fCheckResult);
UpdateCoins(entry->GetTx(), mempoolDuplicate, 1000000);
Expand Down
25 changes: 10 additions & 15 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ unsigned int GetLegacySigOpCount(const CTransaction& tx)

unsigned int GetP2SHSigOpCount(const CTransaction &tx, const CCoinsViewCache &inputs)
{
if (tx.IsCoinBase() || tx.IsZerocoinSpend() || tx.IsSigmaSpend() || tx.IsLelantusJoinSplit())
if (tx.IsCoinBase() || tx.HasNoRegularInputs())
return 0;

unsigned int nSigOps = 0;
Expand All @@ -538,7 +538,7 @@ int64_t GetTransactionSigOpCost(const CTransaction &tx, const CCoinsViewCache &i
{
int64_t nSigOps = GetLegacySigOpCount(tx) * WITNESS_SCALE_FACTOR;

if (tx.IsCoinBase() || tx.IsZerocoinSpend() || tx.IsSigmaSpend() || tx.IsZerocoinRemint() || tx.IsLelantusJoinSplit() || tx.IsSparkSpend())
if (tx.IsCoinBase() || tx.HasNoRegularInputs())
return nSigOps;

if (flags & SCRIPT_VERIFY_P2SH) {
Expand Down Expand Up @@ -615,7 +615,7 @@ bool CheckTransaction(const CTransaction &tx, CValidationState &state, bool fChe
bool const check_di = nHeight != INT_MAX && nHeight > ::Params().GetConsensus().nStartDuplicationCheck;
if (fCheckDuplicateInputs || check_di) {
std::set<COutPoint> vInOutPoints;
if (tx.IsSigmaSpend() || tx.IsLelantusJoinSplit() || tx.IsSparkSpend()) {
if (tx.HasPrivateInputs()) {
std::set<CScript> spendScripts;
for (const auto& txin: tx.vin)
{
Expand Down Expand Up @@ -1023,7 +1023,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
std::set<uint256> setConflicts;
{
LOCK(pool.cs); // protect pool.mapNextTx
if (!tx.IsSigmaSpend() && !tx.IsLelantusJoinSplit() && !tx.IsSparkSpend()) {
if (!tx.HasPrivateInputs()) {
BOOST_FOREACH(const CTxIn &txin, tx.vin)
{
auto itConflicting = pool.mapNextTx.find(txin.prevout);
Expand Down Expand Up @@ -1089,7 +1089,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
}
}

if (!tx.IsSigmaSpend() && !tx.IsLelantusJoinSplit() && !tx.IsSparkSpend()) {
if (!tx.HasPrivateInputs()) {
// do all inputs exist?
BOOST_FOREACH(const CTxIn txin, tx.vin) {
if (!pcoinsTip->HaveCoinInCache(txin.prevout)) {
Expand Down Expand Up @@ -1168,7 +1168,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C

CAmount inChainInputValue = 0;
bool fSpendsCoinbase = false;
if (!tx.IsSigmaSpend() && !tx.IsLelantusJoinSplit() && !tx.IsSparkSpend()) {
if (!tx.HasPrivateInputs()) {
// Keep track of transactions that spend a coinbase, which we re-scan
// during reorgs to ensure COINBASE_MATURITY is still met.
BOOST_FOREACH(const CTxIn &txin, tx.vin) {
Expand Down Expand Up @@ -2004,7 +2004,7 @@ void static InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state
void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo &txundo, int nHeight)
{
// mark inputs spent
if (!tx.IsCoinBase() && !tx.IsZerocoinSpend() && !tx.IsSigmaSpend() && !tx.IsZerocoinRemint() && !tx.IsLelantusJoinSplit()) {
if (!tx.IsCoinBase() && !tx.HasNoRegularInputs()) {
txundo.vprevout.reserve(tx.vin.size());
BOOST_FOREACH(const CTxIn &txin, tx.vin) {
txundo.vprevout.emplace_back();
Expand Down Expand Up @@ -2218,7 +2218,7 @@ bool CheckZerocoinFoundersInputs(const CTransaction &tx, CValidationState &state

bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks, unsigned int flags, bool cacheStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks)
{
if (!tx.IsCoinBase() && !tx.IsZerocoinSpend() && !tx.IsSigmaSpend() && !tx.IsZerocoinRemint() && !tx.IsLelantusJoinSplit() &&!tx.IsSparkSpend())
if (!tx.IsCoinBase() && !tx.HasNoRegularInputs())
{
if (!Consensus::CheckTxInputs(tx, state, inputs, GetSpendHeight(inputs)))
return false;
Expand Down Expand Up @@ -2880,7 +2880,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
return state.DoS(100, error("ConnectBlock(): invalid joinsplit tx"),
REJECT_INVALID, "bad-txns-input-invalid");

if (!tx.IsCoinBase() && !tx.IsZerocoinSpend() && !tx.IsSigmaSpend() && !tx.IsZerocoinRemint() && !tx.IsLelantusJoinSplit() && !tx.IsSparkSpend())
if (!tx.IsCoinBase() && !tx.HasNoRegularInputs())
{
if (!view.HaveInputs(tx))
return state.DoS(100, error("ConnectBlock(): inputs missing/spent"),
Expand Down Expand Up @@ -2954,12 +2954,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
REJECT_INVALID, "bad-blk-sigops");

txdata.emplace_back(tx);
if (!tx.IsCoinBase()
&& !tx.IsZerocoinSpend()
&& !tx.IsSigmaSpend()
&& !tx.IsZerocoinRemint()
&& !tx.IsLelantusJoinSplit()
&& !tx.IsSparkSpend())
if (!tx.IsCoinBase() && !tx.HasNoRegularInputs())
{
nFees += view.GetValueIn(tx)-tx.GetValueOut();

Expand Down
2 changes: 1 addition & 1 deletion src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ void ListTransactions(CWallet * const pwallet, const CWalletTx& wtx, const std::
}
entry.push_back(Pair("account", strSentAccount));
MaybePushAddress(entry, s.destination, addr);
if (wtx.tx->IsZerocoinSpend() || wtx.tx->IsSigmaSpend() || wtx.tx->IsZerocoinRemint() || wtx.tx->IsLelantusJoinSplit() || wtx.tx->IsSparkSpend()) {
if (wtx.tx->HasNoRegularInputs()) {
entry.push_back(Pair("category", "spend"));
}
else if (wtx.tx->IsZerocoinMint() || wtx.tx->IsSigmaMint() || wtx.tx->IsLelantusMint() || wtx.tx->IsSparkMint()) {
Expand Down
6 changes: 3 additions & 3 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ void CWallet::AddToSpends(const uint256& wtxid)
return;

BOOST_FOREACH(const CTxIn& txin, thisTx.tx->vin) {
if (!txin.IsZerocoinSpend() && !txin.IsSigmaSpend() && !txin.IsLelantusJoinSplit() && !thisTx.tx->IsSparkSpend()) {
if (!thisTx.tx->HasNoRegularInputs()) {
AddToSpends(txin.prevout, wtxid);
}
}
Expand Down Expand Up @@ -1315,7 +1315,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlockIndex
AssertLockHeld(cs_wallet);

if (posInBlock != -1) {
if(!(tx.IsCoinBase() || tx.IsSigmaSpend() || tx.IsZerocoinRemint() || tx.IsZerocoinSpend() || tx.IsLelantusJoinSplit() || tx.IsSparkSpend())) {
if(!(tx.IsCoinBase() || tx.HasNoRegularInputs())) {
BOOST_FOREACH(const CTxIn& txin, tx.vin) {
std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range(txin.prevout);
while (range.first != range.second) {
Expand Down Expand Up @@ -2679,7 +2679,7 @@ bool CWalletTx::IsTrusted() const
// Trusted if all inputs are from us and are in the mempool:
BOOST_FOREACH(const CTxIn& txin, tx->vin)
{
if (txin.IsZerocoinSpend() || txin.IsSigmaSpend() || txin.IsZerocoinRemint() || txin.IsLelantusJoinSplit()) {
if (tx->HasNoRegularInputs()) {
if (!(pwallet->IsMine(txin, *tx) & ISMINE_SPENDABLE)) {
return false;
}
Expand Down

0 comments on commit 1a8a4f0

Please sign in to comment.