From bc06bf1e719d67d3567e445718ec1ba03194228f Mon Sep 17 00:00:00 2001 From: jouzo Date: Tue, 15 Mar 2022 10:58:36 +0100 Subject: [PATCH 1/4] Add ACCOUNTCHANGE log category --- src/logging.cpp | 1 + src/logging.h | 55 +++++++++++++++-------------- src/masternodes/accountshistory.cpp | 5 +++ 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/logging.cpp b/src/logging.cpp index 3ae0fc7465..367f898151 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -154,6 +154,7 @@ const CLogCategoryDesc LogCategories[] = {BCLog::SPV, "spv"}, {BCLog::ORACLE, "oracle"}, {BCLog::LOAN, "loan"}, + {BCLog::ACCOUNTCHANGE, "accountchange"}, {BCLog::ALL, "1"}, {BCLog::ALL, "all"}, }; diff --git a/src/logging.h b/src/logging.h index 362e859bc0..de9ea78294 100644 --- a/src/logging.h +++ b/src/logging.h @@ -32,33 +32,34 @@ struct CLogCategoryActive namespace BCLog { enum LogFlags : uint32_t { - NONE = 0, - NET = (1 << 0), - TOR = (1 << 1), - MEMPOOL = (1 << 2), - HTTP = (1 << 3), - BENCH = (1 << 4), - ZMQ = (1 << 5), - DB = (1 << 6), - RPC = (1 << 7), - ESTIMATEFEE = (1 << 8), - ADDRMAN = (1 << 9), - SELECTCOINS = (1 << 10), - REINDEX = (1 << 11), - CMPCTBLOCK = (1 << 12), - RAND = (1 << 13), - PRUNE = (1 << 14), - PROXY = (1 << 15), - MEMPOOLREJ = (1 << 16), - LIBEVENT = (1 << 17), - COINDB = (1 << 18), - LEVELDB = (1 << 20), - STAKING = (1 << 21), - ANCHORING = (1 << 22), - SPV = (1 << 23), - ORACLE = (1 << 24), - LOAN = (1 << 25), - ALL = ~(uint32_t)0, + NONE = 0, + NET = (1 << 0), + TOR = (1 << 1), + MEMPOOL = (1 << 2), + HTTP = (1 << 3), + BENCH = (1 << 4), + ZMQ = (1 << 5), + DB = (1 << 6), + RPC = (1 << 7), + ESTIMATEFEE = (1 << 8), + ADDRMAN = (1 << 9), + SELECTCOINS = (1 << 10), + REINDEX = (1 << 11), + CMPCTBLOCK = (1 << 12), + RAND = (1 << 13), + PRUNE = (1 << 14), + PROXY = (1 << 15), + MEMPOOLREJ = (1 << 16), + LIBEVENT = (1 << 17), + COINDB = (1 << 18), + LEVELDB = (1 << 20), + STAKING = (1 << 21), + ANCHORING = (1 << 22), + SPV = (1 << 23), + ORACLE = (1 << 24), + LOAN = (1 << 25), + ACCOUNTCHANGE = (1 << 26), + ALL = ~(uint32_t)0, }; class Logger diff --git a/src/masternodes/accountshistory.cpp b/src/masternodes/accountshistory.cpp index f084e35327..8481502a24 100644 --- a/src/masternodes/accountshistory.cpp +++ b/src/masternodes/accountshistory.cpp @@ -151,9 +151,12 @@ void CHistoryErasers::Flush(const uint32_t height, const uint32_t txn, const uin CHistoryWriters::CHistoryWriters(CAccountHistoryStorage* historyView, CBurnHistoryStorage* burnView, CVaultHistoryStorage* vaultView) : historyView(historyView), burnView(burnView), vaultView(vaultView) {} +extern std::string ScriptToString(CScript const& script); + void CHistoryWriters::AddBalance(const CScript& owner, const CTokenAmount amount, const uint256& vaultID) { if (historyView) { + LogPrint(BCLog::ACCOUNTCHANGE, "AccountChange AddBalance: %s: %s\n", ScriptToString(owner), amount.ToString()); diffs[owner][amount.nTokenId] += amount.nValue; } if (burnView && owner == Params().GetConsensus().burnAddress) { @@ -174,6 +177,7 @@ void CHistoryWriters::AddFeeBurn(const CScript& owner, const CAmount amount) void CHistoryWriters::SubBalance(const CScript& owner, const CTokenAmount amount, const uint256& vaultID) { if (historyView) { + LogPrint(BCLog::ACCOUNTCHANGE, "AccountChange SubBalance: %s: %s\n", ScriptToString(owner), amount.ToString()); diffs[owner][amount.nTokenId] -= amount.nValue; } if (burnView && owner == Params().GetConsensus().burnAddress) { @@ -188,6 +192,7 @@ void CHistoryWriters::Flush(const uint32_t height, const uint256& txid, const ui { if (historyView) { for (const auto& diff : diffs) { + LogPrint(BCLog::ACCOUNTCHANGE, "AccountChange: Tx: %s => %s: %s\n", txid.GetHex(), ScriptToString(diff.first), CTokenAmount{diff.second.begin()->first, diff.second.begin()->second}.ToString()); historyView->WriteAccountHistory({diff.first, height, txn}, {txid, type, diff.second}); } } From f13c9392c6287b5c9009e0717758125f534d86be Mon Sep 17 00:00:00 2001 From: jouzo Date: Tue, 15 Mar 2022 11:10:35 +0100 Subject: [PATCH 2/4] Fix lint --- src/masternodes/accountshistory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/masternodes/accountshistory.cpp b/src/masternodes/accountshistory.cpp index 8481502a24..2eb60cc702 100644 --- a/src/masternodes/accountshistory.cpp +++ b/src/masternodes/accountshistory.cpp @@ -192,7 +192,7 @@ void CHistoryWriters::Flush(const uint32_t height, const uint256& txid, const ui { if (historyView) { for (const auto& diff : diffs) { - LogPrint(BCLog::ACCOUNTCHANGE, "AccountChange: Tx: %s => %s: %s\n", txid.GetHex(), ScriptToString(diff.first), CTokenAmount{diff.second.begin()->first, diff.second.begin()->second}.ToString()); + LogPrint(BCLog::ACCOUNTCHANGE, "AccountChange: Tx: %s => %s: %s\n", txid.GetHex(), ScriptToString(diff.first), (CTokenAmount{diff.second.begin()->first, diff.second.begin()->second}.ToString())); historyView->WriteAccountHistory({diff.first, height, txn}, {txid, type, diff.second}); } } From ca5d1446c2066e35b1103d87e751267d1edb3e06 Mon Sep 17 00:00:00 2001 From: jouzo Date: Tue, 15 Mar 2022 11:20:00 +0100 Subject: [PATCH 3/4] Remove add/subBalance from ACCOUNTCHANGE log category --- src/masternodes/accountshistory.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/masternodes/accountshistory.cpp b/src/masternodes/accountshistory.cpp index 2eb60cc702..cce7e841f8 100644 --- a/src/masternodes/accountshistory.cpp +++ b/src/masternodes/accountshistory.cpp @@ -156,7 +156,6 @@ extern std::string ScriptToString(CScript const& script); void CHistoryWriters::AddBalance(const CScript& owner, const CTokenAmount amount, const uint256& vaultID) { if (historyView) { - LogPrint(BCLog::ACCOUNTCHANGE, "AccountChange AddBalance: %s: %s\n", ScriptToString(owner), amount.ToString()); diffs[owner][amount.nTokenId] += amount.nValue; } if (burnView && owner == Params().GetConsensus().burnAddress) { @@ -177,7 +176,6 @@ void CHistoryWriters::AddFeeBurn(const CScript& owner, const CAmount amount) void CHistoryWriters::SubBalance(const CScript& owner, const CTokenAmount amount, const uint256& vaultID) { if (historyView) { - LogPrint(BCLog::ACCOUNTCHANGE, "AccountChange SubBalance: %s: %s\n", ScriptToString(owner), amount.ToString()); diffs[owner][amount.nTokenId] -= amount.nValue; } if (burnView && owner == Params().GetConsensus().burnAddress) { From 8b348a7c33a6b280798bc592085b30af322ed26c Mon Sep 17 00:00:00 2001 From: jouzo Date: Tue, 15 Mar 2022 11:48:46 +0100 Subject: [PATCH 4/4] Use CBalances ToString method --- src/masternodes/accountshistory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/masternodes/accountshistory.cpp b/src/masternodes/accountshistory.cpp index cce7e841f8..f28c6f1929 100644 --- a/src/masternodes/accountshistory.cpp +++ b/src/masternodes/accountshistory.cpp @@ -190,7 +190,7 @@ void CHistoryWriters::Flush(const uint32_t height, const uint256& txid, const ui { if (historyView) { for (const auto& diff : diffs) { - LogPrint(BCLog::ACCOUNTCHANGE, "AccountChange: Tx: %s => %s: %s\n", txid.GetHex(), ScriptToString(diff.first), (CTokenAmount{diff.second.begin()->first, diff.second.begin()->second}.ToString())); + LogPrint(BCLog::ACCOUNTCHANGE, "AccountChange: txid=%s addr=%s change=%s\n", txid.GetHex(), ScriptToString(diff.first), (CBalances{diff.second}.ToString())); historyView->WriteAccountHistory({diff.first, height, txn}, {txid, type, diff.second}); } }