From 605824952c86006fad36116ffc7dc25558206749 Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Mon, 29 Jun 2015 11:46:36 -0400 Subject: [PATCH] Clean up is_valid_symbol --- .../chain/include/graphene/chain/config.hpp | 6 ++- libraries/chain/operations.cpp | 37 ++++++++++++------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index b1e181b2..e31eead5 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -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 diff --git a/libraries/chain/operations.cpp b/libraries/chain/operations.cpp index 3a9029e0..598c7539 100644 --- a/libraries/chain/operations.cpp +++ b/libraries/chain/operations.cpp @@ -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; } /**