Commit 4e6f01da authored by Artem B's avatar Artem B

Enhancement request: add nftproto equivalent of nftoken totalsupply #345

parent 33b3c9e4
Pipeline #1165 failed with stage
in 17 minutes and 46 seconds
......@@ -106,6 +106,12 @@ namespace Platform
return CKeyID();
}
std::size_t NftProtocolsManager::TotalSupply() const
{
LOCK(m_cs);
return m_totalProtocolsCount;
}
void NftProtocolsManager::ProcessFullNftProtoIndexRange(std::function<bool(const NftProtoIndex &)> protoIndexHandler) const
{
LOCK(m_cs);
......
......@@ -99,6 +99,9 @@ namespace Platform
/// Owner of a specified nf-token protocol
CKeyID OwnerOf(uint64_t protocolId);
/// Retrieve total amount of nft protocols
std::size_t TotalSupply() const;
using NftProtoIndexRange = boost::any_range<const NftProtoIndex &, boost::bidirectional_traversal_tag>;
void ProcessFullNftProtoIndexRange(std::function<bool(const NftProtoIndex &)> protoIndexHandler) const;
......
......@@ -26,6 +26,8 @@ json_spirit::Value nftproto(const json_spirit::Array& params, bool fHelp)
return Platform::GetNftProtocolByTxId(params, fHelp);
else if (command == "ownerof")
return Platform::NftProtoOwnerOf(params, fHelp);
else if (command == "totalsupply")
return Platform::NftProtoTotalSupply(params, fHelp);
throw std::runtime_error("Invalid command: " + command);
}
......@@ -296,4 +298,25 @@ Examples:
return CBitcoinAddress(ownerId).ToString();
}
json_spirit::Value NftProtoTotalSupply(const json_spirit::Array& params, bool fHelp)
{
if (fHelp || params.empty() || params.size() > 1)
NftProtoTotalSupplyHelp();
std::size_t totalSupply = NftProtocolsManager::Instance().TotalSupply();
return static_cast<uint64_t>(totalSupply);
}
void NftProtoTotalSupplyHelp()
{
static std::string helpMessage = R"(nftproto totalsupply
Get NFT protocols current total supply
Examples:
)"
+ HelpExampleCli("nftproto", "totalsupply")
+ HelpExampleRpc("nftproto", R"(totalsupply)");
throw std::runtime_error(helpMessage);
}
}
\ No newline at end of file
......@@ -21,6 +21,8 @@ namespace Platform
void GetNftProtocolByTxIdHelp();
json_spirit::Value NftProtoOwnerOf(const json_spirit::Array& params, bool fHelp);
void NftProtoOwnerOfHelp();
json_spirit::Value NftProtoTotalSupply(const json_spirit::Array& params, bool fHelp);
void NftProtoTotalSupplyHelp();
}
#endif // PROJECT_RPC_NFT_PROTO_H
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