WIP, SON operations, cli_wallet commands and RPC

- update_son_votes
This commit is contained in:
Srdjan Obucina 2019-10-04 01:24:30 +02:00
parent 5ecbba8717
commit e4bf00e349
2 changed files with 85 additions and 1 deletions

View file

@ -1464,9 +1464,42 @@ class wallet_api
bool approve,
bool broadcast = false);
/** Change your SON votes.
*
* An account can publish a list of all SONs they approve of.
* Each account's vote is weighted according to the number of shares of the
* core asset owned by that account at the time the votes are tallied.
* This command allows you to add or remove one or more SON from this list
* in one call. When you are changing your vote on several SONs, this
* may be easier than multiple `vote_for_sons` and
* `set_desired_witness_and_committee_member_count` calls.
*
* @note you cannot vote against a SON, you can only vote for the SON
* or not vote for the SON.
*
* @param voting_account the name or id of the account who is voting with their shares
* @param sons_to_approve the names or ids of the sons owner accounts you wish
* to approve (these will be added to the list of sons
* you currently approve). This list can be empty.
* @param sons_to_reject the names or ids of the SONs owner accounts you wish
* to reject (these will be removed from the list of SONs
* you currently approve). This list can be empty.
* @param desired_number_of_sons the number of SONs you believe the network
* should have. You must vote for at least this many
* SONs. You can set this to 0 to abstain from
* voting on the number of SONNs.
* @param broadcast true if you wish to broadcast the transaction
* @return the signed transaction changing your vote for the given witnesses
*/
signed_transaction update_son_votes(string voting_account,
std::vector<std::string> sons_to_approve,
std::vector<std::string> sons_to_reject,
uint16_t desired_number_of_son,
bool broadcast = false);
/** Vote for a given witness.
*
* An account can publish a list of all witnesses they approve of. This
* An account can publish a list of all witnesses they approve of. This
* command allows you to add or remove witnesses from this list.
* Each account's vote is weighted according to the number of shares of the
* core asset owned by that account at the time the votes are tallied.
@ -2057,6 +2090,7 @@ FC_API( graphene::wallet::wallet_api,
(withdraw_vesting)
(vote_for_committee_member)
(vote_for_son_member)
(update_son_votes)
(vote_for_witness)
(update_witness_votes)
(set_voting_proxy)

View file

@ -2205,6 +2205,47 @@ public:
return sign_transaction( tx, broadcast );
} FC_CAPTURE_AND_RETHROW( (voting_account)(son_member)(approve)(broadcast) ) }
signed_transaction update_son_votes(string voting_account,
std::vector<std::string> sons_to_approve,
std::vector<std::string> sons_to_reject,
uint16_t desired_number_of_sons,
bool broadcast /* = false */)
{ try {
account_object voting_account_object = get_account(voting_account);
for (const std::string& son : sons_to_approve)
{
account_id_type son_owner_account_id = get_account_id(son);
fc::optional<son_object> son_obj = _remote_db->get_son_by_account(son_owner_account_id);
if (!son_obj)
FC_THROW("Account ${son} is not registered as a witness", ("son", son));
auto insert_result = voting_account_object.options.votes.insert(son_obj->vote_id);
if (!insert_result.second)
FC_THROW("Account ${account} was already voting for son ${son}", ("account", voting_account)("son", son));
}
for (const std::string& son : sons_to_reject)
{
account_id_type son_owner_account_id = get_account_id(son);
fc::optional<son_object> son_obj = _remote_db->get_son_by_account(son_owner_account_id);
if (!son_obj)
FC_THROW("Account ${son} is not registered as a son", ("son", son));
unsigned votes_removed = voting_account_object.options.votes.erase(son_obj->vote_id);
if (!votes_removed)
FC_THROW("Account ${account} is already not voting for son ${son}", ("account", voting_account)("son", son));
}
voting_account_object.options.num_son = desired_number_of_sons;
account_update_operation account_update_op;
account_update_op.account = voting_account_object.id;
account_update_op.new_options = voting_account_object.options;
signed_transaction tx;
tx.operations.push_back( account_update_op );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
} FC_CAPTURE_AND_RETHROW( (voting_account)(sons_to_approve)(sons_to_reject)(desired_number_of_sons)(broadcast) ) }
signed_transaction vote_for_witness(string voting_account,
string witness,
bool approve,
@ -4264,6 +4305,15 @@ signed_transaction wallet_api::vote_for_son_member(string voting_account,
return my->vote_for_son_member(voting_account, son_member, approve, broadcast);
}
signed_transaction wallet_api::update_son_votes(string voting_account,
std::vector<std::string> sons_to_approve,
std::vector<std::string> sons_to_reject,
uint16_t desired_number_of_sons,
bool broadcast /* = false */)
{
return my->update_son_votes(voting_account, sons_to_approve, sons_to_reject, desired_number_of_sons, broadcast);
}
signed_transaction wallet_api::vote_for_witness(string voting_account,
string witness,
bool approve,