Skip to content

Commit

Permalink
Merge branch 'master' into vladik5
Browse files Browse the repository at this point in the history
  • Loading branch information
valdok committed Jun 25, 2023
2 parents 6a936f3 + b82041b commit 0df816e
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 18 deletions.
1 change: 0 additions & 1 deletion core/block_crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ namespace beam
const T& m_Val;
Printable(const T& x) :m_Val(x) {}

template <typename T>
friend std::ostream& operator << (std::ostream& os, const AmountBig::Printable<T>& x) {
AmountBig::Print(os, x.m_Val);
return os;
Expand Down
42 changes: 35 additions & 7 deletions explorer/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; )
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -554,6 +559,7 @@ class Adapter : public Node::IObserver, public IAdapter {
MakeTableHdr("Method"),
MakeTableHdr("Arguments"),
MakeTableHdr("Funds"),
MakeTableHdr("Emission"),
MakeTableHdr("Keys")
}));

Expand Down Expand Up @@ -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();
Expand All @@ -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())
Expand Down
6 changes: 4 additions & 2 deletions explorer/htm/explorer.htm
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h2>Asset " + g_CurrentID + " history</h2>\n\

let j = jRow[isInp ? "height" : "spent"];

if (j)
if (j != null)
{
text += MakeCell(MakeBlock(j));
delete jRow.height;
Expand Down Expand Up @@ -590,7 +590,8 @@ <h2>Asset " + g_CurrentID + " history</h2>\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 += "</tr>";
}
Expand Down Expand Up @@ -647,6 +648,7 @@ <h2>Contract " + MakeMonospace(g_CurrentID) + "</h2>\n";
<th>Method</th>\n\
<th>Arguments</th>\n\
<th>Funds</th>\n\
<th>Emisison</th>\n\
<th>Keys</th>\n\
";

Expand Down
10 changes: 7 additions & 3 deletions node/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
28 changes: 23 additions & 5 deletions node/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Amount>(-val);
}

bool NodeProcessor::HandleAssetEmit2(const PeerID& pidOwner, BlockInterpretCtx& bic, Asset::ID aid, AmountSigned val, uint32_t nSubIdx)
{
Asset::Full ai;
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions node/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ class NodeProcessor
struct ContractInvokeExtraInfoBase
{
FundsChangeMap m_FundsIO; // including nested
FundsChangeMap m_Emission;
std::vector<ECC::Point> m_vSigs; // excluding nested
uint32_t m_iParent; // including sub-nested
uint32_t m_NumNested;
Expand All @@ -425,6 +426,7 @@ class NodeProcessor
ar
& m_Sid
& m_FundsIO.m_Map
& m_Emission.m_Map
& m_vSigs
& m_iParent
& m_NumNested
Expand Down

0 comments on commit 0df816e

Please sign in to comment.