Add wallet api function to vote for number of witnesses/delegates

This commit is contained in:
Eric Frias 2015-07-06 15:27:42 -04:00
parent b9b4aa08de
commit ce729ba9f9
2 changed files with 61 additions and 0 deletions

View file

@ -936,6 +936,31 @@ class wallet_api
signed_transaction set_voting_proxy(string account_to_modify,
optional<string> voting_account,
bool broadcast = false);
/** Set your vote for the number of witnesses and delegates in the system.
*
* Each account can voice their opinion on how many delegates and how many
* witnesses there should be in the active delegate/active witness list. These
* are independent of each other. You must vote your approval of at least as many
* delegates or witnesses as you claim there should be (you can't say that there should
* be 20 delegates but only vote for 10).
*
* There are maximum values for each set in the blockchain parameters (currently
* defaulting to 1001).
*
* This setting can be changed at any time. If your account has a voting proxy
* set, your preferences will be ignored.
*
* @param account_to_modify the name or id of the account to update
* @param number_of_delegates the number
*
* @param broadcast true if you wish to broadcast the transaction
* @return the signed transaction changing your vote proxy settings
*/
signed_transaction set_desired_witness_and_delegate_count(string account_to_modify,
uint16_t desired_number_of_witnesses,
uint16_t desired_number_of_delegates,
bool broadcast = false);
/** Signs a transaction.
*
@ -1042,6 +1067,7 @@ FC_API( graphene::wallet::wallet_api,
(vote_for_delegate)
(vote_for_witness)
(set_voting_proxy)
(set_desired_witness_and_delegate_count)
(get_account)
(get_account_id)
(get_block)

View file

@ -1328,6 +1328,32 @@ public:
return sign_transaction( tx, broadcast );
} FC_CAPTURE_AND_RETHROW( (account_to_modify)(voting_account)(broadcast) ) }
signed_transaction set_desired_witness_and_delegate_count(string account_to_modify,
uint16_t desired_number_of_witnesses,
uint16_t desired_number_of_delegates,
bool broadcast /* = false */)
{ try {
account_object account_object_to_modify = get_account(account_to_modify);
if (account_object_to_modify.options.num_witness == desired_number_of_witnesses &&
account_object_to_modify.options.num_committee == desired_number_of_delegates)
FC_THROW("Account ${account} is already voting for ${witnesses} witnesses and ${delegates} delegates",
("account", account_to_modify)("witnesses", desired_number_of_witnesses)("delegates",desired_number_of_witnesses));
account_object_to_modify.options.num_witness = desired_number_of_witnesses;
account_object_to_modify.options.num_committee = desired_number_of_delegates;
account_update_operation account_update_op;
account_update_op.account = account_object_to_modify.id;
account_update_op.new_options = account_object_to_modify.options;
signed_transaction tx;
tx.operations.push_back( account_update_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
tx.validate();
return sign_transaction( tx, broadcast );
} FC_CAPTURE_AND_RETHROW( (account_to_modify)(desired_number_of_witnesses)(desired_number_of_delegates)(broadcast) ) }
signed_transaction sign_transaction(signed_transaction tx, bool broadcast = false)
{
flat_set<account_id_type> req_active_approvals;
@ -2074,6 +2100,15 @@ signed_transaction wallet_api::set_voting_proxy(string account_to_modify,
return my->set_voting_proxy(account_to_modify, voting_account, broadcast);
}
signed_transaction wallet_api::set_desired_witness_and_delegate_count(string account_to_modify,
uint16_t desired_number_of_witnesses,
uint16_t desired_number_of_delegates,
bool broadcast /* = false */)
{
return my->set_desired_witness_and_delegate_count(account_to_modify, desired_number_of_witnesses,
desired_number_of_delegates, broadcast);
}
void wallet_api::set_wallet_filename(string wallet_filename)
{
my->_wallet_filename = wallet_filename;