Skip to content

Commit

Permalink
Fix #385 - HARDFORK to expand valid names
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemaster committed Oct 21, 2015
1 parent 3bc8832 commit ddd58e9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion libraries/chain/asset_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o
FC_ASSERT( asset_symbol_itr == asset_indx.end() );

auto dotpos = op.symbol.find( '.' );
if( dotpos != std::string::npos ) {
if( dotpos != std::string::npos && d.head_block_time() > HARDFORK_385_TIME ) {
auto prefix = op.symbol.substr( 0, dotpos );
auto asset_symbol_itr = asset_indx.find( op.symbol );
FC_ASSERT( asset_symbol_itr != asset_indx.end(), "Asset ${s} may only be created by issuer of ${p}, but ${p} has not been registered",
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/graphene/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define GRAPHENE_SYMBOL "BTS"
#define GRAPHENE_ADDRESS_PREFIX "BTS"

#define GRAPHENE_MIN_ACCOUNT_NAME_LENGTH 3
#define GRAPHENE_MIN_ACCOUNT_NAME_LENGTH 1
#define GRAPHENE_MAX_ACCOUNT_NAME_LENGTH 63

#define GRAPHENE_MIN_ASSET_SYMBOL_LENGTH 3
Expand Down
1 change: 1 addition & 0 deletions libraries/chain/include/graphene/chain/hardfork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@

#define HARDFORK_357_TIME (fc::time_point_sec( 1444416300 ))
#define HARDFORK_359_TIME (fc::time_point_sec( 1444416300 ))
#define HARDFORK_385_TIME (fc::time_point_sec( 1445558400 )) // October 23 enforce PARENT.CHILD and allow short names
31 changes: 24 additions & 7 deletions libraries/chain/protocol/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
*/
#include <graphene/chain/protocol/account.hpp>
#include <graphene/chain/hardfork.hpp>

namespace graphene { namespace chain {

Expand Down Expand Up @@ -53,26 +54,39 @@ namespace graphene { namespace chain {
* - Length is between (inclusive) GRAPHENE_MIN_ACCOUNT_NAME_LENGTH and GRAPHENE_MAX_ACCOUNT_NAME_LENGTH
*/
bool is_valid_name( const string& name )
{
#if GRAPHENE_MIN_ACCOUNT_NAME_LENGTH < 3
#error This is_valid_name implementation implicitly enforces minimum name length of 3.
#endif

{ try {
const size_t len = name.size();

/** this condition will prevent witnesses from including new names before this time, but
* allow them after this time. This check can be removed from the code after HARDFORK_385_TIME
* has passed.
*/
if( fc::time_point::now() < fc::time_point(HARDFORK_385_TIME) )
FC_ASSERT( len >= 3 );

if( len < GRAPHENE_MIN_ACCOUNT_NAME_LENGTH )
{
ilog( ".");
return false;
}

if( len > GRAPHENE_MAX_ACCOUNT_NAME_LENGTH )
{
ilog( ".");
return false;
}

size_t begin = 0;
while( true )
{
size_t end = name.find_first_of( '.', begin );
if( end == std::string::npos )
end = len;
if( end - begin < 3 )
if( (end - begin) < GRAPHENE_MIN_ACCOUNT_NAME_LENGTH )
{
idump( (name) (end)(len)(begin)(GRAPHENE_MAX_ACCOUNT_NAME_LENGTH) );
return false;
}
switch( name[begin] )
{
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h':
Expand All @@ -81,6 +95,7 @@ bool is_valid_name( const string& name )
case 'y': case 'z':
break;
default:
ilog( ".");
return false;
}
switch( name[end-1] )
Expand All @@ -93,6 +108,7 @@ bool is_valid_name( const string& name )
case '8': case '9':
break;
default:
ilog( ".");
return false;
}
for( size_t i=begin+1; i<end-1; i++ )
Expand All @@ -108,6 +124,7 @@ bool is_valid_name( const string& name )
case '-':
break;
default:
ilog( ".");
return false;
}
}
Expand All @@ -116,7 +133,7 @@ bool is_valid_name( const string& name )
begin = end+1;
}
return true;
}
} FC_CAPTURE_AND_RETHROW( (name) ) }

bool is_cheap_name( const string& n )
{
Expand Down

0 comments on commit ddd58e9

Please sign in to comment.