HARDFORK Allow digits in asset name; fix #359

This commit is contained in:
theoreticalbts 2015-10-08 14:59:43 -04:00
parent 0106a896dc
commit 9b910ee1a4
4 changed files with 75 additions and 2 deletions

View file

@ -21,14 +21,64 @@
#include <graphene/chain/market_evaluator.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/exceptions.hpp>
#include <graphene/chain/hardfork.hpp>
#include <functional>
namespace graphene { namespace chain {
/**
* Valid symbols can contain [A-Z0-9], and '.'
* They must start with [A, Z]
* They must end with [A, Z]
* They can contain a maximum of one '.'
*/
bool is_valid_symbol_old( const string& symbol )
{
if( symbol.size() < GRAPHENE_MIN_ASSET_SYMBOL_LENGTH )
return false;
if( symbol.size() > GRAPHENE_MAX_ASSET_SYMBOL_LENGTH )
return false;
if( !isalpha( symbol.front() ) )
return false;
if( !isalpha( symbol.back() ) )
return false;
bool dot_already_present = false;
for( const auto c : symbol )
{
if( (isalpha( c ) || isdigit(c)) && isupper( c ) )
continue;
if( c == '.' )
{
if( dot_already_present )
return false;
dot_already_present = true;
continue;
}
return false;
}
return true;
}
void_result asset_create_evaluator::do_evaluate( const asset_create_operation& op )
{ try {
database& d = db();
#warning HARDFORK remove this check after HARDFORK_359_TIME and rename is_valid_symbol_old -> is_valid_symbol
if( d.head_block_time() <= HARDFORK_359_TIME )
{
FC_ASSERT( is_valid_symbol_old( op.symbol ) );
}
const auto& chain_parameters = d.get_global_properties().parameters;
FC_ASSERT( op.common_options.whitelist_authorities.size() <= chain_parameters.maximum_asset_whitelist_authorities );
FC_ASSERT( op.common_options.blacklist_authorities.size() <= chain_parameters.maximum_asset_whitelist_authorities );

View file

@ -0,0 +1,20 @@
/*
* Copyright (c) 2015, Cryptonomex, Inc.
* All rights reserved.
*
* This source code is provided for evaluation in private test networks only, until September 8, 2015. After this date, this license expires and
* the code may not be used, modified or distributed for any purpose. Redistribution and use in source and binary forms, with or without modification,
* are permitted until September 8, 2015, provided that the following conditions are met:
*
* 1. The code and/or derivative works are used only for private test networks consisting of no more than 10 P2P nodes.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#define HARDFORK_359_TIME (fc::time_point_sec( 1444416300 ))

View file

@ -25,7 +25,7 @@ bool is_valid_symbol( const string& symbol )
bool dot_already_present = false;
for( const auto c : symbol )
{
if( (isalpha( c ) || isdigit(c)) && isupper( c ) )
if( (isalpha( c ) && isupper( c )) || isdigit(c) )
continue;
if( c == '.' )
@ -42,6 +42,7 @@ bool is_valid_symbol( const string& symbol )
return true;
}
share_type asset_issue_operation::calculate_fee(const fee_parameters_type& k)const
{
return k.fee + calculate_data_fee( fc::raw::pack_size(memo), k.price_per_kbyte );

View file

@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE( valid_symbol_test )
BOOST_CHECK( is_valid_symbol( "AAA" ) );
BOOST_CHECK( !is_valid_symbol( "AaA" ) );
BOOST_CHECK( !is_valid_symbol( "A0A" ) );
BOOST_CHECK( is_valid_symbol( "A0A" ) );
BOOST_CHECK( is_valid_symbol( "A.A" ) );
BOOST_CHECK( !is_valid_symbol( "A..A" ) );
@ -126,6 +126,8 @@ BOOST_AUTO_TEST_CASE( valid_symbol_test )
BOOST_CHECK( !is_valid_symbol( "AAAAAAAAAAAAAAAAA" ) );
BOOST_CHECK( is_valid_symbol( "A.AAAAAAAAAAAAAA" ) );
BOOST_CHECK( !is_valid_symbol( "A.AAAAAAAAAAAA.A" ) );
BOOST_CHECK( is_valid_symbol( "AAA000AAA" ) );
}
BOOST_AUTO_TEST_CASE( price_test )