BitShares Forum
Main => General Discussion => Topic started by: BTSdac on December 16, 2015, 02:00:17 pm
-
I am a new learner of C++ , and try to leaning BTS code
but there are so many questions. BM ,can you answer the question
there are many operations of BTS , but all operations use same function return sign_transaction( tx, broadcast );
to finish sign.
signed_transaction set_desired_witness_and_committee_member_count(string account_to_modify,
uint16_t desired_number_of_witnesses,
uint16_t desired_number_of_committee_members,
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_committee_members)
FC_THROW("Account ${account} is already voting for ${witnesses} witnesses and ${committee_members} committee_members",
("account", account_to_modify)("witnesses", desired_number_of_witnesses)("committee_members",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_committee_members;
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 );
set_operation_fees( tx, _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_committee_members)(broadcast) ) }
signed_transaction set_voting_proxy(string account_to_modify,
optional<string> voting_account,
bool broadcast /* = false */)
{ try {
account_object account_object_to_modify = get_account(account_to_modify);
if (voting_account)
{
account_id_type new_voting_account_id = get_account_id(*voting_account);
if (account_object_to_modify.options.voting_account == new_voting_account_id)
FC_THROW("Voting proxy for ${account} is already set to ${voter}", ("account", account_to_modify)("voter", *voting_account));
account_object_to_modify.options.voting_account = new_voting_account_id;
}
else
{
if (account_object_to_modify.options.voting_account == GRAPHENE_PROXY_TO_SELF_ACCOUNT)
FC_THROW("Account ${account} is already voting for itself", ("account", account_to_modify));
account_object_to_modify.options.voting_account = GRAPHENE_PROXY_TO_SELF_ACCOUNT;
}
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 );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
} FC_CAPTURE_AND_RETHROW( (account_to_modify)(voting_account)(broadcast) ) }
though tx.operations is different . but how to finish this operation, I cannot find the specific code
BM ,can you answer the question , +5% +5%
-
a transaction contains several operations in an array ...
the transaction including those operations is signed
There are some calls implemented that build operations into transactions an sign them directly, such as set_voting_proxy, but in theory you can construct all transaction manually.
See http://docs.bitshares.eu/bitshares/tutorials/construct-transaction.html
-
Looks like its creating copies of objects everywhere.. Why no const references?
-
Looks like its creating copies of objects everywhere.. Why no const references?
Because these API calls are called with newly constructed objects. No extra copies are made. Also string is copy on write or small string optimized.
-
Looks like its creating copies of objects everywhere.. Why no const references?
Because these API calls are called with newly constructed objects. No extra copies are made. Also string is copy on write or small string optimized.
What about the string that is copied upon each call to "set_desired_witness_and_committee_member_count" for example? This should be a const & for strictness and performance reasons. Just an example, it should extend to any params.
With this design it's invoking the copy constructor instead of allocating memory directly into the object space of the variable you need. 1 Extra copy is made and cleaned up by the garbage collector every time. The string's that are passed by value are creating copies every time needlessly?
-
Looks like its creating copies of objects everywhere.. Why no const references?
Because these API calls are called with newly constructed objects. No extra copies are made. Also string is copy on write or small string optimized.
What about the string that is copied upon each call to "set_desired_witness_and_committee_member_count" for example? This should be a const & for strictness and performance reasons. Just an example, it should extend to any params.
With this design it's invoking the copy constructor instead of allocating memory directly into the object space of the variable you need. 1 Extra copy is made and cleaned up by the garbage collector every time. The string's that are passed by value are creating copies every time needlessly?
There are micro optimizations in the API interface that we could implement. If it were in the inner loop of validation I would be more concerned. If you look at the ACTUAL call site for this method you will see that the string passed in is a temporary (RVALUE) and thus no extra copy is made.