From 7285a3d31012b3c052f9751e01d3c2d44b825d21 Mon Sep 17 00:00:00 2001 From: valdok Date: Sun, 25 Jun 2023 11:30:13 +0300 Subject: [PATCH 1/2] explorer node: showing asset emit/burn during contract invocation --- explorer/adapter.cpp | 42 ++++++++++++++++++++++++++++++++------- explorer/htm/explorer.htm | 6 ++++-- node/db.cpp | 10 +++++++--- node/processor.cpp | 28 +++++++++++++++++++++----- node/processor.h | 2 ++ 5 files changed, 71 insertions(+), 17 deletions(-) diff --git a/explorer/adapter.cpp b/explorer/adapter.cpp index 28f3b5d60..d97a9de39 100644 --- a/explorer/adapter.cpp +++ b/explorer/adapter.cpp @@ -456,6 +456,17 @@ class Adapter : public Node::IObserver, public IAdapter { } }; + static void MergeInto(FundsChangeMap& dst, const FundsChangeMap& src, bool bAdd) + { + for (auto it = src.m_Map.begin(); src.m_Map.end() != it; it++) + { + auto val = it->second; + if (!bAdd) + val.Negate(); + dst.Add(val, it->first); + } + } + static void FundsToExclusive(NodeProcessor::ContractInvokeExtraInfo& info) { for (uint32_t iNested = 0; iNested < info.m_NumNested; ) @@ -464,13 +475,7 @@ class Adapter : public Node::IObserver, public IAdapter { iNested += infoNested.m_NumNested; FundsToExclusive(infoNested); - - for (auto it = infoNested.m_FundsIO.m_Map.begin(); infoNested.m_FundsIO.m_Map.end() != it; it++) - { - auto val = it->second; - val.Negate(); - info.m_FundsIO.Add(val, it->first); - } + MergeInto(info.m_FundsIO, infoNested.m_FundsIO, false); } } @@ -554,6 +559,7 @@ class Adapter : public Node::IObserver, public IAdapter { MakeTableHdr("Method"), MakeTableHdr("Arguments"), MakeTableHdr("Funds"), + MakeTableHdr("Emission"), MakeTableHdr("Keys") })); @@ -648,6 +654,8 @@ class Adapter : public Node::IObserver, public IAdapter { if (!info.m_iParent) FundsToExclusive(Cast::NotConst(info)); + MergeInto(Cast::NotConst(info.m_FundsIO), info.m_Emission, true); + if (!info.m_FundsIO.m_Map.empty()) { json jArr = json::array(); @@ -669,6 +677,26 @@ class Adapter : public Node::IObserver, public IAdapter { else m_json.push_back(""); + // Emission + if (!info.m_Emission.m_Map.empty()) + { + json jArr = json::array(); + + for (auto it = info.m_Emission.m_Map.begin(); info.m_Emission.m_Map.end() != it; it++) + { + auto val = it->second; + val.Negate(); + + json jEntry = json::array(); + jEntry.push_back(MakeObjAid(it->first)); + jEntry.push_back(MakeObjAmount(val)); + jArr.push_back(std::move(jEntry)); + } + + m_json.push_back(MakeTable(std::move(jArr))); + } + else + m_json.push_back(""); // Keys if (!info.m_vSigs.empty()) diff --git a/explorer/htm/explorer.htm b/explorer/htm/explorer.htm index 46a74aca1..583b6476b 100644 --- a/explorer/htm/explorer.htm +++ b/explorer/htm/explorer.htm @@ -367,7 +367,7 @@

Asset " + g_CurrentID + " history

\n\ let j = jRow[isInp ? "height" : "spent"]; - if (j) + if (j != null) { text += MakeCell(MakeBlock(j)); delete jRow.height; @@ -590,7 +590,8 @@

Asset " + g_CurrentID + " history

\n\ text += MakeCell(Obj2Html(jRow[3])); text += MakeCell(Obj2Html(jRow[4])); text += MakeCell(MakeFundsTbl(jRow[5]["value"])); - text += MakeCell(Obj2Html(jRow[6])); + text += MakeCell(MakeFundsTbl(jRow[6]["value"])); + text += MakeCell(Obj2Html(jRow[7])); text += ""; } @@ -647,6 +648,7 @@

Contract " + MakeMonospace(g_CurrentID) + "

\n"; Method\n\ Arguments\n\ Funds\n\ + Emisison\n\ Keys\n\ "; diff --git a/node/db.cpp b/node/db.cpp index 3ee5cc6e5..b61ddebbd 100644 --- a/node/db.cpp +++ b/node/db.cpp @@ -375,7 +375,7 @@ void NodeDB::Open(const char* szPath) bCreate = !rs.Step(); } - const uint64_t nVersionTop = 35; + const uint64_t nVersionTop = 36; Transaction t(*this); @@ -456,8 +456,6 @@ void NodeDB::Open(const char* szPath) // no break; case 33: // fix asset evt table, after previous Rebuild non-std - - ParamIntSet(ParamID::Flags1, ParamIntGetDef(ParamID::Flags1) | Flags1::PendingRebuildNonStd); // no break; case 34: @@ -470,8 +468,14 @@ void NodeDB::Open(const char* szPath) ParamDelSafe(ParamID::Deprecated_EventsSerif); CreateTables34(); + // no break; + + case 35: // changed format of contract invoke info + + ParamIntSet(ParamID::Flags1, ParamIntGetDef(ParamID::Flags1) | Flags1::PendingRebuildNonStd); ParamIntSet(ParamID::DbVer, nVersionTop); + // no break; case nVersionTop: diff --git a/node/processor.cpp b/node/processor.cpp index fba9c36d0..6f242a89f 100644 --- a/node/processor.cpp +++ b/node/processor.cpp @@ -3934,6 +3934,15 @@ bool NodeProcessor::HandleAssetEmit(const PeerID& pidOwner, BlockInterpretCtx& b return false; } +Amount SplitAmountSigned(AmountSigned val, bool& isPositive) +{ + isPositive = (val >= 0); + if (isPositive) + return val; + + return static_cast(-val); +} + bool NodeProcessor::HandleAssetEmit2(const PeerID& pidOwner, BlockInterpretCtx& bic, Asset::ID aid, AmountSigned val, uint32_t nSubIdx) { Asset::Full ai; @@ -3945,11 +3954,8 @@ bool NodeProcessor::HandleAssetEmit2(const PeerID& pidOwner, BlockInterpretCtx& return false; } - bool bAdd = (val >= 0); - Amount valUns = val; // treat as unsigned. - - if (!bAdd) - valUns = 0 - valUns; + bool bAdd; + Amount valUns = SplitAmountSigned(val, bAdd); AmountBig::Type valBig = valUns; if (bic.m_Fwd) @@ -5421,6 +5427,18 @@ bool NodeProcessor::BlockInterpretCtx::BvmProcessor::AssetEmit(Asset::ID aid, co if (!m_Proc.HandleAssetEmit(pidOwner, m_Bic, aid, val, m_AssetEvtSubIdx)) return false; + if (m_Bic.m_pvC) + { + auto& vec = *m_Bic.m_pvC; // alias + + assert(m_iCurrentInvokeExtraInfo <= vec.size()); + auto& x = vec[m_iCurrentInvokeExtraInfo - 1]; + + bool bAdd; + auto valUns = SplitAmountSigned(val, bAdd); + x.m_Emission.Add(valUns, aid, bAdd); + } + BlockInterpretCtx::Ser ser(m_Bic); RecoveryTag::Type nTag = RecoveryTag::AssetEmit; ser & nTag; diff --git a/node/processor.h b/node/processor.h index f74df1660..b35001806 100644 --- a/node/processor.h +++ b/node/processor.h @@ -409,6 +409,7 @@ class NodeProcessor struct ContractInvokeExtraInfoBase { FundsChangeMap m_FundsIO; // including nested + FundsChangeMap m_Emission; std::vector m_vSigs; // excluding nested uint32_t m_iParent; // including sub-nested uint32_t m_NumNested; @@ -425,6 +426,7 @@ class NodeProcessor ar & m_Sid & m_FundsIO.m_Map + & m_Emission.m_Map & m_vSigs & m_iParent & m_NumNested From b82041b266061542216722acad7aa6007f08fce4 Mon Sep 17 00:00:00 2001 From: valdok Date: Sun, 25 Jun 2023 11:57:19 +0300 Subject: [PATCH 2/2] build fix --- core/block_crypt.h | 1 - 1 file changed, 1 deletion(-) diff --git a/core/block_crypt.h b/core/block_crypt.h index ead77bae2..7ce30a363 100644 --- a/core/block_crypt.h +++ b/core/block_crypt.h @@ -118,7 +118,6 @@ namespace beam const T& m_Val; Printable(const T& x) :m_Val(x) {} - template friend std::ostream& operator << (std::ostream& os, const AmountBig::Printable& x) { AmountBig::Print(os, x.m_Val); return os;