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

Commit

Permalink
properly register set vote op
Browse files Browse the repository at this point in the history
  • Loading branch information
nmushegian committed Nov 24, 2014
1 parent e442f24 commit dad5c88
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 3 deletions.
31 changes: 31 additions & 0 deletions libraries/api/wallet_api.json
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion libraries/blockchain/include/bts/blockchain/operations.hpp
Expand Up @@ -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) )
Expand Down
1 change: 1 addition & 0 deletions libraries/blockchain/operations.cpp
Expand Up @@ -78,6 +78,7 @@ namespace bts { namespace blockchain {
bts::blockchain::operation_factory::instance().register_operation<update_block_signing_key>();
bts::blockchain::operation_factory::instance().register_operation<relative_bid_operation>();
bts::blockchain::operation_factory::instance().register_operation<relative_ask_operation>();
bts::blockchain::operation_factory::instance().register_operation<update_balance_vote_operation>();
return true;
}();

Expand Down
17 changes: 15 additions & 2 deletions libraries/client/wallet_api.cpp
Expand Up @@ -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();
Expand All @@ -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,
Expand Down Expand Up @@ -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 )
Expand Down
5 changes: 5 additions & 0 deletions libraries/wallet/include/bts/wallet/wallet.hpp
Expand Up @@ -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,
Expand Down
47 changes: 47 additions & 0 deletions libraries/wallet/wallet.cpp
Expand Up @@ -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,
Expand Down

0 comments on commit dad5c88

Please sign in to comment.