Skip to content

Commit 4593532

Browse files
artem-bvwalkjivefly
artem-bv
authored andcommitted
add name and id min size check, issue bitcoin#354
(cherry picked from commit c4e6041)
1 parent 802bee3 commit 4593532

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/platform/nf-token/nf-token-protocol-reg-tx.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ namespace Platform
3636
if (nftProto.nftRegSign < static_cast<uint8_t>(NftRegSignMin) || nftProto.nftRegSign > static_cast<uint8_t>(NftRegSignMax))
3737
return state.DoS(10, false, REJECT_INVALID, "bad-nft-proto-reg-tx-reg-sign");
3838

39-
if (nftProto.tokenProtocolName.size() > NfTokenProtocol::TOKEN_PROTOCOL_NAME_MAX)
39+
if (nftProto.tokenProtocolName.size() < NfTokenProtocol::TOKEN_PROTOCOL_NAME_MIN
40+
|| nftProto.tokenProtocolName.size() > NfTokenProtocol::TOKEN_PROTOCOL_NAME_MAX)
4041
return state.DoS(10, false, REJECT_INVALID, "bad-nft-proto-reg-tx-proto-name");
4142

4243
if (nftProto.tokenMetadataMimeType.size() > NfTokenProtocol::TOKEN_METADATA_MIMETYPE_MAX)

src/platform/nf-token/nf-token-protocol.h

+2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ namespace Platform
5757
CKeyID tokenProtocolOwnerId;
5858
//TODO: add admin key to the protocol structure. add option to use setup admin key rights including tranfering ownership
5959

60+
static const unsigned TOKEN_PROTOCOL_ID_MIN = 3;
6061
static const unsigned TOKEN_PROTOCOL_ID_MAX = 12;
62+
static const unsigned TOKEN_PROTOCOL_NAME_MIN = 3;
6163
static const unsigned TOKEN_PROTOCOL_NAME_MAX = 24;
6264
static const unsigned TOKEN_METADATA_SCHEMA_URI_MAX = 128;
6365
static const unsigned TOKEN_METADATA_MIMETYPE_MAX = 32;

src/platform/nf-token/nft-protocol-reg-tx-builder.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@ namespace Platform
2020
NftProtocolRegTxBuilder & SetTokenProtocol(const json_spirit::Value & tokenProtocolId)
2121
{
2222
auto nftProtoStr = tokenProtocolId.get_str();
23-
if (nftProtoStr.size() > NfTokenProtocol::TOKEN_PROTOCOL_ID_MAX)
24-
throw JSONRPCError(RPC_INVALID_PARAMETER, "NFT protocol ID is longer than permitted");
23+
if (nftProtoStr.size() < NfTokenProtocol::TOKEN_PROTOCOL_ID_MIN || nftProtoStr.size() > NfTokenProtocol::TOKEN_PROTOCOL_ID_MAX)
24+
throw JSONRPCError(RPC_INVALID_PARAMETER, "NFT protocol ID must be between 3 and 12 symbols long");
2525
m_nftProto.tokenProtocolId = StringToProtocolName(nftProtoStr.c_str());
2626
return *this;
2727
}
2828

2929
NftProtocolRegTxBuilder & SetTokenProtocolName(const json_spirit::Value & tokenProtocolName)
3030
{
3131
m_nftProto.tokenProtocolName = tokenProtocolName.get_str();
32-
if (m_nftProto.tokenProtocolName.size() > NfTokenProtocol::TOKEN_PROTOCOL_NAME_MAX)
33-
throw JSONRPCError(RPC_INVALID_PARAMETER, "NFT Protocol name is longer than permitted");
32+
if (m_nftProto.tokenProtocolName.size() < NfTokenProtocol::TOKEN_PROTOCOL_NAME_MIN
33+
|| m_nftProto.tokenProtocolName.size() > NfTokenProtocol::TOKEN_PROTOCOL_NAME_MAX)
34+
throw JSONRPCError(RPC_INVALID_PARAMETER, "NFT Protocol name must be between 3 and 24 symbols long");
3435
return *this;
3536
}
3637

0 commit comments

Comments
 (0)