From d121672ec7dabf3f117b9b9326e2606dfac22f06 Mon Sep 17 00:00:00 2001 From: valdok Date: Mon, 4 Dec 2023 14:17:25 +0200 Subject: [PATCH] explorer node: assets removed from block info into /assets --- explorer/adapter.cpp | 87 ++++++++++++++++++++++---------------------- explorer/adapter.h | 8 +--- explorer/server.cpp | 6 +++ explorer/server.h | 3 +- 4 files changed, 53 insertions(+), 51 deletions(-) diff --git a/explorer/adapter.cpp b/explorer/adapter.cpp index 180ce308b..caff17a15 100644 --- a/explorer/adapter.cpp +++ b/explorer/adapter.cpp @@ -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; @@ -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}, @@ -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; } diff --git a/explorer/adapter.h b/explorer/adapter.h index 4d0e29e30..fee3d93fd 100644 --- a/explorer/adapter.h +++ b/explorer/adapter.h @@ -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); diff --git a/explorer/server.cpp b/explorer/server.cpp index 3efd3180b..f6c6ee650 100644 --- a/explorer/server.cpp +++ b/explorer/server.cpp @@ -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); diff --git a/explorer/server.h b/explorer/server.h index 1434297b2..6c869c9dc 100644 --- a/explorer/server.h +++ b/explorer/server.h @@ -31,7 +31,8 @@ macro(swap_totals) \ macro(contracts) \ macro(contract) \ - macro(asset) + macro(asset) \ + macro(assets) namespace beam { namespace explorer {