<commit_before>#include <bts/blockchain/account_record.hpp>
#include <bts/blockchain/chain_interface.hpp>

namespace bts { namespace blockchain {

    share_type account_record::delegate_pay_balance()const
    {
        FC_ASSERT( is_delegate() );
        return delegate_info->pay_balance;
    }

    bool account_record::is_delegate()const
    {
        return delegate_info.valid();
    }

    int64_t account_record::net_votes()const
    {
        FC_ASSERT( is_delegate() );
        return delegate_info->votes_for;
    }

    void account_record::adjust_votes_for( const share_type delta )
    {
        FC_ASSERT( is_delegate() );
        delegate_info->votes_for += delta;
    }

    bool account_record::is_retracted()const
    {
        return active_key() == public_key_type();
    }

    address account_record::active_address()const
    {
        return address( active_key() );
    }

    void account_record::set_active_key( const time_point_sec now, const public_key_type& new_key )
    { try {
        FC_ASSERT( now != fc::time_point_sec() );
        active_key_history[ now ] = new_key;
    } FC_CAPTURE_AND_RETHROW( (now)(new_key) ) }

    public_key_type account_record::active_key()const
    {
        if( active_key_history.empty() )
            return public_key_type();

        return active_key_history.rbegin()->second;
    }

    uint8_t account_record::delegate_pay_rate()const
    {
        if( !is_delegate() )
            return -1;

        return delegate_info->pay_rate;
    }

    void account_record::set_signing_key( uint32_t block_num, const public_key_type& signing_key )
    {
        FC_ASSERT( is_delegate() );
        delegate_info->signing_key_history[ block_num ] = signing_key;
    }

    public_key_type account_record::signing_key()const
    {
        FC_ASSERT( is_delegate() );
        FC_ASSERT( !delegate_info->signing_key_history.empty() );
        return delegate_info->signing_key_history.crbegin()->second;
    }

    address account_record::signing_address()const
    {
        return address( signing_key() );
    }

    public_key_type burn_record_value::signer_key()const
    {
       FC_ASSERT( signer.valid() );
       fc::sha256 digest;
       if( message.size() )
          digest = fc::sha256::hash( message.c_str(), message.size() );
       return fc::ecc::public_key( *signer, digest );
    }

    const account_db_interface& account_record::db_interface( const chain_interface& db )
    { try {
        return db._account_db_interface;
    } FC_CAPTURE_AND_RETHROW() }

    void account_record::sanity_check( const chain_interface& db )const
    { try {
        FC_ASSERT( id > 0 );
        FC_ASSERT( !name.empty() );
        if( delegate_info.valid() )
        {
            FC_ASSERT( delegate_info->votes_for >= 0 );
            FC_ASSERT( delegate_info->pay_rate <= 100 );
            FC_ASSERT( !delegate_info->signing_key_history.empty() );
            FC_ASSERT( delegate_info->pay_balance >= 0 );
        }
    } FC_CAPTURE_AND_RETHROW( (*this) ) }

    oaccount_record account_db_interface::lookup( const account_id_type id )const
    { try {
        return lookup_by_id( id );
    } FC_CAPTURE_AND_RETHROW( (id) ) }

    oaccount_record account_db_interface::lookup( const string& name )const
    { try {<commit_msg>Tweak account_record invariants<commit_after>#include <bts/blockchain/account_record.hpp>
#include <bts/blockchain/chain_interface.hpp>

namespace bts { namespace blockchain {

    share_type account_record::delegate_pay_balance()const
    {
        FC_ASSERT( is_delegate() );
        return delegate_info->pay_balance;
    }

    bool account_record::is_delegate()const
    {
        return delegate_info.valid();
    }

    int64_t account_record::net_votes()const
    {
        FC_ASSERT( is_delegate() );
        return delegate_info->votes_for;
    }

    void account_record::adjust_votes_for( const share_type delta )
    {
        FC_ASSERT( is_delegate() );
        delegate_info->votes_for += delta;
    }

    bool account_record::is_retracted()const
    {
        return active_key() == public_key_type();
    }

    address account_record::active_address()const
    {
        return address( active_key() );
    }

    void account_record::set_active_key( const time_point_sec now, const public_key_type& new_key )
    { try {
        FC_ASSERT( now != fc::time_point_sec() );
        active_key_history[ now ] = new_key;
    } FC_CAPTURE_AND_RETHROW( (now)(new_key) ) }

    public_key_type account_record::active_key()const
    {
        FC_ASSERT( !active_key_history.empty() );
        return active_key_history.rbegin()->second;
    }

    uint8_t account_record::delegate_pay_rate()const
    {
        if( !is_delegate() )
            return -1;

        return delegate_info->pay_rate;
    }

    void account_record::set_signing_key( uint32_t block_num, const public_key_type& signing_key )
    {
        FC_ASSERT( is_delegate() );
        delegate_info->signing_key_history[ block_num ] = signing_key;
    }

    public_key_type account_record::signing_key()const
    {
        FC_ASSERT( is_delegate() );
        FC_ASSERT( !delegate_info->signing_key_history.empty() );
        return delegate_info->signing_key_history.crbegin()->second;
    }

    address account_record::signing_address()const
    {
        return address( signing_key() );
    }

    public_key_type burn_record_value::signer_key()const
    {
       FC_ASSERT( signer.valid() );
       fc::sha256 digest;
       if( message.size() )
          digest = fc::sha256::hash( message.c_str(), message.size() );
       return fc::ecc::public_key( *signer, digest );
    }

    const account_db_interface& account_record::db_interface( const chain_interface& db )
    { try {
        return db._account_db_interface;
    } FC_CAPTURE_AND_RETHROW() }

    void account_record::sanity_check( const chain_interface& db )const
    { try {
        FC_ASSERT( id > 0 );
        FC_ASSERT( !name.empty() );
        FC_ASSERT( !active_key_history.empty() );
        if( delegate_info.valid() )
        {
            FC_ASSERT( delegate_info->votes_for >= 0 );
            FC_ASSERT( delegate_info->pay_rate <= 100 );
            FC_ASSERT( !delegate_info->signing_key_history.empty() );
            FC_ASSERT( delegate_info->pay_balance >= 0 );
        }
    } FC_CAPTURE_AND_RETHROW( (*this) ) }

    oaccount_record account_db_interface::lookup( const account_id_type id )const
    { try {
        return lookup_by_id( id );
    } FC_CAPTURE_AND_RETHROW( (id) ) }

    oaccount_record account_db_interface::lookup( const string& name )const
    { try {
{'fraction_non_alphanumeric': 0.1094692400482509, 'fraction_numerical': 0.005428226779252111, 'mean_word_length': 2.9155844155844157, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 39, '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': '6874115', 'n_tokens_mistral': 2169, 'n_tokens_neox': 2099, 'n_words': 348}