Commit 91ca83d9 authored by artem-bv's avatar artem-bv

fix issue #352, restrict invalid characters in protocol ID

parent e3a6ef32
......@@ -27,6 +27,7 @@ namespace Platform
public:
/// NF token protocol unique symbol/identifier, can be an a abbreviated name describing this NF token type
/// Represented as a base32 string, can only contain characters: .abcdefghijklmnopqrstuvwxyz12345
/// Dots(.) are not allowed as a first and last characters
/// Minimum length 3 symbols, maximum length 12 symbols
uint64_t tokenProtocolId;
......
......@@ -19,6 +19,8 @@ namespace Platform
NfTokenRegTxBuilder & SetTokenProtocol(const json_spirit::Value & tokenProtocolId)
{
m_nfToken.tokenProtocolId = StringToProtocolName(tokenProtocolId.get_str().c_str());
if (m_nfToken.tokenProtocolId == NfToken::UNKNOWN_TOKEN_PROTOCOL)
throw JSONRPCError(RPC_INVALID_PARAMETER, "NFT protocol ID contains invalid characters");
return *this;
}
......
......@@ -11,6 +11,7 @@
#include "platform/platform-utils.h"
#include "platform/rpc/specialtx-rpc-utils.h"
#include "nf-token-protocol-reg-tx.h"
#include "nf-token.h"
namespace Platform
{
......@@ -23,6 +24,8 @@ namespace Platform
if (nftProtoStr.size() < NfTokenProtocol::TOKEN_PROTOCOL_ID_MIN || nftProtoStr.size() > NfTokenProtocol::TOKEN_PROTOCOL_ID_MAX)
throw JSONRPCError(RPC_INVALID_PARAMETER, "NFT protocol ID must be between 3 and 12 symbols long");
m_nftProto.tokenProtocolId = StringToProtocolName(nftProtoStr.c_str());
if (m_nftProto.tokenProtocolId == NfToken::UNKNOWN_TOKEN_PROTOCOL)
throw JSONRPCError(RPC_INVALID_PARAMETER, "NFT protocol ID contains invalid characters");
return *this;
}
......
......@@ -11,6 +11,11 @@
namespace Platform
{
static bool IsValidSymbol(char c)
{
return (( c >= 'a' && c <= 'z' ) || ( c >= '1' && c <= '5' ) || c == '.');
}
/**
* Converts a base32 symbol into its binary representation, used by StringToProtocolName()
*
......@@ -40,13 +45,20 @@ namespace Platform
uint32_t len = 0;
while( str[len] ) ++len;
if (str[0] == '.' || (len > 1 && str[len - 1] == '.'))
return static_cast<uint64_t >(-1);
uint64_t value = 0;
for( uint32_t i = 0; i <= 12; ++i )
{
uint64_t c = 0;
if( i < len && i <= 12 )
c = uint64_t(CharToSymbol( str[i] ));
{
if (!IsValidSymbol(str[i]))
return static_cast<uint64_t >(-1);
c = uint64_t(CharToSymbol(str[i]));
}
if( i < 12 )
{
......
......@@ -199,8 +199,11 @@ List the most recent 20 NFT records
if (params.size() > 1)
{
std::string nftProtoIdStr = params[1].get_str();
if (nftProtoIdStr != "*")
if (nftProtoIdStr != "*") {
nftProtoId = StringToProtocolName(nftProtoIdStr.c_str());
if (nftProtoId == NfToken::UNKNOWN_TOKEN_PROTOCOL)
throw JSONRPCError(RPC_INVALID_PARAMETER, "NFT protocol ID contains invalid characters");
}
}
CKeyID filterKeyId;
......@@ -275,6 +278,8 @@ Examples:
GetNfTokenHelp();
uint64_t tokenProtocolId = StringToProtocolName(params[1].get_str().c_str());
if (tokenProtocolId == NfToken::UNKNOWN_TOKEN_PROTOCOL)
throw JSONRPCError(RPC_INVALID_PARAMETER, "NFT protocol ID contains invalid characters");
uint256 tokenId = ParseHashV(params[2].get_str(), "nfTokenId");
auto nftIndex = NfTokensManager::Instance().GetNfTokenIndex(tokenProtocolId, tokenId);
......@@ -340,6 +345,8 @@ Examples:
if (params.size() == 2)
{
uint64_t tokenProtocolId = StringToProtocolName(params[1].get_str().c_str());
if (tokenProtocolId == NfToken::UNKNOWN_TOKEN_PROTOCOL)
throw JSONRPCError(RPC_INVALID_PARAMETER, "NFT protocol ID contains invalid characters");
totalSupply = NfTokensManager::Instance().TotalSupply(tokenProtocolId);
}
else
......@@ -383,6 +390,8 @@ Display balance of "CRWS78Yf5kbWAyfcES6RfiTVzP87csPNhZzc" address
if (params.size() == 3)
{
uint64_t tokenProtocolId = StringToProtocolName(params[2].get_str().c_str());
if (tokenProtocolId == NfToken::UNKNOWN_TOKEN_PROTOCOL)
throw JSONRPCError(RPC_INVALID_PARAMETER, "NFT protocol ID contains invalid characters");
balance = NfTokensManager::Instance().BalanceOf(tokenProtocolId, filterKeyId);
}
else
......@@ -417,6 +426,8 @@ Examples:
NfTokenOwnerOfHelp();
uint64_t tokenProtocolId = StringToProtocolName(params[1].get_str().c_str());
if (tokenProtocolId == NfToken::UNKNOWN_TOKEN_PROTOCOL)
throw JSONRPCError(RPC_INVALID_PARAMETER, "NFT protocol ID contains invalid characters");
uint256 tokenId = ParseHashV(params[2].get_str(), "nfTokenId");
CKeyID ownerId = NfTokensManager::Instance().OwnerOf(tokenProtocolId, tokenId);
......
......@@ -293,6 +293,8 @@ Examples:
NftProtoOwnerOfHelp();
uint64_t tokenProtocolId = StringToProtocolName(params[1].get_str().c_str());
if (tokenProtocolId == NfToken::UNKNOWN_TOKEN_PROTOCOL)
throw JSONRPCError(RPC_INVALID_PARAMETER, "NFT protocol ID contains invalid characters");
CKeyID ownerId = NftProtocolsManager::Instance().OwnerOf(tokenProtocolId);
if (ownerId.IsNull())
......
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