<commit_before>#include <bts/blockchain/chain_interface.hpp>
#include <bts/blockchain/exceptions.hpp>
#include <fc/io/raw_variant.hpp>

#include <algorithm>
#include <locale>

namespace bts { namespace blockchain {

   optional<string> chain_interface::get_parent_account_name( const string& account_name )const
   {
      const size_t pos = account_name.find( '.' );
      if( pos != string::npos )
          return account_name.substr( pos + 1 );
      return optional<string>();
   }

   bool chain_interface::is_valid_account_name( const string& name )const
   { try {
      if( name.size() < BTS_BLOCKCHAIN_MIN_NAME_SIZE ) return false;
      if( name.size() > BTS_BLOCKCHAIN_MAX_NAME_SIZE ) return false;
      if( !isalpha(name[0]) ) return false;
      if ( !isalnum(name[name.size()-1]) || isupper(name[name.size()-1]) ) return false;

      string subname(name);
      string supername;
      int dot = name.find('.');
      if( dot != string::npos )
      {
        subname = name.substr(0, dot);
        //There is definitely a remainder; we checked above that the last character is not a dot
        supername = name.substr(dot+1);
      }

      if ( !isalnum(subname[subname.size()-1]) || isupper(subname[subname.size()-1]) ) return false;
      for( const auto& c : subname )
      {
          if( isalnum(c) && !isupper(c) ) continue;
          else if( c == '-' ) continue;
          else return false;
      }

      if( supername.empty() )
        return true;
      return is_valid_account_name(supername);
   } FC_CAPTURE_AND_RETHROW( (name) ) }

   /**
    *  Symbol names must be Alpha Numeric and may have a single '.' in the name that cannot be
    *  the first or last.
    */
   bool chain_interface::is_valid_symbol_name( const string& symbol )const
   { try {

       int dots = 0;
       int sub_symbol_size = 0;
       for( const char& c : symbol )
       {
           sub_symbol_size++;
           ulog("char is: ${c}, count is: ${s}", ("c", std::string(1, c))("s", sub_symbol_size));
           if( c == '.' )
           {
              if( sub_symbol_size < BTS_BLOCKCHAIN_MIN_SYMBOL_SIZE
                 || sub_symbol_size > BTS_BLOCKCHAIN_MAX_SYMBOL_SIZE )
                 return false;
              sub_symbol_size = 0;
              ulog("it's a dot, resetting subsize to 0");

              if( ++dots > 1 )
                 return false;
           }
           else
           {
               if( !std::isalnum( c, std::locale::classic() ) || !std::isupper( c, std::locale::classic() ) )
                   return false;
              ulog("it's not a dot and passes basic test");
           }
       }
       if( symbol.back() == '.' ) return false;
       if( symbol.front() == '.' ) return false;

       if( symbol.size() >= 3 && symbol.find( "BIT" ) == 0 )
           return false;

       return true;
   } FC_CAPTURE_AND_RETHROW( (symbol) ) }

   // Starting 2014-11-06, delegates are issued max 50 shares per block produced, and this value is halved every 4 years
   // just like in Bitcoin
   share_type chain_interface::get_max_delegate_pay_issued_per_block()const<commit_msg>fix #1181 and remove logging<commit_after>#include <bts/blockchain/chain_interface.hpp>
#include <bts/blockchain/exceptions.hpp>
#include <fc/io/raw_variant.hpp>

#include <algorithm>
#include <locale>

namespace bts { namespace blockchain {

   optional<string> chain_interface::get_parent_account_name( const string& account_name )const
   {
      const size_t pos = account_name.find( '.' );
      if( pos != string::npos )
          return account_name.substr( pos + 1 );
      return optional<string>();
   }

   bool chain_interface::is_valid_account_name( const string& name )const
   { try {
      if( name.size() < BTS_BLOCKCHAIN_MIN_NAME_SIZE ) return false;
      if( name.size() > BTS_BLOCKCHAIN_MAX_NAME_SIZE ) return false;
      if( !isalpha(name[0]) ) return false;
      if ( !isalnum(name[name.size()-1]) || isupper(name[name.size()-1]) ) return false;

      string subname(name);
      string supername;
      int dot = name.find('.');
      if( dot != string::npos )
      {
        subname = name.substr(0, dot);
        //There is definitely a remainder; we checked above that the last character is not a dot
        supername = name.substr(dot+1);
      }

      if ( !isalnum(subname[subname.size()-1]) || isupper(subname[subname.size()-1]) ) return false;
      for( const auto& c : subname )
      {
          if( isalnum(c) && !isupper(c) ) continue;
          else if( c == '-' ) continue;
          else return false;
      }

      if( supername.empty() )
        return true;
      return is_valid_account_name(supername);
   } FC_CAPTURE_AND_RETHROW( (name) ) }

   /**
    *  Symbol names must be Alpha Numeric and may have a single '.' in the name that cannot be
    *  the first or last.
    */
   bool chain_interface::is_valid_symbol_name( const string& symbol )const
   { try {

       int dots = 0;
       int sub_symbol_size = 0;
       for( const char& c : symbol )
       {
           sub_symbol_size++;
           if( c == '.' )
           {
              if( sub_symbol_size < BTS_BLOCKCHAIN_MIN_SYMBOL_SIZE
                 || sub_symbol_size > BTS_BLOCKCHAIN_MAX_SYMBOL_SIZE )
                 return false;
              sub_symbol_size = 0;

              if( ++dots > 1 )
                 return false;
           }
           else
           {
               if( !std::isalnum( c, std::locale::classic() ) || !std::isupper( c, std::locale::classic() ) )
                   return false;
           }
       }
       if( sub_symbol_size < BTS_BLOCKCHAIN_MIN_SYMBOL_SIZE
          || sub_symbol_size > BTS_BLOCKCHAIN_MAX_SYMBOL_SIZE )
          return false;

       if( symbol.back() == '.' ) return false;
       if( symbol.front() == '.' ) return false;

       if( symbol.size() >= 3 && symbol.find( "BIT" ) == 0 )
           return false;

       return true;
   } FC_CAPTURE_AND_RETHROW( (symbol) ) }

   // Starting 2014-11-06, delegates are issued max 50 shares per block produced, and this value is halved every 4 years
   // just like in Bitcoin
   share_type chain_interface::get_max_delegate_pay_issued_per_block()const
{'fraction_non_alphanumeric': 0.12218287186091437, 'fraction_numerical': 0.00901481004507405, 'mean_word_length': 2.2665615141955837, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1774889', 'n_tokens_mistral': 2001, 'n_tokens_neox': 1932, 'n_words': 497}