Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/groovy_gluon_7.2RC' into…
Browse files Browse the repository at this point in the history
… mainnet
  • Loading branch information
anatolse committed Nov 7, 2022
2 parents af52e3c + 87052a2 commit 826d41c
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 0 deletions.
24 changes: 24 additions & 0 deletions bvm/ManagerStd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,30 @@ namespace bvm2 {
return false;
}

bool ManagerStd::get_AssetInfo(Asset::Full& ai)
{
if (!m_Pending.m_pSingleRequest)
{
proto::FlyClient::RequestAsset::Ptr pReq(new proto::FlyClient::RequestAsset);
pReq->m_Msg.m_AssetID = ai.m_ID;
PerformSingleRequest(*pReq);
}

if (!IsSuspended())
{
auto pReq = GetResSingleRequest();
auto& r = pReq->As<proto::FlyClient::RequestAsset>();

if (!r.m_Res.m_Proof.empty())
{
ai = std::move(r.m_Res.m_Info);
return true;
}
}

return false;
}

bool ManagerStd::LogGetProof(const HeightPos& hp, beam::Merkle::Proof& proof)
{
if (!m_Pending.m_pSingleRequest)
Expand Down
1 change: 1 addition & 0 deletions bvm/ManagerStd.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace beam::bvm2 {
bool get_HdrAt(Block::SystemState::Full&) override;
void VarsEnum(const Blob& kMin, const Blob& kMax, IReadVars::Ptr&) override;
void LogsEnum(const Blob& kMin, const Blob& kMax, const HeightPos* pPosMin, const HeightPos* pPosMax, IReadLogs::Ptr&) override;
bool get_AssetInfo(Asset::Full&) override;
void get_ContractShader(ByteBuffer&) override;
bool get_SpecialParam(const char*, Blob&) override;
bool VarGetProof(Blob& key, ByteBuffer& val, beam::Merkle::Proof&) override;
Expand Down
33 changes: 33 additions & 0 deletions bvm/bvm2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,39 @@ namespace bvm2 {

BVM_METHOD_HOST_AUTO(get_ForkHeight)

BVM_METHOD(get_AssetInfo)
{
if (Kind::Contract == get_Kind())
{
Wasm::Test(IsPastFork(6));
DischargeUnits(Limits::Cost::LoadVar);
}

return OnHost_get_AssetInfo(aid, get_AddrAsW<AssetInfo>(res), get_AddrW(pMetadata, nMetadata), nMetadata);
}

BVM_METHOD_HOST(get_AssetInfo)
{
ZeroObject(res);

Asset::Full ai;
ai.m_ID = aid;
if (get_AssetInfo(ai))
{
res.m_ValueLo = AmountBig::get_Lo(ai.m_Value);
res.m_ValueHi = AmountBig::get_Hi(ai.m_Value);
res.m_Owner = Cast::Down<HashValue>(ai.m_Owner);
res.m_Cid = ai.m_Cid;
res.m_LockHeight = ai.m_LockHeight;
res.m_Deposit = ai.m_Deposit;
}

Blob md(ai.m_Metadata.m_Value);
memcpy(pMetadata, md.p, std::min(nMetadata, md.n));

return md.n;
}

struct Processor::DataProcessor::Instance
{
template <uint32_t nBytes>
Expand Down
2 changes: 2 additions & 0 deletions bvm/bvm2.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace bvm2 {
using Shaders::HashValue;
using Shaders::HashValue512;
using Shaders::BlockHeader;
using Shaders::AssetInfo;

namespace Merkle {
using namespace Shaders::Merkle;
Expand Down Expand Up @@ -182,6 +183,7 @@ namespace bvm2 {
virtual uint32_t get_HeapLimit() { return 0; }
virtual Height get_Height() { return 0; }
virtual bool get_HdrAt(Block::SystemState::Full& s) { return false; }
virtual bool get_AssetInfo(Asset::Full&) { return false; }

template <typename T> const T& get_AddrAsR(uint32_t nOffset) {
return *reinterpret_cast<const T*>(get_AddrR(nOffset, sizeof(T)));
Expand Down
7 changes: 7 additions & 0 deletions bvm/bvm2_opcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@

#define BVMOp_Halt(macro, sep)

#define BVMOp_get_AssetInfo(macro, sep) \
macro(AssetID, aid) sep \
macro(AssetInfo&, res) sep \
macro(void*, pMetadata) sep \
macro(uint32_t, nMetadata)

#define BVMOp_AddSig(macro, sep) \
macro(const PubKey&, pubKey)

Expand Down Expand Up @@ -485,6 +491,7 @@
macro(0x1A, void* , Heap_Alloc) \
macro(0x1B, void , Heap_Free) \
macro(0x28, void , Halt) \
macro(0x2A, uint32_t , get_AssetInfo) \
macro(0x2B, void , HashWrite) \
macro(0x2D, void , HashGetValue) \
macro(0x2E, void , HashFree) \
Expand Down
10 changes: 10 additions & 0 deletions bvm/bvm2_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,14 @@ struct ApiVersion
static const uint32_t Current = 1;
};

struct AssetInfo
{
Amount m_ValueLo;
Amount m_ValueHi;
HashValue m_Owner;
ContractID m_Cid; // seto to 0 if owned by user
Height m_LockHeight;
Amount m_Deposit;
};

#pragma pack (pop)
6 changes: 6 additions & 0 deletions node/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2456,6 +2456,7 @@ struct NodeProcessor::BlockInterpretCtx
virtual void LoadVarEx(Blob& key, Blob& res, bool bExact, bool bBigger) override;
virtual uint32_t SaveVar(const Blob& key, const Blob&) override;
virtual uint32_t OnLog(const Blob& key, const Blob& val) override;
virtual bool get_AssetInfo(Asset::Full&) override;

virtual Height get_Height() override;
virtual bool get_HdrAt(Block::SystemState::Full&) override;
Expand Down Expand Up @@ -5120,6 +5121,11 @@ uint32_t NodeProcessor::BlockInterpretCtx::BvmProcessor::OnLog(const Blob& key,
return m_Bic.m_ContractLogs++;
}

bool NodeProcessor::BlockInterpretCtx::BvmProcessor::get_AssetInfo(Asset::Full& ai)
{
return m_Proc.get_DB().AssetGetSafe(ai);
}

Height NodeProcessor::BlockInterpretCtx::BvmProcessor::get_Height()
{
return m_Bic.m_Height - 1;
Expand Down

0 comments on commit 826d41c

Please sign in to comment.