Commit 80051896 authored by Artem B's avatar Artem B

fix nftproto and nftoken list API paging

parent 9b1855d1
......@@ -327,7 +327,7 @@ namespace Platform
void NfTokensManager::ProcessNftIndexRangeByHeight(std::function<bool(const NfTokenIndex &)> nftIndexHandler,
int height,
int count,
int startFrom) const
int skipFromTip) const
{
LOCK(m_cs);
if (PlatformDb::Instance().OptimizeSpeed())
......@@ -340,10 +340,8 @@ namespace Platform
long rangeSize = std::distance(originalRange.first, originalRange.second);
assert(rangeSize >= 0);
long reverseBegin = rangeSize < startFrom ? rangeSize : startFrom;
long reverseEnd = rangeSize < startFrom + count ? 0 : reverseBegin - count;
auto begin = std::prev(originalRange.second, reverseBegin);
auto end = std::prev(originalRange.second, reverseEnd);
auto begin = skipFromTip + count > rangeSize ? originalRange.first : std::prev(originalRange.second, skipFromTip + count);
auto end = skipFromTip > rangeSize ? originalRange.first : std::prev(originalRange.second, skipFromTip);
NftIndexRange finalRange(begin, end);
for (const auto & nftIndex : finalRange)
......@@ -363,7 +361,7 @@ namespace Platform
uint64_t nftProtoId,
int height,
int count,
int startFrom) const
int skipFromTip) const
{
LOCK(m_cs);
if (PlatformDb::Instance().OptimizeSpeed())
......@@ -374,10 +372,8 @@ namespace Platform
long rangeSize = std::distance(first, second);
assert(rangeSize >= 0);
long reverseBegin = rangeSize < startFrom ? rangeSize : startFrom;
long reverseEnd = rangeSize < startFrom + count ? 0 : reverseBegin - count;
auto begin = std::prev(second, reverseBegin);
auto end = std::prev(second, reverseEnd);
auto begin = skipFromTip + count > rangeSize ? first : std::prev(second, skipFromTip + count);
auto end = skipFromTip > rangeSize ? first : std::prev(second, skipFromTip);
NftIndexRange finalRange(begin, end);
for (const auto & nftIndex : finalRange)
......@@ -397,7 +393,7 @@ namespace Platform
CKeyID keyId,
int height,
int count,
int startFrom) const
int skipFromTip) const
{
LOCK(m_cs);
if (PlatformDb::Instance().OptimizeSpeed())
......@@ -408,10 +404,8 @@ namespace Platform
long rangeSize = std::distance(first, second);
assert(rangeSize >= 0);
long reverseBegin = rangeSize < startFrom ? rangeSize : startFrom;
long reverseEnd = rangeSize < startFrom + count ? 0 : reverseBegin - count;
auto begin = std::prev(second, reverseBegin);
auto end = std::prev(second, reverseEnd);
auto begin = skipFromTip + count > rangeSize ? first : std::prev(second, skipFromTip + count);
auto end = skipFromTip > rangeSize ? first : std::prev(second, skipFromTip);
NftIndexRange finalRange(begin, end);
for (const auto & nftIndex : finalRange)
......@@ -432,7 +426,7 @@ namespace Platform
CKeyID keyId,
int height,
int count,
int startFrom) const
int skipFromTip) const
{
LOCK(m_cs);
if (PlatformDb::Instance().OptimizeSpeed())
......@@ -443,10 +437,8 @@ namespace Platform
long rangeSize = std::distance(first, second);
assert(rangeSize >= 0);
long reverseBegin = rangeSize < startFrom ? rangeSize : startFrom;
long reverseEnd = rangeSize < startFrom + count ? 0 : reverseBegin - count;
auto begin = std::prev(second, reverseBegin);
auto end = std::prev(second, reverseEnd);
auto begin = skipFromTip + count > rangeSize ? first : std::prev(second, skipFromTip + count);
auto end = skipFromTip > rangeSize ? first : std::prev(second, skipFromTip);
NftIndexRange finalRange(begin, end);
for (const auto & nftIndex : finalRange)
......
......@@ -217,26 +217,26 @@ namespace Platform
void ProcessNftIndexRangeByHeight(std::function<bool(const NfTokenIndex &)> nftIndexHandler,
int height,
int count,
int startFrom) const;
int skipFromTip) const;
void ProcessNftIndexRangeByHeight(std::function<bool(const NfTokenIndex &)> nftIndexHandler,
uint64_t nftProtoId,
int height,
int count,
int startFrom) const;
int skipFromTip) const;
void ProcessNftIndexRangeByHeight(std::function<bool(const NfTokenIndex &)> nftIndexHandler,
CKeyID keyId,
int height,
int count,
int startFrom) const;
int skipFromTip) const;
void ProcessNftIndexRangeByHeight(std::function<bool(const NfTokenIndex &)> nftIndexHandler,
uint64_t nftProtoId,
CKeyID keyId,
int height,
int count,
int startFrom) const;
int skipFromTip) const;
/// Delete a specified nf-token
bool Delete(uint64_t protocolId, const uint256 & tokenId);
......
......@@ -119,7 +119,7 @@ namespace Platform
void NftProtocolsManager::ProcessNftProtoIndexRangeByHeight(std::function<bool(const NftProtoIndex &)> protoIndexHandler,
int height,
int count,
int startFrom) const
int skipFromTip) const
{
LOCK(m_cs);
auto originalRange = m_nftProtoIndexSet.get<Tags::Height>().range(
......@@ -130,10 +130,8 @@ namespace Platform
long rangeSize = std::distance(originalRange.first, originalRange.second);
assert(rangeSize >= 0);
long reverseBegin = rangeSize < startFrom ? rangeSize : startFrom;
long reverseEnd = rangeSize < startFrom + count ? 0 : reverseBegin - count;
auto begin = std::prev(originalRange.second, reverseBegin);
auto end = std::prev(originalRange.second, reverseEnd);
auto begin = skipFromTip + count > rangeSize ? originalRange.first : std::prev(originalRange.second, skipFromTip + count);
auto end = skipFromTip > rangeSize ? originalRange.first : std::prev(originalRange.second, skipFromTip);
NftProtoIndexRange finalRange(begin, end);
for (const auto & protoIndex : finalRange)
......
......@@ -105,7 +105,7 @@ namespace Platform
void ProcessNftProtoIndexRangeByHeight(std::function<bool(const NftProtoIndex &)> protoIndexHandler,
int height,
int count,
int startFrom) const;
int skipFromTip) const;
/// Delete a specified nf-token protocol
bool Delete(uint64_t protocolId);
......
......@@ -131,7 +131,7 @@ Arguments:
The private key belonging to this address may be or may be not known in your wallet. If "*" is set, it will list NFTs for all addresses.
3. height (numeric, optional) If height is not specified, it defaults to the current chain-tip
4. count (numeric, optional, default=20) The number of transactions to return
5. from (numeric, optional, default=0) The number of transactions to skip
5. skipFromTip (numeric, optional, default=0) The number of transactions to skip from tip
6. regTxOnly (boolean, optional, default=false) false for a detailed list, true for an array of transaction IDs
Examples:
......@@ -151,10 +151,10 @@ List the most recent 20 NFT records
+ R"(List the most recent 20 records of the "doc" NFT protocol and "CRWS78Yf5kbWAyfcES6RfiTVzP87csPNhZzc" address up to 5050st block
)"
+ HelpExampleCli("nftoken", R"(list "doc" "CRWS78Yf5kbWAyfcES6RfiTVzP87csPNhZzc" 5050)")
+ R"(List records 100 to 150 of the "doc" NFT protocol and "CRWS78Yf5kbWAyfcES6RfiTVzP87csPNhZzc" address up to 5050st block
+ R"(List recent 100 records skipping 50 from the end of the "doc" NFT protocol and "CRWS78Yf5kbWAyfcES6RfiTVzP87csPNhZzc" address up to 5050st block
)"
+ HelpExampleCli("nftoken", R"(list "doc" "CRWS78Yf5kbWAyfcES6RfiTVzP87csPNhZzc" 5050 100 50)")
+ R"(List records 100 to 150 of the "doc" NFT protocol and "CRWS78Yf5kbWAyfcES6RfiTVzP87csPNhZzc" address up to 5050st block. List only registration tx IDs.
+ R"(List recent 100 records skipping 50 from the end of the "doc" NFT protocol and "CRWS78Yf5kbWAyfcES6RfiTVzP87csPNhZzc" address up to 5050st block. List only registration tx IDs.
)"
+ HelpExampleCli("nftoken", R"(list "doc" "CRWS78Yf5kbWAyfcES6RfiTVzP87csPNhZzc" 5050 100 50 true)")
+ R"(As JSON-RPC calls
......@@ -213,9 +213,9 @@ List the most recent 20 NFT records
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height is out of range");
static const int defaultTxsCount = 20;
static const int defaultStartFrom = 20;
static const int defaultSkipFromTip = 0;
int count = (params.size() > 4) ? ParseInt32V(params[4], "count") : defaultTxsCount;
int startFrom = (params.size() > 5) ? ParseInt32V(params[5], "from") : defaultStartFrom;
int skipFromTip = (params.size() > 5) ? ParseInt32V(params[5], "skipFromTip") : defaultSkipFromTip;
bool regTxOnly = (params.size() > 6) ? ParseBoolV(params[6], "regTxOnly") : false;
json_spirit::Array nftList;
......@@ -236,13 +236,13 @@ List the most recent 20 NFT records
};
if (nftProtoId == NfToken::UNKNOWN_TOKEN_PROTOCOL && filterKeyId.IsNull())
NfTokensManager::Instance().ProcessNftIndexRangeByHeight(nftIndexHandler, height, count, startFrom);
NfTokensManager::Instance().ProcessNftIndexRangeByHeight(nftIndexHandler, height, count, skipFromTip);
else if (nftProtoId != NfToken::UNKNOWN_TOKEN_PROTOCOL && filterKeyId.IsNull())
NfTokensManager::Instance().ProcessNftIndexRangeByHeight(nftIndexHandler, nftProtoId, height, count, startFrom);
NfTokensManager::Instance().ProcessNftIndexRangeByHeight(nftIndexHandler, nftProtoId, height, count, skipFromTip);
else if (nftProtoId == NfToken::UNKNOWN_TOKEN_PROTOCOL && !filterKeyId.IsNull())
NfTokensManager::Instance().ProcessNftIndexRangeByHeight(nftIndexHandler, filterKeyId, height, count, startFrom);
NfTokensManager::Instance().ProcessNftIndexRangeByHeight(nftIndexHandler, filterKeyId, height, count, skipFromTip);
else if (nftProtoId != NfToken::UNKNOWN_TOKEN_PROTOCOL && !filterKeyId.IsNull())
NfTokensManager::Instance().ProcessNftIndexRangeByHeight(nftIndexHandler, nftProtoId, filterKeyId, height, count, startFrom);
NfTokensManager::Instance().ProcessNftIndexRangeByHeight(nftIndexHandler, nftProtoId, filterKeyId, height, count, skipFromTip);
return nftList;
}
......
......@@ -150,9 +150,9 @@ Examples:
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height is out of range");
static const int defaultTxsCount = 20;
static const int defaultStartFrom = 20;
static const int defaultSkipFromTip = 0;
int count = (params.size() > 2) ? ParseInt32V(params[2], "count") : defaultTxsCount;
int startFrom = (params.size() > 3) ? ParseInt32V(params[3], "from") : defaultStartFrom;
int skipFromTip = (params.size() > 3) ? ParseInt32V(params[3], "skipFromTip") : defaultSkipFromTip;
bool regTxOnly = (params.size() > 4) ? ParseBoolV(params[4], "regTxOnly") : false;
json_spirit::Array protoList;
......@@ -172,7 +172,7 @@ Examples:
return true;
};
NftProtocolsManager::Instance().ProcessNftProtoIndexRangeByHeight(protoHandler, height, count, startFrom);
NftProtocolsManager::Instance().ProcessNftProtoIndexRangeByHeight(protoHandler, height, count, skipFromTip);
return protoList;
}
......@@ -185,7 +185,7 @@ Lists all NFT protocol records on chain
Arguments:
1. height (numeric, optional) If height is not specified, it defaults to the current chain-tip
2. count (numeric, optional, default=20) The number of transactions to return
3. from (numeric, optional, default=0) The number of transactions to skip
3. skipFromTip (numeric, optional, default=0) The number of transactions to skip from tip
4. regTxOnly (boolean, optional, default=false) false for a detailed list, true for an array of transaction IDs
Examples:
......@@ -195,10 +195,10 @@ List the most recent 20 NFT protocol records
+ R"(List the most recent 20 NFT protocol records up to 5050st block
)"
+ HelpExampleCli("nftproto", R"(list 5050)")
+ R"(List records 100 to 150 up to 5050st block
+ R"(List recent 100 records skipping 50 from the end up to 5050st block
)"
+ HelpExampleCli("nftproto", R"(list 5050 100 50)")
+ R"(List records 100 to 150 up to 5050st block. List only registration tx IDs.
+ R"(List recent 100 records skipping 50 from the end up to 5050st block. List only registration tx IDs.
)"
+ HelpExampleCli("nftoken", R"(list 5050 100 50 true)")
+ R"(As JSON-RPC calls
......
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