Skip to content

Commit

Permalink
explorer node: assets removed from block info into /assets
Browse files Browse the repository at this point in the history
  • Loading branch information
valdok committed Dec 4, 2023
1 parent cd50b52 commit d121672
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 51 deletions.
87 changes: 44 additions & 43 deletions explorer/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,47 @@ class Adapter : public Node::IObserver, public IAdapter {
return wr.m_json;
}

json get_assets_at(Height h) override
{
json jAssets = json::array();
jAssets.push_back(json::array({
MakeTableHdr("Aid"),
MakeTableHdr("Owner"),
MakeTableHdr("Deposit"),
MakeTableHdr("Supply"),
MakeTableHdr("Lock height"),
MakeTableHdr("Metadata")
}));

Asset::Full ai;
for (ai.m_ID = 1; ; ai.m_ID++)
{
int ret = _nodeBackend.get_AssetAt(ai, h);
if (!ret)
break;
if (ret < 0)
continue;

ExtraInfo::Writer wr(json::array());
wr.m_json.push_back(MakeObjAid(ai.m_ID));

wr.m_json.push_back(ExtraInfo::Writer::get_AssetOwner(ai));

wr.m_json.push_back(MakeObjAmount(ai.m_Deposit));
wr.m_json.push_back(MakeObjAmount(ai.m_Value));

wr.m_json.push_back(ai.m_LockHeight);

std::string s;
ai.m_Metadata.get_String(s);
wr.m_json.push_back(std::move(s));

jAssets.push_back(std::move(wr.m_json));
}

return jAssets;
}

static uint32_t ExpanedNumWithCommas(char* szDst, const char* szSrc, uint32_t len)
{
const uint32_t nGroupLen = 3;
Expand Down Expand Up @@ -1761,48 +1802,11 @@ class Adapter : public Node::IObserver, public IAdapter {
kernels.push_back(std::move(j));
}


json jAssets = json::array();
jAssets.push_back(json::array({
MakeTableHdr("Aid"),
MakeTableHdr("Owner"),
MakeTableHdr("Deposit"),
MakeTableHdr("Supply"),
MakeTableHdr("Lock height"),
MakeTableHdr("Metadata")
}));

Asset::Full ai;
for (ai.m_ID = 1; ; ai.m_ID++)
{
int ret = _nodeBackend.get_AssetAt(ai, height);
if (!ret)
break;
if (ret < 0)
continue;

ExtraInfo::Writer wr(json::array());
wr.m_json.push_back(MakeObjAid(ai.m_ID));

wr.m_json.push_back(ExtraInfo::Writer::get_AssetOwner(ai));

wr.m_json.push_back(MakeObjAmount(ai.m_Deposit));
wr.m_json.push_back(MakeObjAmount(ai.m_Value));

wr.m_json.push_back(ai.m_LockHeight);

std::string s;
ai.m_Metadata.get_String(s);
wr.m_json.push_back(std::move(s));

jAssets.push_back(std::move(wr.m_json));
}

auto btcRate = _exchangeRateProvider->getBeamTo(wallet::Currency::BTC(), blockState.m_Height);
auto usdRate = _exchangeRateProvider->getBeamTo(wallet::Currency::USD(), blockState.m_Height);

if (Mode::Legacy == m_Mode)
{
auto btcRate = _exchangeRateProvider->getBeamTo(wallet::Currency::BTC(), blockState.m_Height);
auto usdRate = _exchangeRateProvider->getBeamTo(wallet::Currency::USD(), blockState.m_Height);

out = json{
{"found", true},
{"timestamp", blockState.m_TimeStamp},
Expand Down Expand Up @@ -1842,12 +1846,9 @@ class Adapter : public Node::IObserver, public IAdapter {
out["info"] = MakeTable(std::move(jInfo));
}

out["assets"] = MakeTable(std::move(jAssets));
out["inputs"] = std::move(inputs);
out["outputs"] = std::move(outputs);
out["kernels"] = std::move(kernels);

LOG_DEBUG() << out;
}
return ok;
}
Expand Down
8 changes: 1 addition & 7 deletions explorer/adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,20 @@ struct IAdapter {

/// Returns body for /status request
virtual json get_status() = 0;

virtual json get_block(uint64_t height) = 0;

virtual json get_block_by_kernel(const Blob& key) = 0;

virtual json get_blocks(uint64_t startHeight, uint64_t n) = 0;

virtual json get_hdrs(uint64_t hMax, uint64_t nMax) = 0;

virtual json get_peers() = 0;

#ifdef BEAM_ATOMIC_SWAP_SUPPORT
virtual json get_swap_offers() = 0;

virtual json get_swap_totals() = 0;
#endif // BEAM_ATOMIC_SWAP_SUPPORT

virtual json get_contracts() = 0;
virtual json get_contract_details(const Blob& id, Height hMin, Height hMax, uint32_t nMaxTxs) = 0;
virtual json get_asset_history(uint32_t, Height hMin, Height hMax, uint32_t nMaxOps) = 0;
virtual json get_assets_at(Height) = 0;
};

IAdapter::Ptr create_adapter(Node& node);
Expand Down
6 changes: 6 additions & 0 deletions explorer/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,12 @@ OnRequest(asset)
return _backend.get_asset_history((uint32_t) aid, hMin, hMax, nMaxOps);
}

OnRequest(assets)
{
auto height = _currentUrl.get_int_arg("height", 0);
return _backend.get_assets_at(height);
}

bool Server::send(const HttpConnection::Ptr& conn, int code, const char* message, bool isHtml)
{
assert(conn);
Expand Down
3 changes: 2 additions & 1 deletion explorer/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
macro(swap_totals) \
macro(contracts) \
macro(contract) \
macro(asset)
macro(asset) \
macro(assets)

namespace beam { namespace explorer {

Expand Down

0 comments on commit d121672

Please sign in to comment.