Commit e3a6ef32 authored by artem-bv's avatar artem-bv

fix negative values for height count and skip in the list NFT RPC

parent ef537b04
......@@ -325,19 +325,19 @@ namespace Platform
}
void NfTokensManager::ProcessNftIndexRangeByHeight(std::function<bool(const NfTokenIndex &)> nftIndexHandler,
int height,
int count,
int skipFromTip) const
unsigned int height,
unsigned int count,
unsigned int skipFromTip) const
{
LOCK(m_cs);
if (PlatformDb::Instance().OptimizeSpeed())
{
auto originalRange = m_nfTokensIndexSet.get<Tags::Height>().range(
bmx::unbounded,
[&](int curHeight) { return curHeight <= height; }
[&](unsigned int curHeight) { return curHeight <= height; }
);
long rangeSize = std::distance(originalRange.first, originalRange.second);
unsigned long rangeSize = std::distance(originalRange.first, originalRange.second);
assert(rangeSize >= 0);
auto begin = skipFromTip + count > rangeSize ? originalRange.first : std::prev(originalRange.second, skipFromTip + count);
......@@ -359,9 +359,9 @@ namespace Platform
void NfTokensManager::ProcessNftIndexRangeByHeight(std::function<bool(const NfTokenIndex &)> nftIndexHandler,
uint64_t nftProtoId,
int height,
int count,
int skipFromTip) const
unsigned int height,
unsigned int count,
unsigned int skipFromTip) const
{
LOCK(m_cs);
if (PlatformDb::Instance().OptimizeSpeed())
......@@ -369,7 +369,7 @@ namespace Platform
auto first = m_nfTokensIndexSet.get<Tags::ProtocolIdHeight>().lower_bound(std::make_tuple(nftProtoId, 0));
auto second = m_nfTokensIndexSet.get<Tags::ProtocolIdHeight>().upper_bound(std::make_tuple(nftProtoId, height));
long rangeSize = std::distance(first, second);
unsigned long rangeSize = std::distance(first, second);
assert(rangeSize >= 0);
auto begin = skipFromTip + count > rangeSize ? first : std::prev(second, skipFromTip + count);
......@@ -391,9 +391,9 @@ namespace Platform
void NfTokensManager::ProcessNftIndexRangeByHeight(std::function<bool(const NfTokenIndex &)> nftIndexHandler,
CKeyID keyId,
int height,
int count,
int skipFromTip) const
unsigned int height,
unsigned int count,
unsigned int skipFromTip) const
{
LOCK(m_cs);
if (PlatformDb::Instance().OptimizeSpeed())
......@@ -401,7 +401,7 @@ namespace Platform
auto first = m_nfTokensIndexSet.get<Tags::OwnerId>().lower_bound(std::make_tuple(keyId, 0));
auto second = m_nfTokensIndexSet.get<Tags::OwnerId>().upper_bound(std::make_tuple(keyId, height));
long rangeSize = std::distance(first, second);
unsigned long rangeSize = std::distance(first, second);
assert(rangeSize >= 0);
auto begin = skipFromTip + count > rangeSize ? first : std::prev(second, skipFromTip + count);
......@@ -424,9 +424,9 @@ namespace Platform
void NfTokensManager::ProcessNftIndexRangeByHeight(std::function<bool(const NfTokenIndex &)> nftIndexHandler,
uint64_t nftProtoId,
CKeyID keyId,
int height,
int count,
int skipFromTip) const
unsigned int height,
unsigned int count,
unsigned int skipFromTip) const
{
LOCK(m_cs);
if (PlatformDb::Instance().OptimizeSpeed())
......@@ -434,7 +434,7 @@ namespace Platform
auto first = m_nfTokensIndexSet.get<Tags::ProtocolIdOwnerId>().lower_bound(std::make_tuple(nftProtoId, keyId, 0));
auto second = m_nfTokensIndexSet.get<Tags::ProtocolIdOwnerId>().upper_bound(std::make_tuple(nftProtoId, keyId, height));
long rangeSize = std::distance(first, second);
unsigned long rangeSize = std::distance(first, second);
assert(rangeSize >= 0);
auto begin = skipFromTip + count > rangeSize ? first : std::prev(second, skipFromTip + count);
......
......@@ -215,28 +215,28 @@ namespace Platform
void ProcessFullNftIndexRange(std::function<bool(const NfTokenIndex &)> nftIndexHandler) const;
void ProcessNftIndexRangeByHeight(std::function<bool(const NfTokenIndex &)> nftIndexHandler,
int height,
int count,
int skipFromTip) const;
unsigned int height,
unsigned int count,
unsigned int skipFromTip) const;
void ProcessNftIndexRangeByHeight(std::function<bool(const NfTokenIndex &)> nftIndexHandler,
uint64_t nftProtoId,
int height,
int count,
int skipFromTip) const;
unsigned int height,
unsigned int count,
unsigned int skipFromTip) const;
void ProcessNftIndexRangeByHeight(std::function<bool(const NfTokenIndex &)> nftIndexHandler,
CKeyID keyId,
int height,
int count,
int skipFromTip) const;
unsigned int height,
unsigned int count,
unsigned int skipFromTip) const;
void ProcessNftIndexRangeByHeight(std::function<bool(const NfTokenIndex &)> nftIndexHandler,
uint64_t nftProtoId,
CKeyID keyId,
int height,
int count,
int skipFromTip) const;
unsigned int height,
unsigned int count,
unsigned int skipFromTip) const;
/// Delete a specified nf-token
bool Delete(uint64_t protocolId, const uint256 & tokenId);
......
......@@ -123,17 +123,17 @@ namespace Platform
}
void NftProtocolsManager::ProcessNftProtoIndexRangeByHeight(std::function<bool(const NftProtoIndex &)> protoIndexHandler,
int height,
int count,
int skipFromTip) const
unsigned int height,
unsigned int count,
unsigned int skipFromTip) const
{
LOCK(m_cs);
auto originalRange = m_nftProtoIndexSet.get<Tags::Height>().range(
bmx::unbounded,
[&](int curHeight) { return curHeight <= height; }
[&](unsigned int curHeight) { return curHeight <= height; }
);
long rangeSize = std::distance(originalRange.first, originalRange.second);
unsigned long rangeSize = std::distance(originalRange.first, originalRange.second);
assert(rangeSize >= 0);
auto begin = skipFromTip + count > rangeSize ? originalRange.first : std::prev(originalRange.second, skipFromTip + count);
......
......@@ -106,9 +106,9 @@ namespace Platform
void ProcessFullNftProtoIndexRange(std::function<bool(const NftProtoIndex &)> protoIndexHandler) const;
void ProcessNftProtoIndexRangeByHeight(std::function<bool(const NftProtoIndex &)> protoIndexHandler,
int height,
int count,
int skipFromTip) const;
unsigned int height,
unsigned int count,
unsigned int skipFromTip) const;
/// Delete a specified nf-token protocol
bool Delete(uint64_t protocolId);
......
......@@ -209,12 +209,12 @@ List the most recent 20 NFT records
filterKeyId = ParsePubKeyIDFromAddress(params[2].get_str(), "nfTokenOwnerAddr");
}
static const int defaultTxsCount = 20;
static const int defaultSkipFromTip = 0;
int count = (params.size() > 3) ? ParseInt32V(params[3], "count") : defaultTxsCount;
int skipFromTip = (params.size() > 4) ? ParseInt32V(params[4], "skipFromTip") : defaultSkipFromTip;
static unsigned const int defaultTxsCount = 20;
static unsigned const int defaultSkipFromTip = 0;
unsigned int count = (params.size() > 3) ? ParseUInt32V(params[3], "count") : defaultTxsCount;
unsigned int skipFromTip = (params.size() > 4) ? ParseUInt32V(params[4], "skipFromTip") : defaultSkipFromTip;
int height = (params.size() > 5 && params[5].get_str() != "*") ? ParseInt32V(params[5], "height") : chainActive.Height();
unsigned int height = (params.size() > 5 && params[5].get_str() != "*") ? ParseUInt32V(params[5], "height") : chainActive.Height();
if (height < 0 || height > chainActive.Height())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height is out of range");
......
......@@ -143,12 +143,12 @@ Examples:
if (fHelp || params.empty() || params.size() > 5)
ListNftProtocolsHelp();
static const int defaultTxsCount = 20;
static const int defaultSkipFromTip = 0;
int count = (params.size() > 1) ? ParseInt32V(params[1], "count") : defaultTxsCount;
int skipFromTip = (params.size() > 2) ? ParseInt32V(params[2], "skipFromTip") : defaultSkipFromTip;
static const unsigned int defaultTxsCount = 20;
static const unsigned int defaultSkipFromTip = 0;
unsigned int count = (params.size() > 1) ? ParseUInt32V(params[1], "count") : defaultTxsCount;
unsigned int skipFromTip = (params.size() > 2) ? ParseUInt32V(params[2], "skipFromTip") : defaultSkipFromTip;
int height = (params.size() > 3 && params[3].get_str() != "*") ? ParseInt32V(params[3], "height") : chainActive.Height();
unsigned int height = (params.size() > 3 && params[3].get_str() != "*") ? ParseUInt32V(params[3], "height") : chainActive.Height();
if (height < 0 || height > chainActive.Height())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height is out of range");
......
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