2017-11-09 19:34:51 +01:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
|
|
|
|
* Copyright (C) 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/>.
|
|
|
|
|
*/
|
2015-07-17 13:46:18 -04:00
|
|
|
|
2018-01-16 10:47:52 +00:00
|
|
|
#ifndef FLOWEE_CORE_MEMUSAGE_H
|
|
|
|
|
#define FLOWEE_CORE_MEMUSAGE_H
|
2015-07-17 13:46:18 -04:00
|
|
|
|
2021-11-02 09:59:13 +01:00
|
|
|
#include <primitives/transaction.h>
|
2021-11-02 10:08:27 +01:00
|
|
|
#include <primitives/MutableBlock.h>
|
2015-07-17 13:46:18 -04:00
|
|
|
#include "memusage.h"
|
2021-11-02 09:59:13 +01:00
|
|
|
#include "blocklocator.h"
|
2015-07-17 13:46:18 -04:00
|
|
|
|
|
|
|
|
static inline size_t RecursiveDynamicUsage(const CScript& script) {
|
2015-10-29 07:11:24 +01:00
|
|
|
return memusage::DynamicUsage(*static_cast<const CScriptBase*>(&script));
|
2015-07-17 13:46:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline size_t RecursiveDynamicUsage(const COutPoint& out) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline size_t RecursiveDynamicUsage(const CTxIn& in) {
|
|
|
|
|
return RecursiveDynamicUsage(in.scriptSig) + RecursiveDynamicUsage(in.prevout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline size_t RecursiveDynamicUsage(const CTxOut& out) {
|
|
|
|
|
return RecursiveDynamicUsage(out.scriptPubKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline size_t RecursiveDynamicUsage(const CTransaction& tx) {
|
|
|
|
|
size_t mem = memusage::DynamicUsage(tx.vin) + memusage::DynamicUsage(tx.vout);
|
|
|
|
|
for (std::vector<CTxIn>::const_iterator it = tx.vin.begin(); it != tx.vin.end(); it++) {
|
|
|
|
|
mem += RecursiveDynamicUsage(*it);
|
|
|
|
|
}
|
|
|
|
|
for (std::vector<CTxOut>::const_iterator it = tx.vout.begin(); it != tx.vout.end(); it++) {
|
|
|
|
|
mem += RecursiveDynamicUsage(*it);
|
|
|
|
|
}
|
|
|
|
|
return mem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline size_t RecursiveDynamicUsage(const CMutableTransaction& tx) {
|
|
|
|
|
size_t mem = memusage::DynamicUsage(tx.vin) + memusage::DynamicUsage(tx.vout);
|
|
|
|
|
for (std::vector<CTxIn>::const_iterator it = tx.vin.begin(); it != tx.vin.end(); it++) {
|
|
|
|
|
mem += RecursiveDynamicUsage(*it);
|
|
|
|
|
}
|
|
|
|
|
for (std::vector<CTxOut>::const_iterator it = tx.vout.begin(); it != tx.vout.end(); it++) {
|
|
|
|
|
mem += RecursiveDynamicUsage(*it);
|
|
|
|
|
}
|
|
|
|
|
return mem;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-02 09:36:09 +01:00
|
|
|
static inline size_t RecursiveDynamicUsage(const MutableBlock& block) {
|
2015-08-11 21:03:31 +02:00
|
|
|
size_t mem = memusage::DynamicUsage(block.vtx);
|
2015-07-17 13:46:18 -04:00
|
|
|
for (std::vector<CTransaction>::const_iterator it = block.vtx.begin(); it != block.vtx.end(); it++) {
|
|
|
|
|
mem += RecursiveDynamicUsage(*it);
|
|
|
|
|
}
|
|
|
|
|
return mem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline size_t RecursiveDynamicUsage(const CBlockLocator& locator) {
|
|
|
|
|
return memusage::DynamicUsage(locator.vHave);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-16 10:47:52 +00:00
|
|
|
#endif
|