GetBalance() is defined in wallet.cpp:
CAmount CWallet::GetBalance() const
{
CAmount nTotal = 0;
{
LOCK2(cs_main, cs_wallet);
for (const auto& entry : mapWallet)
{
const CWalletTx* pcoin = &entry.second;
if (pcoin->IsTrusted())
nTotal += pcoin->GetAvailableCredit();
}
}
return nTotal;
}
Steps taken in this method:
- Begin function setting up temporary variables
- Set
nTotalto 0 first, we will later usenTotalto sum up coins - Start a new code block
- Lock
cs_mainandcs_wallet
- Iterate through
mapWallet:for (const auto& entry : mapWallet)
auto&automatically convertsentryto whatever type the members ofmapWalletare (?)mapWalletis defined in wallet.h as a mapping ofuint256toCWalletTx. Therefore,entryis a single pair of the mapping<uint256, CWalletTx>- More detailed information on
mapWalletbelow
- For each
<uint256, CWalletTx>pair inmapWalletdo the following:
- Create a pointer to the
CWalletTxin that pair:const CWalletTx* pcoin = &entry.second; if (pcoin->IsTrusted()then addpcoin->GetAvailableCredit()tonTotal
@defgroup mapWallet
*
* @{
*/
(?)
mapWallet defined in wallet.h:
std::map<uint256, CWalletTx> mapWallet;
it's a mapping of uint256 (the transaction hash) to CWalletTx (the class used to store Wallet Transactions)
from the definition of class CWalletTx:
* A transaction with a bunch of additional info that only the owner cares about.
* It includes any unrecorded transactions needed to link it back to the block chain.
CWalletTx has various balances each with a cache and a mutable amount:
- Debit
- Credit
- Immature
- Available
- Change
- Watch-only (not relevant to our examination)
There are also various
GetAvailableCredit() caches the available credit when it's called. It's called from these functions:
GetBalance()which is called by:GetCredit(const isminefilter& filter)which is called by:-
UniValue gettransaction()from rpcwallet.cpp which is called by the RPC only -
decomeposeTransaction)in transactionrecord.cpp which is called by:refreshWallet()which is a member function ofclass TransactionTablePrivcalled by:TransactionTableModelconstructor which is called:- Any time a
TransactionTablePrivis constructed
updateWallet()which is a member function ofclass TransactionTablePriv
-
GetAvailableCredit()(recursive?) (?) -
GetImmatureWatchOnlyCredit()which is called by: -
GetAvailableWatchOnlyCredit()which is called by:
-
-
Observations:
- In consensus.h, COINBASE_MATURITY is set to 100 for bitcoin
- In FLO it is currently 100 as well
Solution:
- For FLO it should be 1500
- Optional: make it 1040 for simplicity in the next hard fork, maybe?