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

Commit

Permalink
Make delegate trust level a boolean (true for trusted)
Browse files Browse the repository at this point in the history
  • Loading branch information
vikramrajkumar committed Jun 25, 2014
1 parent ff873a2 commit 3d45435
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 73 deletions.
14 changes: 7 additions & 7 deletions libraries/api/ruby_generator/output/blockchain_api.coffee
Expand Up @@ -148,22 +148,22 @@ class BlockchainAPI
# parameters:
# asset_symbol `quote_symbol` - the symbol name the market is quoted in
# asset_symbol `base_symbol` - the item being bought in this market
# int64_t `limit` - the maximum number of items to return, -1 for all
# uint32_t `limit` - the maximum number of items to return, -1 for all
# return_type: `market_order_array`
market_list_bids: (quote_symbol, base_symbol, limit) ->
@rpc.request('blockchain_market_list_bids', [quote_symbol, base_symbol, limit]).then (response) ->
response.result

# returns the order of delegates that is fixed for the current round
# parameters:
# return_type: `account_id_array`
# return_type: `map<account_id_type, string>`
list_current_round_active_delegates: ->
@rpc.request('blockchain_list_current_round_active_delegates').then (response) ->
response.result

# Returns the block headers for blocks in a range
# Returns the block headers for blocks in a range in a reverse order, from the newest to oldest
# parameters:
# int32_t `first_block_number` - the first block to list
# int32_t `first_block_number` - the position of the first block relate to the head block, 0 is header block
# uint32_t `limit` - the maximum number of blocks to return
# return_type: `block_record_array`
list_blocks: (first_block_number, limit) ->
Expand All @@ -189,10 +189,10 @@ class BlockchainAPI

# Query the block production stats for a particular delegate
# parameters:
# account_id_type `delegate_id` - Delegate whose block stats to query
# string `delegate_name` - Delegate whose block stats to query
# return_type: `delegate_block_stats_map`
get_delegate_block_stats: (delegate_id) ->
@rpc.request('blockchain_get_delegate_block_stats', [delegate_id]).then (response) ->
get_delegate_block_stats: (delegate_name) ->
@rpc.request('blockchain_get_delegate_block_stats', [delegate_name]).then (response) ->
response.result

# Get the delegate that signed a given block
Expand Down
50 changes: 36 additions & 14 deletions libraries/api/ruby_generator/output/wallet_api.coffee
Expand Up @@ -189,13 +189,22 @@ class WalletAPI
@rpc.request('wallet_account_create', [account_name, private_data]).then (response) ->
response.result

# Updates the favorited status of the specified account
# parameters:
# account_name `account_name` - the name of the account to set favorited status on
# bool `is_favorite` - true if account should be marked as a favorite; false otherwise
# return_type: `void`
account_set_favorite: (account_name, is_favorite) ->
@rpc.request('wallet_account_set_favorite', [account_name, is_favorite]).then (response) ->
response.result

# Updates the trust placed in a given delegate
# parameters:
# account_name `delegate_name` - the name of the delegate to set trust level on
# int32_t `trust_level` - Positive for Trust, Negative for Distrust, 0 for Neutral
# account_name `delegate_name` - the name of the delegate to set trust on
# bool `trusted` - true for trusted and false for neutral
# return_type: `void`
set_delegate_trust_level: (delegate_name, trust_level) ->
@rpc.request('wallet_set_delegate_trust_level', [delegate_name, trust_level]).then (response) ->
set_delegate_trust: (delegate_name, trusted) ->
@rpc.request('wallet_set_delegate_trust', [delegate_name, trusted]).then (response) ->
response.result

# Add new account for sending payments
Expand Down Expand Up @@ -253,10 +262,10 @@ class WalletAPI
# account_name `account_name` - the account that will be updated
# account_name `pay_from_account` - the account from which fees will be paid
# json_variant `public_data` - public data about the account
# bool `as_delegate` - true if account_name should be upgraded to a delegate.
# uint32_t `delegate_pay_rate` - A value between 0 and 100% delegates, 255 for non delegates
# return_type: `transaction_record`
account_register: (account_name, pay_from_account, public_data, as_delegate) ->
@rpc.request('wallet_account_register', [account_name, pay_from_account, public_data, as_delegate]).then (response) ->
account_register: (account_name, pay_from_account, public_data, delegate_pay_rate) ->
@rpc.request('wallet_account_register', [account_name, pay_from_account, public_data, delegate_pay_rate]).then (response) ->
response.result

# Updates the local private data for an account
Expand All @@ -273,10 +282,9 @@ class WalletAPI
# account_name `account_name` - the account that will be updated
# account_name `pay_from_account` - the account from which fees will be paid
# json_variant `public_data` - public data about the account
# bool `as_delegate` - true if account_name should be upgraded to a delegate.
# return_type: `transaction_record`
account_update_registration: (account_name, pay_from_account, public_data, as_delegate) ->
@rpc.request('wallet_account_update_registration', [account_name, pay_from_account, public_data, as_delegate]).then (response) ->
account_update_registration: (account_name, pay_from_account, public_data) ->
@rpc.request('wallet_account_update_registration', [account_name, pay_from_account, public_data]).then (response) ->
response.result

# Lists all accounts associated with this wallet
Expand All @@ -286,6 +294,20 @@ class WalletAPI
@rpc.request('wallet_list_accounts').then (response) ->
response.result

# Lists all accounts which have been marked as favorites.
# parameters:
# return_type: `wallet_account_record_array`
list_favorite_accounts: ->
@rpc.request('wallet_list_favorite_accounts').then (response) ->
response.result

# Lists all unregistered accounts belonging to this wallet
# parameters:
# return_type: `wallet_account_record_array`
list_unregistered_accounts: ->
@rpc.request('wallet_list_unregistered_accounts').then (response) ->
response.result

# Lists all accounts for which we have a private key in this wallet
# parameters:
# return_type: `wallet_account_record_array`
Expand Down Expand Up @@ -391,9 +413,9 @@ class WalletAPI
@rpc.request('wallet_account_list_public_keys', [account_name]).then (response) ->
response.result

# Used to transfer some of the delegates pay from their balance
# Used to transfer some of the delegate's pay from their balance
# parameters:
# account_name `delegate_name` - the delegate who's pay is being cashed out
# account_name `delegate_name` - the delegate whose pay is being cashed out
# account_name `to_account_name` - the account that should receive the funds
# real_amount `amount_to_withdraw` - the amount to withdraw
# string `memo` - memo to add to transaction
Expand Down Expand Up @@ -483,8 +505,8 @@ class WalletAPI

# Enable or disable block production for a particular delegate account
# parameters:
# string `delegate_name` - The delegate to enable/disable block production for
# bool `enable` - True to enable block production, false otherwise
# string `delegate_name` - The delegate to enable/disable block production for; ALL for all delegate accounts
# bool `enable` - true to enable block production, false otherwise
# return_type: `void`
enable_delegate_block_production: (delegate_name, enable) ->
@rpc.request('wallet_enable_delegate_block_production', [delegate_name, enable]).then (response) ->
Expand Down
16 changes: 8 additions & 8 deletions libraries/api/wallet_api.json
Expand Up @@ -392,29 +392,29 @@
{
"name" : "is_favorite",
"type" : "bool",
"description" : "True if account should be marked as a favorite; false otherwise",
"description" : "true if account should be marked as a favorite; false otherwise",
"default_value" : true
}
],
"prerequisites" : ["wallet_open"],
"aliases" : [ "favor" ]
},
{
"method_name": "wallet_set_delegate_trust_level",
"method_name": "wallet_set_delegate_trust",
"description": "Updates the trust placed in a given delegate",
"return_type": "void",
"parameters" :
[
{
"name" : "delegate_name",
"type" : "account_name",
"description" : "the name of the delegate to set trust level on"
"description" : "the name of the delegate to set trust on"
},
{
"name" : "trust_level",
"type" : "int32_t",
"description" : "Positive for Trust, Negative for Distrust, 0 for Neutral",
"default_value" : 0
"name" : "trusted",
"type" : "bool",
"description" : "true for trusted and false for neutral",
"default_value" : false
}
],
"prerequisites" : ["wallet_open"],
Expand Down Expand Up @@ -1087,7 +1087,7 @@
{
"name" : "enable",
"type" : "bool",
"description" : "True to enable block production, false otherwise"
"description" : "true to enable block production, false otherwise"
}
],
"prerequisites" : ["wallet_open"]
Expand Down
13 changes: 6 additions & 7 deletions libraries/cli/cli.cpp
Expand Up @@ -1164,7 +1164,7 @@ namespace bts { namespace cli {
*_out << std::setw( 64 ) << "KEY";
*_out << std::setw( 22 ) << "REGISTERED";
*_out << std::setw( 15 ) << "FAVORITE";
*_out << std::setw( 15 ) << "TRUST LEVEL";
*_out << std::setw( 15 ) << "TRUSTED";
*_out << "\n";

for( auto acct : account_records )
Expand All @@ -1186,19 +1186,18 @@ namespace bts { namespace cli {
else
*_out << std::setw( 15 ) << "NO";

*_out << std::setw( 10) << acct.trust_level;
*_out << std::setw( 10) << acct.trusted;
*_out << "\n";
}
}


void print_receive_account_list(const vector<wallet_account_record>& account_records)
{
*_out << std::setw( 35 ) << std::left << "NAME (* delegate)";
*_out << std::setw( 64 ) << "KEY";
*_out << std::setw( 22 ) << "REGISTERED";
*_out << std::setw( 15 ) << "FAVORITE";
*_out << std::setw( 15 ) << "TRUST LEVEL";
*_out << std::setw( 15 ) << "TRUSTED";
*_out << std::setw( 25 ) << "BLOCK PRODUCTION ENABLED";
*_out << "\n";

Expand Down Expand Up @@ -1229,7 +1228,7 @@ namespace bts { namespace cli {
else
*_out << std::setw( 15 ) << "NO";

*_out << std::setw( 15 ) << acct.trust_level;
*_out << std::setw( 15 ) << acct.trusted;
if (acct.is_delegate())
*_out << std::setw( 25 ) << (acct.block_production_enabled ? "YES" : "NO");
else
Expand All @@ -1244,7 +1243,7 @@ namespace bts { namespace cli {
*_out << std::setw( 64 ) << "KEY";
*_out << std::setw( 22 ) << "REGISTERED";
*_out << std::setw( 15 ) << "VOTES FOR";
*_out << std::setw( 15 ) << "TRUST LEVEL";
*_out << std::setw( 15 ) << "TRUSTED";

*_out << "\n";
auto counter = 0;
Expand Down Expand Up @@ -1277,7 +1276,7 @@ namespace bts { namespace cli {
}
else
{
auto trust = _client->get_wallet()->get_delegate_trust_level( acct.name );
auto trust = _client->get_wallet()->get_delegate_trust( acct.name );
*_out << std::setw( 15 ) << trust;
}

Expand Down
18 changes: 6 additions & 12 deletions libraries/client/client.cpp
Expand Up @@ -1422,17 +1422,12 @@ config load_config( const fc::path& datadir )
return _chain_db->get_asset_record(asset_id);
}

void detail::client_impl::wallet_set_delegate_trust_level( const string& delegate_name,
int32_t user_trust_level)
{
try {
auto account_record = _chain_db->get_account_record(delegate_name);
FC_ASSERT(account_record.valid(), "delegate ${d} does not exist", ("d", delegate_name));
FC_ASSERT(account_record->is_delegate(), "${d} is not a delegate", ("d", delegate_name));

_wallet->set_delegate_trust_level(delegate_name, user_trust_level);
} FC_RETHROW_EXCEPTIONS(warn, "", ("delegate_name", delegate_name)("user_trust_level", user_trust_level))
}
void detail::client_impl::wallet_set_delegate_trust( const string& delegate_name, bool trusted )
{ try {
auto delegate_record = _chain_db->get_account_record( delegate_name );
FC_ASSERT( delegate_record.valid() && delegate_record->is_delegate() );
_wallet->set_delegate_trust( delegate_name, trusted );
} FC_RETHROW_EXCEPTIONS( warn, "", ("delegate_name",delegate_name)("trusted",trusted) ) }

/*
bts::wallet::delegate_trust_status client::wallet_get_delegate_trust_status(const string& delegate_name) const
Expand All @@ -1452,7 +1447,6 @@ config load_config( const fc::path& datadir )
}
*/


otransaction_record detail::client_impl::blockchain_get_transaction(const string& transaction_id, bool exact ) const
{
auto id = variant( transaction_id ).as<transaction_id_type>();
Expand Down
6 changes: 2 additions & 4 deletions libraries/wallet/include/bts/wallet/wallet.hpp
Expand Up @@ -336,10 +336,8 @@ namespace bts { namespace wallet {
pretty_transaction to_pretty_trx( const wallet_transaction_record& trx_rec ) const;


void set_delegate_trust_level(const string& delegate_name,
int32_t trust_level);

int32_t get_delegate_trust_level(const string& delegate_name) const;
void set_delegate_trust( const string& delegate_name, bool trusted );
bool get_delegate_trust( const string& delegate_name )const;

bool is_sending_address( const address& addr )const;
bool is_receive_address( const address& addr )const;
Expand Down
6 changes: 3 additions & 3 deletions libraries/wallet/include/bts/wallet/wallet_records.hpp
Expand Up @@ -81,7 +81,7 @@ namespace bts { namespace wallet {
struct account : public bts::blockchain::account_record
{
account()
:trust_level(0)
:trusted(false)
,block_production_enabled(false)
,is_my_account(false),is_favorite(false)
{}
Expand All @@ -100,7 +100,7 @@ namespace bts { namespace wallet {
* The assumption is that if the delegate is in the
* users wallet then they are a potential canidate.
*/
int32_t trust_level;
bool trusted;

bool block_production_enabled;
bool is_my_account;
Expand Down Expand Up @@ -251,7 +251,7 @@ FC_REFLECT( bts::wallet::transaction_data,
(received_time)
(block_num)
(transmit_count) )
FC_REFLECT_DERIVED( bts::wallet::account, (bts::blockchain::account_record), (account_address)(trust_level)(block_production_enabled)(private_data)(is_my_account)(is_favorite) )
FC_REFLECT_DERIVED( bts::wallet::account, (bts::blockchain::account_record), (account_address)(trusted)(block_production_enabled)(private_data)(is_my_account)(is_favorite) )

FC_REFLECT( bts::wallet::market_order_status, (order)(proceeds)(transactions) )
FC_REFLECT( bts::wallet::setting, (name)(value) )
Expand Down
33 changes: 15 additions & 18 deletions libraries/wallet/wallet.cpp
Expand Up @@ -3022,22 +3022,22 @@ namespace bts { namespace wallet {
} FC_RETHROW_EXCEPTIONS( warn, "", ("account_name",account_name) ) }

/**
* Randomly select a slate of delegates from those supported by this wallet. The
* slate will be no more than BTS_BLOCKCHAIN_NUM_DELEGATES.
* Randomly select a slate of delegates from those supported by this wallet.
* The slate will be no more than BTS_BLOCKCHAIN_NUM_DELEGATES.
*/
delegate_slate wallet::select_delegate_vote()const
{
vector<account_id_type> for_candidates;

for (auto acct_rec : my->_wallet_db.get_accounts())
for( const auto& acct_rec : my->_wallet_db.get_accounts() )
{
if (acct_rec.second.trust_level > 0)
for_candidates.push_back(acct_rec.second.id);
if( acct_rec.second.trusted )
for_candidates.push_back( acct_rec.second.id );
}
std::sort( for_candidates.begin(), for_candidates.end() );

delegate_slate result;
uint32_t delegates_to_select = std::min<uint32_t>( for_candidates.size(), BTS_BLOCKCHAIN_MAX_SLATE_SIZE);
uint32_t delegates_to_select = std::min<uint32_t>( for_candidates.size(), BTS_BLOCKCHAIN_MAX_SLATE_SIZE );

for( uint32_t i = 0; i < delegates_to_select; ++i )
{
Expand All @@ -3048,19 +3048,18 @@ namespace bts { namespace wallet {
for_candidates[d] = 0;
}
}
std::sort( result.supported_delegates.begin(),
result.supported_delegates.end() );

std::sort( result.supported_delegates.begin(), result.supported_delegates.end() );
return result;
}

void wallet::set_delegate_trust_level( const string& delegate_name,
int32_t trust_level)
void wallet::set_delegate_trust( const string& delegate_name, bool trusted )
{ try {
FC_ASSERT( is_open() );
auto war = my->_wallet_db.lookup_account( delegate_name );
if( war.valid() )
{
war->trust_level = trust_level;
war->trusted = trusted;
my->_wallet_db.cache_account( *war );
}
else
Expand All @@ -3071,18 +3070,16 @@ namespace bts { namespace wallet {
FC_ASSERT( !"Not a Registered Account" );
}
add_contact_account( delegate_name, reg_account->active_key() );
set_delegate_trust_level( delegate_name, trust_level );
set_delegate_trust( delegate_name, trusted );
}
} FC_RETHROW_EXCEPTIONS( warn, "", ("delegate_name",delegate_name)
("trust_level", trust_level) ) }
} FC_RETHROW_EXCEPTIONS( warn, "", ("delegate_name",delegate_name)("trusted", trusted) ) }

int32_t wallet::get_delegate_trust_level( const string& delegate_name) const
bool wallet::get_delegate_trust( const string& delegate_name )const
{ try {
FC_ASSERT( is_open() );
auto war = my->_wallet_db.lookup_account( delegate_name );
if( war.valid() )
return war->trust_level;
return 0;
FC_ASSERT( war.valid() );
return war->trusted;
} FC_RETHROW_EXCEPTIONS( warn, "", ("delegate_name",delegate_name) ) }

vector<wallet_balance_record> wallet::get_unspent_balances( const string& account_name,
Expand Down

0 comments on commit 3d45435

Please sign in to comment.