Skip to content

Commit

Permalink
add wallet log (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
cchanm authored and shangqd committed Dec 6, 2019
1 parent ee6ad04 commit e195588
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/bigbang/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CWalletTx> spWalletTx = InsertWalletTx(txid, tx, hashFork, fIsMine, fFromMe);
if (spWalletTx != nullptr)
Expand All @@ -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<CWalletTx> spWalletTx(new CWalletTx(wtx));
mapWalletTx.insert(make_pair(wtx.txid, spWalletTx));

Expand All @@ -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<uint256> vFork;
GetWalletTxFork(wtx.hashFork, wtx.nBlockHeight, vFork);
if (wtx.IsFromMe())
Expand Down Expand Up @@ -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<boost::shared_mutex> wlock(rwWalletTx);

vector<CWalletTx> vWalletTx;
Expand Down Expand Up @@ -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<CWalletTx> spWalletTx = InsertWalletTx(txid, tx, hashFork, fIsMine, fFromMe);
if (spWalletTx != nullptr)
Expand Down Expand Up @@ -1461,6 +1466,7 @@ void CWallet::GetWalletTxFork(const uint256& hashFork, int nHeight, vector<uint2

void CWallet::AddNewWalletTx(std::shared_ptr<CWalletTx>& spWalletTx, vector<uint256>& vFork)
{
StdTrace("CWallet", "AddNewWalletTx: txid: %s", spWalletTx->txid.GetHex().c_str());
if (spWalletTx->IsFromMe())
{
for (const CTxIn& txin : spWalletTx->vInput)
Expand Down Expand Up @@ -1496,6 +1502,7 @@ void CWallet::AddNewWalletTx(std::shared_ptr<CWalletTx>& spWalletTx, vector<uint

void CWallet::RemoveWalletTx(std::shared_ptr<CWalletTx>& spWalletTx, const uint256& hashFork)
{
StdTrace("CWallet", "RemoveWalletTx: txid: %s", spWalletTx->txid.GetHex().c_str());
if (spWalletTx->IsFromMe())
{
for (const CTxIn& txin : spWalletTx->vInput)
Expand Down
43 changes: 37 additions & 6 deletions src/bigbang/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,62 @@
#include <boost/thread/thread.hpp>

#include "base.h"
#include "util.h"
#include "walletdb.h"
#include "wallettx.h"

namespace bigbang
{

using namespace xengine;

class CWalletCoins
{
public:
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());
}
}

Expand Down

0 comments on commit e195588

Please sign in to comment.