From e19558890355293e1945cff2880e3555238fc1a4 Mon Sep 17 00:00:00 2001 From: "chuanhua.chen" Date: Fri, 6 Dec 2019 16:50:33 +0800 Subject: [PATCH] add wallet log (#318) --- src/bigbang/wallet.cpp | 7 +++++++ src/bigbang/wallet.h | 43 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/bigbang/wallet.cpp b/src/bigbang/wallet.cpp index 8d2f4e91..5e084c6e 100644 --- a/src/bigbang/wallet.cpp +++ b/src/bigbang/wallet.cpp @@ -662,6 +662,7 @@ bool CWallet::UpdateTx(const uint256& hashFork, const CAssembledTx& tx) bool fFromMe = IsMine(tx.destIn); if (fFromMe || fIsMine) { + StdTrace("CWallet", "UpdateTx: txid: %s", tx.GetHash().GetHex().c_str()); uint256 txid = tx.GetHash(); std::shared_ptr spWalletTx = InsertWalletTx(txid, tx, hashFork, fIsMine, fFromMe); if (spWalletTx != nullptr) @@ -685,6 +686,7 @@ bool CWallet::UpdateTx(const uint256& hashFork, const CAssembledTx& tx) bool CWallet::LoadTxUnspent(const CWalletTx& wtx) { + StdTrace("CWallet", "LoadTxUnspent: txid: %s", wtx.txid.GetHex().c_str()); std::shared_ptr spWalletTx(new CWalletTx(wtx)); mapWalletTx.insert(make_pair(wtx.txid, spWalletTx)); @@ -710,6 +712,7 @@ bool CWallet::LoadTxUnspent(const CWalletTx& wtx) bool CWallet::LoadTxSpent(const CWalletTx& wtx) { + StdTrace("CWallet", "LoadTxSpent: txid: %s", wtx.txid.GetHex().c_str()); vector vFork; GetWalletTxFork(wtx.hashFork, wtx.nBlockHeight, vFork); if (wtx.IsFromMe()) @@ -1041,6 +1044,7 @@ bool CWallet::InsertKey(const crypto::CKey& key) bool CWallet::SynchronizeTxSet(const CTxSetChange& change) { + StdTrace("CWallet", "SynchronizeTxSet: add: %ld, remove: %ld, udpate: %ld", change.vTxAddNew.size(), change.vTxRemove.size(), change.mapTxUpdate.size()); boost::unique_lock wlock(rwWalletTx); vector vWalletTx; @@ -1116,6 +1120,7 @@ bool CWallet::AddNewTx(const uint256& hashFork, const CAssembledTx& tx) bool fFromMe = IsMine(tx.destIn); if (fFromMe || fIsMine) { + StdTrace("CWallet", "AddNewTx: txid: %s", tx.GetHash().GetHex().c_str()); uint256 txid = tx.GetHash(); std::shared_ptr spWalletTx = InsertWalletTx(txid, tx, hashFork, fIsMine, fFromMe); if (spWalletTx != nullptr) @@ -1461,6 +1466,7 @@ void CWallet::GetWalletTxFork(const uint256& hashFork, int nHeight, vector& spWalletTx, vector& vFork) { + StdTrace("CWallet", "AddNewWalletTx: txid: %s", spWalletTx->txid.GetHex().c_str()); if (spWalletTx->IsFromMe()) { for (const CTxIn& txin : spWalletTx->vInput) @@ -1496,6 +1502,7 @@ void CWallet::AddNewWalletTx(std::shared_ptr& spWalletTx, vector& spWalletTx, const uint256& hashFork) { + StdTrace("CWallet", "RemoveWalletTx: txid: %s", spWalletTx->txid.GetHex().c_str()); if (spWalletTx->IsFromMe()) { for (const CTxIn& txin : spWalletTx->vInput) diff --git a/src/bigbang/wallet.h b/src/bigbang/wallet.h index 4382e6a3..e58dbd79 100644 --- a/src/bigbang/wallet.h +++ b/src/bigbang/wallet.h @@ -8,12 +8,15 @@ #include #include "base.h" +#include "util.h" #include "walletdb.h" #include "wallettx.h" namespace bigbang { +using namespace xengine; + class CWalletCoins { public: @@ -21,18 +24,46 @@ class CWalletCoins : nTotalValue(0) {} void Push(const CWalletTxOut& out) { - if (!out.IsNull() && setCoins.insert(out).second) + if (!out.IsNull()) + { + if (setCoins.insert(out).second) + { + nTotalValue += out.GetAmount(); + out.AddRef(); + StdTrace("CWalletCoins", "Push: insert success, TotalValue: %ld, RefCount: %d, utxo: [%d] %s", + nTotalValue, out.spWalletTx->GetRefCount(), out.n, out.spWalletTx->txid.GetHex().c_str()); + } + else + { + StdTrace("CWalletCoins", "Push: insert fail, TotalValue: %ld, RefCount: %d, utxo: [%d] %s", + nTotalValue, out.spWalletTx->GetRefCount(), out.n, out.spWalletTx->txid.GetHex().c_str()); + } + } + else { - nTotalValue += out.GetAmount(); - out.AddRef(); + StdTrace("CWalletCoins", "Push: out is null, utxo: [%d] %s", out.n, out.spWalletTx->txid.GetHex().c_str()); } } void Pop(const CWalletTxOut& out) { - if (!out.IsNull() && setCoins.erase(out)) + if (!out.IsNull()) + { + if (setCoins.erase(out)) + { + nTotalValue -= out.GetAmount(); + out.Release(); + StdTrace("CWalletCoins", "Pop: erase success, TotalValue: %ld, RefCount: %d, utxo: [%d] %s", + nTotalValue, out.spWalletTx->GetRefCount(), out.n, out.spWalletTx->txid.GetHex().c_str()); + } + else + { + StdTrace("CWalletCoins", "Pop: erase fail, TotalValue: %ld, RefCount: %d, utxo: [%d] %s", + nTotalValue, out.spWalletTx->GetRefCount(), out.n, out.spWalletTx->txid.GetHex().c_str()); + } + } + else { - nTotalValue -= out.GetAmount(); - out.Release(); + StdTrace("CWalletCoins", "Pop: out is null, utxo: [%d] %s", out.n, out.spWalletTx->txid.GetHex().c_str()); } }