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

Commit

Permalink
Include labels for other withdraw types for scanning; #845
Browse files Browse the repository at this point in the history
  • Loading branch information
vikramrajkumar committed Dec 9, 2014
1 parent 321d5d0 commit 8a7324f
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 91 deletions.
10 changes: 0 additions & 10 deletions libraries/blockchain/balance_record.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <bts/blockchain/balance_record.hpp>
#include <boost/algorithm/string.hpp>

namespace bts { namespace blockchain {

Expand All @@ -9,15 +8,6 @@ namespace bts { namespace blockchain {
condition = withdraw_condition( withdraw_with_signature( owner ), balance_arg.asset_id, delegate_id );
}

string balance_record::small_id()const
{
string type_prefix = string( this->condition.type );
type_prefix = type_prefix.substr( 9 );
type_prefix = type_prefix.substr( 0, type_prefix.find( "_" ) );
boost::to_upper( type_prefix );
return type_prefix + "-" + string( this->id() ).substr( string( BTS_ADDRESS_PREFIX ).size(), 8 );
}

// TODO: deprecate?
address balance_record::owner()const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ namespace bts { namespace blockchain {
balance_record make_null()const { balance_record cpy(*this); cpy.balance = 0; return cpy; }

balance_id_type id()const { return condition.get_address(); }
string small_id()const;
slate_id_type slate_id()const { return condition.slate_id; }

address owner()const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace bts { namespace blockchain {
}

balance_id_type get_address()const;
string type_label()const;

asset_id_type asset_id;
slate_id_type slate_id = 0;
Expand Down
11 changes: 11 additions & 0 deletions libraries/blockchain/withdraw_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <fc/crypto/aes.hpp>
#include <fc/reflect/variant.hpp>

#include <boost/algorithm/string.hpp>

namespace bts { namespace blockchain {

const uint8_t withdraw_with_signature::type = withdraw_signature_type;
Expand Down Expand Up @@ -36,6 +38,15 @@ namespace bts { namespace blockchain {
return address( *this );
}

string withdraw_condition::type_label()const
{
string label = string( this->type );
label = label.substr( 9 );
label = label.substr( 0, label.find( "_" ) );
boost::to_upper( label );
return label;
}

omemo_status withdraw_with_signature::decrypt_memo_data( const fc::ecc::private_key& receiver_key, bool ignore_owner )const
{ try {
try {
Expand Down
18 changes: 9 additions & 9 deletions libraries/wallet/include/bts/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ namespace bts { namespace wallet {

enum delegate_status_flags
{
any_delegate_status = 0x00,
enabled_delegate_status = 0x01,
active_delegate_status = 0x02,
disabled_delegate_status = 0x04,
inactive_delegate_status = 0x08
any_delegate_status = 0,
enabled_delegate_status = 1 << 0,
active_delegate_status = 1 << 1,
disabled_delegate_status = 1 << 2,
inactive_delegate_status = 1 << 3
};

class wallet
Expand Down Expand Up @@ -179,7 +179,7 @@ namespace bts { namespace wallet {
void set_delegate_block_production( const string& delegate_id, bool enabled = true );

///@param delegates_to_retrieve Type is delegate_status_flags. Uses int type to allow ORing multiple flags
vector<wallet_account_record> get_my_delegates( int delegates_to_retrieve = any_delegate_status )const;
vector<wallet_account_record> get_my_delegates( uint32_t delegates_to_retrieve = any_delegate_status )const;

optional<time_point_sec> get_next_producible_block_timestamp( const vector<wallet_account_record>& delegate_records )const;

Expand Down Expand Up @@ -545,11 +545,11 @@ namespace bts { namespace wallet {
vector<escrow_summary> get_escrow_balances( const string& account_name );

account_balance_record_summary_type get_account_balance_records( const string& account_name = "", bool include_empty = true,
uint8_t withdraw_type_mask = 1 << uint8_t( withdraw_signature_type ) )const;
uint32_t withdraw_type_mask = 1 << uint8_t( withdraw_signature_type ) )const;
account_balance_id_summary_type get_account_balance_ids( const string& account_name = "", bool include_empty = true,
uint8_t withdraw_type_mask = 1 << uint8_t( withdraw_signature_type ) )const;
uint32_t withdraw_type_mask = 1 << uint8_t( withdraw_signature_type ) )const;
account_balance_summary_type get_account_balances( const string& account_name = "", bool include_empty = true,
uint8_t withdraw_type_mask = 1 << uint8_t( withdraw_signature_type ) )const;
uint32_t withdraw_type_mask = 1 << uint8_t( withdraw_signature_type ) )const;

account_balance_summary_type get_account_yield( const string& account_name = "" )const;
asset asset_worth( const asset& base, const string& price_in_symbol )const;
Expand Down
2 changes: 0 additions & 2 deletions libraries/wallet/include/bts/wallet/wallet_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ class wallet_impl : public chain_observer
bool overwrite_existing = false
);

void scan_genesis_experimental( const account_balance_record_summary_type& account_balances );

void scan_block_experimental( uint32_t block_num,
const map<private_key_type, string>& account_keys,
const map<address, string>& account_balances,
Expand Down
62 changes: 27 additions & 35 deletions libraries/wallet/transaction_ledger_experimental.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,6 @@
using namespace bts::wallet;
using namespace bts::wallet::detail;

void wallet_impl::scan_genesis_experimental( const account_balance_record_summary_type& account_balances )
{ try {
transaction_ledger_entry record;
record.id = fc::ripemd160::hash( string( "GENESIS" ) );
record.block_num = 0;
record.timestamp = _blockchain->get_genesis_timestamp();

for( const auto& item : account_balances )
{
const string& account_name = item.first;
for( const auto& balance_record : item.second )
{
if( !balance_record.snapshot_info.valid() )
continue;

const string& claim_addr = balance_record.snapshot_info->original_address;
const asset delta_amount = asset( balance_record.snapshot_info->original_balance, balance_record.condition.asset_id );
record.delta_amounts[ claim_addr ][ delta_amount.asset_id ] -= delta_amount.amount;
record.delta_amounts[ account_name ][ delta_amount.asset_id ] += delta_amount.amount;
}
}

record.operation_notes[ 0 ] = "import founder keys";

_wallet_db.experimental_transactions[ record.id ] = record; // TODO
} FC_CAPTURE_AND_RETHROW( (account_balances) ) }

void wallet_impl::scan_block_experimental( uint32_t block_num,
const map<private_key_type, string>& account_keys,
const map<address, string>& account_balances,
Expand Down Expand Up @@ -62,13 +35,35 @@ transaction_ledger_entry wallet_impl::scan_transaction_experimental( const trans
{ try {
const map<private_key_type, string> account_keys = _wallet_db.get_account_private_keys( _wallet_password );

// TODO: Move this into a separate function
map<address, string> account_balances;
const account_balance_id_summary_type balance_id_summary = self->get_account_balance_ids();
for( const auto& balance_item : balance_id_summary )
const account_balance_record_summary_type balance_record_summary = self->get_account_balance_records( "", true, -1 );
for( const auto& balance_item : balance_record_summary )
{
const string& account_name = balance_item.first;
for( const auto& balance_id : balance_item.second )
account_balances[ balance_id ] = account_name;
for( const auto& balance_record : balance_item.second )
{
const balance_id_type& balance_id = balance_record.id();
switch( withdraw_condition_types( balance_record.condition.type ) )
{
case withdraw_signature_type:
if( balance_record.snapshot_info.valid() )
account_balances[ balance_id ] = "GENESIS-" + balance_record.snapshot_info->original_address;
else
account_balances[ balance_id ] = account_name;
break;
case withdraw_vesting_type:
if( balance_record.snapshot_info.valid() )
{
account_balances[ balance_id ] = "SHAREDROP-" + balance_record.snapshot_info->original_address;
break;
}
// else fall through
default:
account_balances[ balance_id ] = balance_record.condition.type_label() + "-" + string( balance_id );
break;
}
}
}

set<string> account_names;
Expand Down Expand Up @@ -129,7 +124,6 @@ void wallet_impl::scan_transaction_experimental( const transaction_evaluation_st
// Used by scan_withdraw and scan_deposit below
const auto collect_balance = [&]( const balance_id_type& balance_id, const asset& delta_amount ) -> bool
{
// TODO: Handle other withdraw types by adding their small ids as values in account_balances outside
if( account_balances.count( balance_id ) > 0 ) // First check canonical labels
{
// TODO: Need to save balance labels locally before emptying them so they can be deleted from the chain
Expand All @@ -155,7 +149,6 @@ void wallet_impl::scan_transaction_experimental( const transaction_evaluation_st

const auto scan_withdraw = [&]( const withdraw_operation& op ) -> bool
{
// TODO: If withdrawing vesting balance, then set delta label appropriately and override account name
++withdrawal_count;
return collect_balance( op.balance_id, eval_state.deltas.at( op_index ) );
};
Expand Down Expand Up @@ -229,6 +222,7 @@ void wallet_impl::scan_transaction_experimental( const transaction_evaluation_st
{
case withdraw_signature_type:
return scan_withdraw_with_signature( op.condition.as<withdraw_with_signature>() );
// TODO: Other withdraw types
default:
break;
}
Expand Down Expand Up @@ -588,8 +582,6 @@ set<pretty_transaction_experimental> wallet::transaction_history_experimental( c
FC_ASSERT( is_open() );
FC_ASSERT( is_unlocked() );

my->scan_genesis_experimental( get_account_balance_records() );

set<pretty_transaction_experimental> history;

const auto& transactions = my->_wallet_db.get_transactions();
Expand Down
41 changes: 7 additions & 34 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,6 @@ namespace detail {
for( const auto& item : account_keys )
private_keys.push_back( item.first );

// Collect balances
map<address, string> account_balances;
const account_balance_id_summary_type balance_id_summary = self->get_account_balance_ids();
for( const auto& balance_item : balance_id_summary )
{
const string& account_name = balance_item.first;
for( const auto& balance_id : balance_item.second )
account_balances[ balance_id ] = account_name;
}

// Collect accounts
set<string> account_names;
const vector<wallet_account_record> accounts = self->list_my_accounts();
for( const wallet_account_record& account : accounts )
account_names.insert( account.name );

if( min_end > start + 1 )
ulog( "Beginning scan at block ${n}...", ("n",start) );

Expand All @@ -229,15 +213,6 @@ namespace detail {
{
}

#ifdef BTS_TEST_NETWORK
try
{
scan_block_experimental( block_num, account_keys, account_balances, account_names );
}
catch( ... )
{
}
#endif
_scan_progress = float(block_num-start)/(min_end-start+1);
self->set_last_scanned_block_number( block_num );

Expand Down Expand Up @@ -1446,9 +1421,6 @@ namespace detail {
if( start == 0 )
{
my->scan_state();
#ifdef BTS_TEST_NETWORK
my->scan_genesis_experimental( get_account_balance_records() );
#endif
++start;
}

Expand Down Expand Up @@ -1567,7 +1539,7 @@ namespace detail {
}
}

vector<wallet_account_record> wallet::get_my_delegates(int delegates_to_retrieve)const
vector<wallet_account_record> wallet::get_my_delegates( uint32_t delegates_to_retrieve )const
{
FC_ASSERT( is_open() );
vector<wallet_account_record> delegate_records;
Expand Down Expand Up @@ -4003,17 +3975,18 @@ namespace detail {
return result;
}

// TODO: Handle multiple owners
account_balance_record_summary_type wallet::get_account_balance_records( const string& account_name, bool include_empty,
uint8_t withdraw_type_mask )const
uint32_t withdraw_type_mask )const
{ try {
if( !is_open() )
FC_CAPTURE_AND_THROW( wallet_closed );
if( !is_open() ) FC_CAPTURE_AND_THROW( wallet_closed );

map<string, vector<balance_record>> balance_records;
const auto pending_state = my->_blockchain->get_pending_state();

const auto scan_balance = [&]( const balance_record& record )
{
if( record.snapshot_info.valid() && !((1 << uint8_t( withdraw_null_type )) & withdraw_type_mask) ) return;
if( !((1 << uint8_t( record.condition.type )) & withdraw_type_mask) ) return;

const auto key_record = my->_wallet_db.lookup_key( record.owner() );
Expand All @@ -4038,7 +4011,7 @@ namespace detail {
} FC_CAPTURE_AND_RETHROW( (account_name)(include_empty)(withdraw_type_mask) ) }

account_balance_id_summary_type wallet::get_account_balance_ids( const string& account_name, bool include_empty,
uint8_t withdraw_type_mask )const
uint32_t withdraw_type_mask )const
{ try {
map<string, vector<balance_id_type>> balance_ids;

Expand All @@ -4056,7 +4029,7 @@ namespace detail {
} FC_CAPTURE_AND_RETHROW( (account_name)(include_empty)(withdraw_type_mask) ) }

account_balance_summary_type wallet::get_account_balances( const string& account_name, bool include_empty,
uint8_t withdraw_type_mask )const
uint32_t withdraw_type_mask )const
{ try {
map<string, map<asset_id_type, share_type>> balances;

Expand Down

0 comments on commit 8a7324f

Please sign in to comment.