Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/assets/assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ bool IsAssetNameASubasset(const std::string& name)
return parts.size() > 1;
}

bool IsAssetNameValid(const std::string& name, AssetType& assetType)
bool IsAssetNameValid(const std::string& name, assettype::AssetType& assetType)
{
assetType = INVALID;
assetType = assettype::AssetType::INVALID;
if (std::regex_match(name, UNIQUE_INDICATOR))
{
if (name.size() > MAX_NAME_LENGTH) return false;
std::vector<std::string> parts;
boost::split(parts, name, boost::is_any_of(UNIQUE_TAG_DELIMITER));
bool valid = IsNameValidBeforeTag(parts.front()) && IsUniqueTagValid(parts.back());
if (!valid) return false;
assetType = AssetType::UNIQUE;
assetType = assettype::AssetType::UNIQUE;
return true;
}
else if (std::regex_match(name, CHANNEL_INDICATOR))
Expand All @@ -128,30 +128,30 @@ bool IsAssetNameValid(const std::string& name, AssetType& assetType)
boost::split(parts, name, boost::is_any_of(CHANNEL_TAG_DELIMITER));
bool valid = IsNameValidBeforeTag(parts.front()) && IsChannelTagValid(parts.back());
if (!valid) return false;
assetType = AssetType::CHANNEL;
assetType = assettype::AssetType::CHANNEL;
return true;
}
else if (std::regex_match(name, OWNER_INDICATOR))
{
if (name.size() > MAX_NAME_LENGTH + 1) return false;
bool valid = IsNameValidBeforeTag(name.substr(0, name.size() - 1));
if (!valid) return false;
assetType = AssetType::OWNER;
assetType = assettype::AssetType::OWNER;
return true;
}
else
{
if (name.size() > MAX_NAME_LENGTH) return false;
bool valid = IsNameValidBeforeTag(name);
if (!valid) return false;
assetType = IsAssetNameASubasset(name) ? AssetType::SUB : AssetType::ROOT;
assetType = IsAssetNameASubasset(name) ? assettype::AssetType::SUB : assettype::AssetType::ROOT;
return true;
}
}

bool IsAssetNameValid(const std::string& name)
{
AssetType _assetType;
assettype::AssetType _assetType;
return IsAssetNameValid(name, _assetType);
}

Expand Down Expand Up @@ -2186,4 +2186,4 @@ bool SendAssetTransaction(CWallet* pwallet, CWalletTx& transaction, CReserveKey&
}
txid = transaction.GetHash().GetHex();
return true;
}
}
24 changes: 13 additions & 11 deletions src/assets/assets.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@ struct CAssetOutputEntry;
// 50000 * 82 Bytes == 4.1 Mb
#define MAX_CACHE_ASSETS_SIZE 50000

enum AssetType
{
ROOT,
OWNER,
SUB,
UNIQUE,
CHANNEL,
VOTE,
INVALID
};
namespace assettype {
enum AssetType
{
ROOT,
OWNER,
SUB,
UNIQUE,
CHANNEL,
VOTE,
INVALID
};
}

class CAssets {
public:
Expand Down Expand Up @@ -311,7 +313,7 @@ CAmount GetIssueSubAssetBurnAmount();
CAmount GetIssueUniqueAssetBurnAmount();

bool IsAssetNameValid(const std::string& name);
bool IsAssetNameValid(const std::string& name, AssetType& assetType);
bool IsAssetNameValid(const std::string& name, assettype::AssetType& assetType);
bool IsAssetNameAnOwner(const std::string& name);

bool IsAssetNameSizeValid(const std::string& name);
Expand Down
14 changes: 7 additions & 7 deletions src/test/assets/asset_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ BOOST_FIXTURE_TEST_SUITE(asset_tests, BasicTestingSetup)
}

BOOST_AUTO_TEST_CASE(name_validation_tests) {
AssetType type;
assettype::AssetType type;

// regular
BOOST_CHECK(IsAssetNameValid("MIN", type));
BOOST_CHECK(type == AssetType::ROOT);
BOOST_CHECK(type == assettype::AssetType::ROOT);
BOOST_CHECK(IsAssetNameValid("MAX_ASSET_IS_30_CHARACTERS_LNG", type));
BOOST_CHECK(!IsAssetNameValid("MAX_ASSET_IS_31_CHARACTERS_LONG", type));
BOOST_CHECK(type == AssetType::INVALID);
BOOST_CHECK(type == assettype::AssetType::INVALID);
BOOST_CHECK(IsAssetNameValid("A_BCDEFGHIJKLMNOPQRSTUVWXY.Z", type));
BOOST_CHECK(IsAssetNameValid("0_12345678.9", type));

Expand Down Expand Up @@ -66,7 +66,7 @@ BOOST_FIXTURE_TEST_SUITE(asset_tests, BasicTestingSetup)

// subs
BOOST_CHECK(IsAssetNameValid("ABC/A", type));
BOOST_CHECK(type == AssetType::SUB);
BOOST_CHECK(type == assettype::AssetType::SUB);
BOOST_CHECK(IsAssetNameValid("ABC/A/1", type));
BOOST_CHECK(IsAssetNameValid("ABC/A_1/1.A", type));
BOOST_CHECK(IsAssetNameValid("ABC/AB/XYZ/STILL/MAX/30/123456", type));
Expand All @@ -89,7 +89,7 @@ BOOST_FIXTURE_TEST_SUITE(asset_tests, BasicTestingSetup)

// unique
BOOST_CHECK(IsAssetNameValid("ABC#AZaz09", type));
BOOST_CHECK(type == AssetType::UNIQUE);
BOOST_CHECK(type == assettype::AssetType::UNIQUE);
BOOST_CHECK(IsAssetNameValid("ABC#@$%&*()[]{}<>-_.;?\\:", type));
BOOST_CHECK(!IsAssetNameValid("ABC#no!bangs", type));
BOOST_CHECK(IsAssetNameValid("ABC/THING#_STILL_30_MAX------_", type));
Expand All @@ -103,7 +103,7 @@ BOOST_FIXTURE_TEST_SUITE(asset_tests, BasicTestingSetup)

// channel
BOOST_CHECK(IsAssetNameValid("ABC~1", type));
BOOST_CHECK(type == AssetType::CHANNEL);
BOOST_CHECK(type == assettype::AssetType::CHANNEL);
BOOST_CHECK(IsAssetNameValid("ABC~STILL_MAX_OF_30.CHARS_1234", type));

BOOST_CHECK(!IsAssetNameValid("MIN~", type));
Expand All @@ -127,7 +127,7 @@ BOOST_FIXTURE_TEST_SUITE(asset_tests, BasicTestingSetup)
BOOST_CHECK(IsAssetNameAnOwner("ABC/A!"));
BOOST_CHECK(IsAssetNameAnOwner("ABC/A/1!"));
BOOST_CHECK(IsAssetNameValid("ABC!", type));
BOOST_CHECK(type == AssetType::OWNER);
BOOST_CHECK(type == assettype::AssetType::OWNER);


}
Expand Down