Clean up is_valid_symbol

This commit is contained in:
Vikram Rajkumar 2015-06-29 11:46:36 -04:00
parent 52d34cc978
commit 605824952c
2 changed files with 29 additions and 14 deletions

View file

@ -19,8 +19,12 @@
#define GRAPHENE_SYMBOL "CORE"
#define GRAPHENE_ADDRESS_PREFIX "GPH"
#define GRAPHENE_MAX_SYMBOL_NAME_LENGTH 16
#define GRAPHENE_MIN_SYMBOL_NAME_LENGTH 3
#define GRAPHENE_MAX_SYMBOL_NAME_LENGTH 17
#define GRAPHENE_MAX_ASSET_NAME_LENGTH 127
#define GRAPHENE_MAX_SHARE_SUPPLY int64_t(1000000000000ll)
#define GRAPHENE_MAX_PAY_RATE 10000 /* 100% */
#define GRAPHENE_MAX_SIG_CHECK_DEPTH 2

View file

@ -23,22 +23,33 @@
namespace graphene { namespace chain {
/**
* Valid symbols have between 3 and 17 upper case characters
* with at most a single "." that is not the first or last character.
* Valid symbols have at most a single "." that is not the first or last character.
*/
bool is_valid_symbol( const string& symbol )
{
if( symbol.size() > 17 ) return false;
if( symbol.size() < 3 ) return false;
int dot_count = 0;
for( auto c : symbol )
{
if( c == '.' ) ++dot_count;
else if( c < 'A' || c > 'Z' ) return false;
}
if( symbol[0] == '.' || symbol[symbol.size()-1] == '.' )
return false;
return dot_count <= 1;
if( symbol.size() < GRAPHENE_MIN_SYMBOL_NAME_LENGTH || symbol.size() > GRAPHENE_MAX_SYMBOL_NAME_LENGTH )
return false;
if( symbol.front() == '.' || symbol.back() == '.' )
return false;
bool dot_already_present = false;
for( const auto c : symbol )
{
if( c == '.' )
{
if( dot_already_present )
return false;
dot_already_present = true;
}
else if( !isalpha( c ) || !isupper( c ) )
{
return false;
}
}
return true;
}
/**