forked from highfidelity/elements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_memusage.h
87 lines (73 loc) · 2.79 KB
/
core_memusage.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright (c) 2015-2016 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
#include "primitives/transaction.h"
#include "primitives/block.h"
#include "memusage.h"
static inline size_t RecursiveDynamicUsage(const CScript& script) {
return memusage::DynamicUsage(*static_cast<const CScriptBase*>(&script));
}
static inline size_t RecursiveDynamicUsage(const COutPoint& out) {
return 0;
}
static inline size_t RecursiveDynamicUsage(const CTxIn& in) {
size_t mem = RecursiveDynamicUsage(in.scriptSig) + RecursiveDynamicUsage(in.prevout);
return mem;
}
static inline size_t RecursiveDynamicUsage(const CTxOut& out) {
return RecursiveDynamicUsage(out.scriptPubKey);
}
static inline size_t RecursiveDynamicUsage(const ::CTxInWitness& wit) {
return memusage::DynamicUsage(wit.vchIssuanceAmountRangeproof)
+ memusage::DynamicUsage(wit.vchInflationKeysRangeproof);
}
static inline size_t RecursiveDynamicUsage(const ::CTxOutWitness& wit) {
return memusage::DynamicUsage(wit.vchSurjectionproof)
+ memusage::DynamicUsage(wit.vchRangeproof);
}
static inline size_t RecursiveDynamicUsage(const ::CTxWitness& wit) {
size_t mem = memusage::DynamicUsage(wit.vtxinwit)
+ memusage::DynamicUsage(wit.vtxoutwit);
for (const CTxInWitness& w : wit.vtxinwit) {
mem += RecursiveDynamicUsage(w);
}
for (const CTxOutWitness& w : wit.vtxoutwit) {
mem += RecursiveDynamicUsage(w);
}
return mem;
}
static inline size_t RecursiveDynamicUsage(const CTransaction& tx) {
size_t mem = memusage::DynamicUsage(tx.vin) + memusage::DynamicUsage(tx.vout);
for (const CTxIn& txi : tx.vin) {
mem += RecursiveDynamicUsage(txi);
}
for (const CTxOut& txo : tx.vout) {
mem += RecursiveDynamicUsage(txo);
}
mem += RecursiveDynamicUsage(tx.wit);
return mem;
}
static inline size_t RecursiveDynamicUsage(const CMutableTransaction& tx) {
size_t mem = memusage::DynamicUsage(tx.vin) + memusage::DynamicUsage(tx.vout);
for (const CTxIn& txi : tx.vin) {
mem += RecursiveDynamicUsage(txi);
}
for (const CTxOut& txo : tx.vout) {
mem += RecursiveDynamicUsage(txo);
}
mem += RecursiveDynamicUsage(tx.wit);
return mem;
}
static inline size_t RecursiveDynamicUsage(const CBlock& block) {
size_t mem = memusage::DynamicUsage(block.vtx);
for (const auto& tx : block.vtx) {
mem += memusage::DynamicUsage(tx) + RecursiveDynamicUsage(*tx);
}
return mem;
}
static inline size_t RecursiveDynamicUsage(const CBlockLocator& locator) {
return memusage::DynamicUsage(locator.vHave);
}
#endif // BITCOIN_CORE_MEMUSAGE_H