From ce729ba9f905d4a05d138f3a2f15381181544d55 Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Mon, 6 Jul 2015 15:27:42 -0400 Subject: [PATCH] Add wallet api function to vote for number of witnesses/delegates --- .../wallet/include/graphene/wallet/wallet.hpp | 26 ++++++++++++++ libraries/wallet/wallet.cpp | 35 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 097bf889..7eed481e 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -936,6 +936,31 @@ class wallet_api signed_transaction set_voting_proxy(string account_to_modify, optional 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) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 4a3ef2b3..75f9d434 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -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 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;