Skip to content
This repository has been archived by the owner on Feb 21, 2019. It is now read-only.

Commit

Permalink
Merge branch 'devshares' into bitshares
Browse files Browse the repository at this point in the history
  • Loading branch information
vikramrajkumar committed Sep 9, 2015
2 parents cf0cd30 + d937bc8 commit 5b2385d
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 9 deletions.
10 changes: 8 additions & 2 deletions libraries/api/blockchain_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@
"aliases" : []
},
{
"method_name": "blockchain_generate_full_snapshot",
"description": "Save snapshot of current state to specified file",
"method_name": "blockchain_graphene_snapshot",
"description": "Save snapshot of current state to specified file in Graphene genesis format",
"return_type": "void",
"parameters" : [
{
"name" : "filename",
"type" : "string",
"description" : "filename to save snapshot to"
},
{
"name" : "whitelist_filename",
"type" : "string",
"description" : "filename containing set of account names to whitelist from name-prefixing",
"default_value" : ""
}
],
"is_const" : true,
Expand Down
59 changes: 56 additions & 3 deletions libraries/blockchain/chain_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3365,7 +3365,7 @@ namespace bts { namespace blockchain {
fc::json::save_to_file( snapshot, filename );
} FC_CAPTURE_AND_RETHROW( (filename) ) }

void chain_database::generate_full_snapshot( const string& filename )const
void chain_database::graphene_snapshot( const string& filename, const set<string>& whitelist )const
{ try {
snapshot_state snapshot;
snapshot.head_block = get_head_block();
Expand Down Expand Up @@ -3451,6 +3451,7 @@ namespace bts { namespace blockchain {
return;

auto& snapshot_account = snapshot.accounts[ record.name ];
snapshot_account.timestamp = record.registration_date;
snapshot_account.owner_key = record.owner_key;
snapshot_account.active_key = record.active_key();

Expand Down Expand Up @@ -3537,7 +3538,7 @@ namespace bts { namespace blockchain {
snapshot_asset.debts[ index.owner ].debt += collateral.payoff_balance;
}

// Rectify supply/debt differences
// Hack to rectify supply/debt differences for GOLD
for( auto& item : snapshot.assets )
{
const auto& symbol = item.first;
Expand Down Expand Up @@ -3668,13 +3669,65 @@ namespace bts { namespace blockchain {
genesis.initial_timestamp = snapshot.head_block.timestamp;
genesis.max_core_supply = snapshot.max_core_supply;

const auto is_cheap_name = []( const string& n ) -> bool
{
bool v = false;
for( auto c : n )
{
if( c >= '0' && c <= '9' ) return true;
if( c == '.' || c == '-' || c == '/' ) return true;
switch( c )
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'y':
v = true;
}
}
if( !v )
return true;
return false;
};

static const auto june8 = time_point_sec( 1433736000 );
static const auto june18 = time_point_sec( 1434600000 );

// Accounts, witnesses, and workers
// TODO: Don't forget name modifications and blacklists
for( const auto& item : snapshot.accounts )
{
const string& name = item.first;
const string& original_name = item.first;
const snapshot_account& keys = item.second;

const auto prefix_name = [ & ]( const string& name ) -> string
{
string prefixed_name = "bts-" + name;
int count = 0;
while( snapshot.accounts.count( prefixed_name ) > 0 )
{
prefixed_name = "bts" + std::to_string( count ) + "-" + name;
++count;
}
return prefixed_name;
};

string name = original_name;
if( keys.timestamp >= june8 )
{
if( keys.timestamp >= june18 )
{
if( whitelist.count( name ) == 0 )
name = prefix_name( name );
}
else if( !is_cheap_name( name ) )
{
name = prefix_name( name );
}
}

genesis_state_type::initial_account_type account;
account.name = name;
account.owner_key = keys.owner_key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ namespace bts { namespace blockchain {
const address& owner );

void generate_snapshot( const fc::path& filename )const;
void generate_full_snapshot( const string& filename )const;
void graphene_snapshot( const string& filename, const set<string>& whitelist )const;
void generate_issuance_map( const string& symbol, const fc::path& filename )const;

unordered_map<asset_id_type, share_type> calculate_supplies()const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct snapshot_balance

struct snapshot_account
{
time_point_sec timestamp;
public_key_type owner_key;
public_key_type active_key;
optional<public_key_type> signing_key;
Expand Down Expand Up @@ -84,7 +85,7 @@ FC_REFLECT( bts::blockchain::snapshot_summary, (num_balance_owners)(num_asset_ba
(num_mias)(num_collateral_positions)(num_uias))
FC_REFLECT( bts::blockchain::snapshot_vesting_balance, (start_time)(duration_seconds)(original_balance)(current_balance) )
FC_REFLECT( bts::blockchain::snapshot_balance, (assets)(vesting) )
FC_REFLECT( bts::blockchain::snapshot_account, (owner_key)(active_key)(signing_key)(daily_pay) )
FC_REFLECT( bts::blockchain::snapshot_account, (timestamp)(owner_key)(active_key)(signing_key)(daily_pay) )
FC_REFLECT( bts::blockchain::snapshot_debt, (collateral)(debt) )
FC_REFLECT( bts::blockchain::snapshot_asset, (owner)(description)(precision)(max_supply)(collected_fees)(debts) )
FC_REFLECT( bts::blockchain::snapshot_state, (head_block)(max_core_supply)(summary)(balances)(accounts)(assets) )
8 changes: 6 additions & 2 deletions libraries/client/blockchain_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,13 @@ void client_impl::blockchain_generate_snapshot( const string& filename )const
_chain_db->generate_snapshot( fc::path( filename ) );
} FC_CAPTURE_AND_RETHROW( (filename) ) }

void client_impl::blockchain_generate_full_snapshot( const string& filename )const
void client_impl::blockchain_graphene_snapshot( const string& filename, const string& whitelist_filename )const
{ try {
_chain_db->generate_full_snapshot( filename );
set<string> whitelist;
if( !whitelist_filename.empty() )
whitelist = fc::json::from_file<std::set<string>>( whitelist_filename );

_chain_db->graphene_snapshot( filename, whitelist );
} FC_CAPTURE_AND_RETHROW( (filename) ) }

void client_impl::blockchain_generate_issuance_map( const string& symbol, const string& filename )const
Expand Down

0 comments on commit 5b2385d

Please sign in to comment.