From dad5c882bd587ce1cdebf43720a08fb90e55915a Mon Sep 17 00:00:00 2001 From: Nikolai Mushegian Date: Mon, 24 Nov 2014 09:58:28 -0500 Subject: [PATCH] properly register set vote op --- libraries/api/wallet_api.json | 31 ++++++++++++ .../include/bts/blockchain/operations.hpp | 2 +- libraries/blockchain/operations.cpp | 1 + libraries/client/wallet_api.cpp | 17 ++++++- .../wallet/include/bts/wallet/wallet.hpp | 5 ++ libraries/wallet/wallet.cpp | 47 +++++++++++++++++++ 6 files changed, 100 insertions(+), 3 deletions(-) diff --git a/libraries/api/wallet_api.json b/libraries/api/wallet_api.json index b242d26ee..3275366ca 100644 --- a/libraries/api/wallet_api.json +++ b/libraries/api/wallet_api.json @@ -2148,6 +2148,37 @@ ], "prerequisites" : ["wallet_unlocked"] }, + { + "method_name" : "wallet_balance_set_vote_info", + "description" : "Set this balance's voting address and slate", + "return_type" : "transaction_builder", + "parameters" : [ + { + "name" : "balance_id", + "type" : "address", + "description" : "the current name of the account" + }, + { + "name" : "voter_address", + "type" : "address", + "description" : "the new voting address" + }, + { + "name" : "vote_method", + "type" : "vote_selection_method", + "description" : "enumeration [vote_none | vote_all | vote_random | vote_recommended] ", + "default_value" : "vote_recommended" + } + { + "name" : "sign_and_broadcast", + "type" : "bool", + "description" : "", + "default_value" : "true" + } + ], + "prerequisites" : ["wallet_open"], + "aliases" : ["set_vote_info"] + }, { "method_name" : "wallet_publish_slate", "description" : "Publishes the current wallet delegate slate to the public data associated with the account", diff --git a/libraries/blockchain/include/bts/blockchain/operations.hpp b/libraries/blockchain/include/bts/blockchain/operations.hpp index 2342dd54c..76874a59e 100644 --- a/libraries/blockchain/include/bts/blockchain/operations.hpp +++ b/libraries/blockchain/include/bts/blockchain/operations.hpp @@ -139,9 +139,9 @@ FC_REFLECT_ENUM( bts::blockchain::operation_type_enum, (withdraw_all_op_type) (release_escrow_op_type) (update_block_signing_key_type) - (update_balance_vote_op_type) (relative_bid_op_type) (relative_ask_op_type) + (update_balance_vote_op_type) ) FC_REFLECT( bts::blockchain::operation, (type)(data) ) diff --git a/libraries/blockchain/operations.cpp b/libraries/blockchain/operations.cpp index 3b1055722..82a4a1fac 100644 --- a/libraries/blockchain/operations.cpp +++ b/libraries/blockchain/operations.cpp @@ -78,6 +78,7 @@ namespace bts { namespace blockchain { bts::blockchain::operation_factory::instance().register_operation(); bts::blockchain::operation_factory::instance().register_operation(); bts::blockchain::operation_factory::instance().register_operation(); + bts::blockchain::operation_factory::instance().register_operation(); return true; }(); diff --git a/libraries/client/wallet_api.cpp b/libraries/client/wallet_api.cpp index 0a70fc9b6..b631e4225 100644 --- a/libraries/client/wallet_api.cpp +++ b/libraries/client/wallet_api.cpp @@ -434,7 +434,7 @@ transaction_builder detail::client_impl::wallet_multisig_withdraw_start( transaction_builder detail::client_impl::wallet_builder_add_signature( const transaction_builder& builder, bool broadcast ) -{ +{ try { auto b2 = _wallet->create_transaction_builder( builder ); if( b2->transaction_record.trx.signatures.empty() ) b2->finalize(); @@ -449,7 +449,7 @@ transaction_builder detail::client_impl::wallet_builder_add_signature( } } return *b2; -} +} FC_CAPTURE_AND_RETHROW( (builder)(broadcast) ) } wallet_transaction_record detail::client_impl::wallet_transfer_from_with_escrow( const string& amount_to_transfer, @@ -1170,6 +1170,19 @@ fc::variant client_impl::wallet_login_finish(const public_key_type &server_key, return _wallet->login_finish(server_key, client_key, client_signature); } + +transaction_builder client_impl::wallet_balance_set_vote_info(const balance_id_type& balance_id, + const address& voter_address, + const vote_selection_method& selection_method, + bool sign_and_broadcast) +{ + auto builder = _wallet->set_vote_info( balance_id, voter_address, selection_method ); + if( sign_and_broadcast ) + wallet_builder_add_signature( builder, true ); + return builder; +} + + wallet_transaction_record client_impl::wallet_publish_price_feed( const std::string& delegate_account, double real_amount_per_xts, const std::string& real_amount_symbol ) diff --git a/libraries/wallet/include/bts/wallet/wallet.hpp b/libraries/wallet/include/bts/wallet/wallet.hpp index eed8291d5..0c5cb3e48 100644 --- a/libraries/wallet/include/bts/wallet/wallet.hpp +++ b/libraries/wallet/include/bts/wallet/wallet.hpp @@ -376,6 +376,11 @@ namespace bts { namespace wallet { bool settle, bool sign ); + transaction_builder set_vote_info( + const balance_id_type& balance_id, + const address& voter_address, + vote_selection_method selection_method + ); wallet_transaction_record publish_slate( const string& account_to_publish_under, const string& account_to_pay_with, diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index b9fd2a6fd..75e1f3240 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2002,6 +2002,53 @@ namespace detail { return record; } FC_CAPTURE_AND_RETHROW( (account_to_publish_under)(account_to_pay_with)(sign) ) } + transaction_builder wallet::set_vote_info( + const balance_id_type& balance_id, + const address& voter_address, + vote_selection_method selection_method ) + { try { + FC_ASSERT( is_open() ); + FC_ASSERT( is_unlocked() ); + + auto builder = create_transaction_builder(); + const auto required_fees = get_transaction_fee(); + auto balance = my->_blockchain->get_balance_record( balance_id ); + FC_ASSERT( balance.valid(), "No such balance!" ); + + signed_transaction trx; + trx.expiration = blockchain::now() + get_transaction_expiration(); + + const auto slate = my->select_delegate_vote( selection_method ); + auto slate_id = slate.id(); + + if( slate_id != slate_id_type( 0 ) && !my->_blockchain->get_delegate_slate( slate_id ).valid() ) + trx.define_delegate_slate( slate ); + + + update_balance_vote_operation op; + op.balance_id = balance_id; + op.new_restricted_owner = voter_address; + op.new_slate = slate_id; + if( balance->restricted_owner == voter_address ) // not an owner update + builder->required_signatures.insert( voter_address ); + else + builder->required_signatures.insert( balance->owner() ); + + trx.withdraw( balance_id, required_fees.amount ); + trx.operations.push_back( op ); + + auto entry = ledger_entry(); + entry.memo = "Set balance vote info"; + auto record = wallet_transaction_record(); + record.ledger_entries.push_back( entry ); + record.fee = required_fees; + + record.trx = trx; + builder->transaction_record = record; + return *builder; + } FC_CAPTURE_AND_RETHROW( (balance_id)(voter_address)(selection_method) ) } + + wallet_transaction_record wallet::update_block_signing_key( const string& authorizing_account_name, const string& delegate_name,