2015-07-17 19:46:18 +02:00
|
|
|
// Copyright (c) 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.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_CORE_MEMUSAGE_H
|
|
|
|
#define BITCOIN_CORE_MEMUSAGE_H
|
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <primitives/transaction.h>
|
|
|
|
#include <primitives/block.h>
|
|
|
|
#include <memusage.h>
|
2015-07-17 19:46:18 +02:00
|
|
|
|
|
|
|
static inline size_t RecursiveDynamicUsage(const CScript& script) {
|
2017-07-15 21:06:13 +02:00
|
|
|
return memusage::DynamicUsage(script);
|
2015-07-17 19:46:18 +02: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t RecursiveDynamicUsage(const CBlock& block) {
|
2015-08-11 21:03:31 +02:00
|
|
|
size_t mem = memusage::DynamicUsage(block.vtx);
|
2016-11-21 10:51:32 +01:00
|
|
|
for (const auto& tx : block.vtx) {
|
|
|
|
mem += memusage::DynamicUsage(tx) + RecursiveDynamicUsage(*tx);
|
2015-07-17 19:46:18 +02:00
|
|
|
}
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t RecursiveDynamicUsage(const CBlockLocator& locator) {
|
|
|
|
return memusage::DynamicUsage(locator.vHave);
|
|
|
|
}
|
|
|
|
|
2017-05-30 18:42:22 +02:00
|
|
|
template<typename X>
|
|
|
|
static inline size_t RecursiveDynamicUsage(const std::shared_ptr<X>& p) {
|
|
|
|
return p ? memusage::DynamicUsage(p) + RecursiveDynamicUsage(*p) : 0;
|
|
|
|
}
|
|
|
|
|
2015-07-17 19:46:18 +02:00
|
|
|
#endif // BITCOIN_CORE_MEMUSAGE_H
|