Commit b2e3c151 authored by Artem B's avatar Artem B

fix issue #344 nftoken totalsupply

parent f11d3ec3
......@@ -7,6 +7,7 @@
#include "platform/platform-utils.h"
#include "platform/specialtx.h"
#include "nft-protocols-manager.h"
#include "nf-tokens-manager.h"
#include "sync.h"
#include "main.h"
......@@ -70,6 +71,7 @@ namespace Platform
if (!NftProtocolsManager::Instance().AddNftProto(nftProto, tx, pindex))
return state.DoS(100, false, REJECT_DUPLICATE/*TODO: REJECT_CONFLICT*/, "nft-proto-reg-tx-conflict");
NfTokensManager::Instance().OnNewProtocolRegistered(nftProto.tokenProtocolId);
return true;
}
......
......@@ -36,7 +36,7 @@ namespace Platform
{
PlatformDb::Instance().ProcessPlatformDbGuts([&, this](const leveldb::Iterator & dbIt) -> bool
{
if (!PlatformDb::Instance().ProcessNftProtosSupply(dbIt, protoSupplyHandler))
if (!PlatformDb::Instance().ProcessNftSupply(dbIt, protoSupplyHandler))
{
return false;
}
......@@ -50,7 +50,7 @@ namespace Platform
{
PlatformDb::Instance().ProcessPlatformDbGuts([&](const leveldb::Iterator & dbIt) -> bool
{
PlatformDb::Instance().ProcessNftProtosSupply(dbIt, protoSupplyHandler);
PlatformDb::Instance().ProcessNftSupply(dbIt, protoSupplyHandler);
return true;
});
}
......@@ -502,6 +502,13 @@ namespace Platform
}
}
void NfTokensManager::OnNewProtocolRegistered(uint64_t protocolId)
{
LOCK(m_cs);
m_protocolsTotalSupply[protocolId] = 0;
PlatformDb::Instance().WriteTotalSupply(0, protocolId);
}
void NfTokensManager::UpdateTotalSupply(uint64_t protocolId, bool increase)
{
std::size_t updatedSize = increase ? ++m_protocolsTotalSupply[protocolId] : --m_protocolsTotalSupply[protocolId];
......
......@@ -246,6 +246,9 @@ namespace Platform
/// Update with the best block tip
void UpdateBlockTip(const CBlockIndex * pindex);
/// Add new registered NFT protocol
void OnNewProtocolRegistered(uint64_t protocolId);
private:
NfTokensManager();
......
......@@ -164,9 +164,9 @@ namespace Platform
return true;
}
bool PlatformDb::ProcessNftProtosSupply(const leveldb::Iterator & dbIt, std::function<bool(uint64_t, std::size_t)> protoSupplyHandler)
bool PlatformDb::ProcessNftSupply(const leveldb::Iterator & dbIt, std::function<bool(uint64_t, std::size_t)> protoSupplyHandler)
{
if (dbIt.key().starts_with(std::string(1, DB_NFT_PROTO_TOTAL)))
if (dbIt.key().starts_with(std::string(1, DB_NFT_TOTAL)))
{
leveldb::Slice sliceKey = dbIt.key();
CDataStream streamKey(sliceKey.data(), sliceKey.data() + sliceKey.size(), SER_DISK, CLIENT_VERSION);
......
......@@ -57,7 +57,7 @@ namespace Platform
void ProcessNftProtoIndexGutsOnly(std::function<bool(NftProtoIndex)> protoIndexHandler);
bool ProcessNftIndex(const leveldb::Iterator & dbIt, std::function<bool(NfTokenIndex)> nftIndexHandler);
bool ProcessNftProtoIndex(const leveldb::Iterator & dbIt, std::function<bool(NftProtoIndex)> protoIndexHandler);
bool ProcessNftProtosSupply(const leveldb::Iterator & dbIt, std::function<bool(uint64_t, std::size_t)> protoSupplyHandler);
bool ProcessNftSupply(const leveldb::Iterator & dbIt, std::function<bool(uint64_t, std::size_t)> protoSupplyHandler);
bool IsNftIndexEmpty();
void WriteNftDiskIndex(const NfTokenDiskIndex & nftDiskIndex);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment