Some renaming to follow existing naming convention, code cleanup

This commit is contained in:
Srdjan Obucina 2019-10-08 21:14:26 +02:00
parent 3b167ffd03
commit 7b6562ec85
13 changed files with 129 additions and 133 deletions

6
.gitmodules vendored
View file

@ -3,6 +3,6 @@
url = https://github.com/bitshares/bitshares-core.wiki.git
ignore = dirty
[submodule "libraries/fc"]
path = libraries/fc
url = https://github.com/PBSA/peerplays-fc.git
ignore = dirty
path = libraries/fc
url = https://github.com/PBSA/peerplays-fc.git
ignore = dirty

View file

@ -441,7 +441,7 @@ namespace graphene { namespace app {
} case son_object_type:{
const auto& aobj = dynamic_cast<const son_object*>(obj);
assert( aobj != nullptr );
accounts.insert( aobj->son_member_account );
accounts.insert( aobj->son_account );
break;
}
case sport_object_type:

View file

@ -1736,13 +1736,13 @@ map<string, son_id_type> database_api_impl::lookup_son_accounts(const string& lo
const auto& sons_by_id = _db.get_index_type<son_index>().indices().get<by_id>();
// we want to order sons by account name, but that name is in the account object
// so the son_member_index doesn't have a quick way to access it.
// so the son_index doesn't have a quick way to access it.
// get all the names and look them all up, sort them, then figure out what
// records to return. This could be optimized, but we expect the
// number of witnesses to be few and the frequency of calls to be rare
std::map<std::string, son_id_type> sons_by_account_name;
for (const son_object& son : sons_by_id)
if (auto account_iter = _db.find(son.son_member_account))
if (auto account_iter = _db.find(son.son_account))
if (account_iter->name >= lower_bound_name) // we can ignore anything below lower_bound_name
sons_by_account_name.insert(std::make_pair(account_iter->name, son.id));

View file

@ -262,10 +262,8 @@ void database::initialize_indexes()
acnt_index->add_secondary_index<account_referrer_index>();
add_index< primary_index<committee_member_index, 8> >(); // 256 members per chunk
add_index< primary_index<son_index, 8> >(); // 256 sons per chunk
add_index< primary_index<witness_index, 10> >(); // 1024 witnesses per chunk
add_index< primary_index<committee_member_index> >();
add_index< primary_index<son_index> >();
add_index< primary_index<witness_index> >();
add_index< primary_index<limit_order_index > >();
add_index< primary_index<call_order_index > >();

View file

@ -253,7 +253,7 @@ void database::update_active_witnesses()
void database::update_active_committee_members()
{ try {
assert( _committee_count_histogram_buffer.size() > 0 );
share_type stake_target = (_total_voting_stake-_witness_count_histogram_buffer[0]) / 2;
share_type stake_target = (_total_voting_stake-_committee_count_histogram_buffer[0]) / 2;
/// accounts that vote for 0 or 1 witness do not get to express an opinion on
/// the number of witnesses to have (they abstain and are non-voting accounts)
@ -329,7 +329,7 @@ void database::update_active_committee_members()
void database::update_active_sons()
{ try {
assert( _son_count_histogram_buffer.size() > 0 );
share_type stake_target = (_total_voting_stake-_witness_count_histogram_buffer[0]) / 2;
share_type stake_target = (_total_voting_stake-_son_count_histogram_buffer[0]) / 2;
/// accounts that vote for 0 or 1 son do not get to express an opinion on
/// the number of sons to have (they abstain and are non-voting accounts)
@ -372,7 +372,7 @@ void database::update_active_sons()
for( const son_object& son : sons )
{
weights.emplace(son.son_member_account, _vote_tally_buffer[son.vote_id]);
weights.emplace(son.son_account, _vote_tally_buffer[son.vote_id]);
total_votes += _vote_tally_buffer[son.vote_id];
}
@ -394,7 +394,7 @@ void database::update_active_sons()
{
vote_counter vc;
for( const son_object& son : sons )
vc.add( son.son_member_account, std::max(_vote_tally_buffer[son.vote_id], UINT64_C(1)) );
vc.add( son.son_account, std::max(_vote_tally_buffer[son.vote_id], UINT64_C(1)) );
vc.finish( a.active );
}
} );

View file

@ -384,7 +384,7 @@ void get_relevant_accounts( const object* obj, flat_set<account_id_type>& accoun
} case son_object_type:{
const auto& aobj = dynamic_cast<const son_object*>(obj);
assert( aobj != nullptr );
accounts.insert( aobj->son_member_account );
accounts.insert( aobj->son_account );
break;
}
}

View file

@ -1,4 +1,5 @@
// SON HARDFORK Monday, September 21, 2020 1:43:11 PM
#ifndef HARDFORK_SON_TIME
#define HARDFORK_SON_TIME (fc::time_point_sec( 1000000000 ))
#include <ctime>
#define HARDFORK_SON_TIME (fc::time_point_sec( time(NULL) - (60 * 60) ))
#endif

View file

@ -8,7 +8,7 @@ namespace graphene { namespace chain {
/**
* @class son_object
* @brief tracks information about a son_member account.
* @brief tracks information about a SON account.
* @ingroup object
*/
class son_object : public abstract_object<son_object>
@ -17,7 +17,7 @@ namespace graphene { namespace chain {
static const uint8_t space_id = protocol_ids;
static const uint8_t type_id = son_object_type;
account_id_type son_member_account;
account_id_type son_account;
vote_id_type vote_id;
uint64_t total_votes = 0;
string url;
@ -28,22 +28,22 @@ namespace graphene { namespace chain {
struct by_account;
struct by_vote_id;
using son_member_multi_index_type = multi_index_container<
using son_multi_index_type = multi_index_container<
son_object,
indexed_by<
ordered_unique< tag<by_id>,
member<object, object_id_type, &object::id>
>,
ordered_unique< tag<by_account>,
member<son_object, account_id_type, &son_object::son_member_account>
member<son_object, account_id_type, &son_object::son_account>
>,
ordered_unique< tag<by_vote_id>,
member<son_object, vote_id_type, &son_object::vote_id>
>
>
>;
using son_index = generic_index<son_object, son_member_multi_index_type>;
using son_index = generic_index<son_object, son_multi_index_type>;
} } // graphene::chain
FC_REFLECT_DERIVED( graphene::chain::son_object, (graphene::db::object),
(son_member_account)(vote_id)(total_votes)(url)(deposit)(signing_key)(pay_vb) )
(son_account)(vote_id)(total_votes)(url)(deposit)(signing_key)(pay_vb) )

View file

@ -21,7 +21,7 @@ object_id_type create_son_evaluator::do_apply(const son_create_operation& op)
});
const auto& new_son_object = db().create<son_object>( [&]( son_object& obj ){
obj.son_member_account = op.owner_account;
obj.son_account = op.owner_account;
obj.vote_id = vote_id;
obj.url = op.url;
obj.deposit = op.deposit;
@ -34,7 +34,7 @@ object_id_type create_son_evaluator::do_apply(const son_create_operation& op)
void_result update_son_evaluator::do_evaluate(const son_update_operation& op)
{ try {
FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); // can be removed after HF date pass
FC_ASSERT(db().get(op.son_id).son_member_account == op.owner_account);
FC_ASSERT(db().get(op.son_id).son_account == op.owner_account);
const auto& idx = db().get_index_type<son_index>().indices().get<by_id>();
FC_ASSERT( idx.find(op.son_id) != idx.end() );
return void_result();
@ -59,7 +59,7 @@ object_id_type update_son_evaluator::do_apply(const son_update_operation& op)
void_result delete_son_evaluator::do_evaluate(const son_delete_operation& op)
{ try {
FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON_HARDFORK"); // can be removed after HF date pass
FC_ASSERT(db().get(op.son_id).son_member_account == op.owner_account);
FC_ASSERT(db().get(op.son_id).son_account == op.owner_account);
const auto& idx = db().get_index_type<son_index>().indices().get<by_id>();
FC_ASSERT( idx.find(op.son_id) != idx.end() );
return void_result();

View file

@ -1466,25 +1466,25 @@ class wallet_api
bool approve,
bool broadcast = false);
/** Vote for a given son_member.
/** Vote for a given SON.
*
* An account can publish a list of all son_memberes they approve of. This
* command allows you to add or remove son_memberes from this list.
* An account can publish a list of all SONs they approve of. This
* command allows you to add or remove SONs 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.
*
* @note you cannot vote against a son_member, you can only vote for the son_member
* or not vote for the son_member.
* @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 son_member the name or id of the son_member' owner account
* @param approve true if you wish to vote in favor of that son_member, false to
* remove your vote in favor of that son_member
* @param son the name or id of the SONs' owner account
* @param approve true if you wish to vote in favor of that SON, false to
* remove your vote in favor of that SON
* @param broadcast true if you wish to broadcast the transaction
* @return the signed transaction changing your vote for the given son_member
* @return the signed transaction changing your vote for the given SON
*/
signed_transaction vote_for_son(string voting_account,
string son_member,
string son,
bool approve,
bool broadcast = false);

View file

@ -701,11 +701,8 @@ public:
result["participation"] = (100*dynamic_props.recent_slots_filled.popcount()) / 128.0;
result["active_witnesses"] = fc::variant(global_props.active_witnesses, GRAPHENE_MAX_NESTED_OBJECTS);
result["active_committee_members"] = fc::variant(global_props.active_committee_members, GRAPHENE_MAX_NESTED_OBJECTS);
result["active_sons"] = fc::variant(global_props.active_sons, GRAPHENE_MAX_NESTED_OBJECTS);
result["entropy"] = fc::variant(dynamic_props.random, GRAPHENE_MAX_NESTED_OBJECTS);
result["active_witnesses"] = global_props.active_witnesses;
result["active_committee_members"] = global_props.active_committee_members;
result["active_sons"] = global_props.active_sons;
result["entropy"] = dynamic_props.random;
return result;
}
@ -1898,7 +1895,7 @@ public:
bool broadcast /* = false */)
{ try {
son_object son = get_son(owner_account);
account_object son_account = get_account( son.son_member_account );
account_object son_account = get_account( son.son_account );
fc::ecc::private_key active_private_key = get_private_key_for_account(son_account);
son_update_operation son_update_op;
@ -1922,7 +1919,7 @@ public:
bool broadcast /* = false */)
{ try {
son_object son = get_son(owner_account);
account_object son_account = get_account( son.son_member_account );
account_object son_account = get_account( son.son_account );
fc::ecc::private_key active_private_key = get_private_key_for_account(son_account);
son_delete_operation son_delete_op;
@ -2206,26 +2203,26 @@ public:
} FC_CAPTURE_AND_RETHROW( (voting_account)(committee_member)(approve)(broadcast) ) }
signed_transaction vote_for_son(string voting_account,
string son_member,
string son,
bool approve,
bool broadcast /* = false */)
{ try {
account_object voting_account_object = get_account(voting_account);
account_id_type son_member_owner_account_id = get_account_id(son_member);
fc::optional<son_object> son_member_obj = _remote_db->get_son_by_account(son_member_owner_account_id);
if (!son_member_obj)
FC_THROW("Account ${son_member} is not registered as a son_member", ("son_member", son_member));
account_id_type son_account_id = get_account_id(son);
fc::optional<son_object> son_obj = _remote_db->get_son_by_account(son_account_id);
if (!son_obj)
FC_THROW("Account ${son} is not registered as a son", ("son", son));
if (approve)
{
auto insert_result = voting_account_object.options.votes.insert(son_member_obj->vote_id);
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_member ${son_member}", ("account", voting_account)("son_member", son_member));
FC_THROW("Account ${account} was already voting for son ${son}", ("account", voting_account)("son", son));
}
else
{
unsigned votes_removed = voting_account_object.options.votes.erase(son_member_obj->vote_id);
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_member ${son_member}", ("account", voting_account)("son_member", son_member));
FC_THROW("Account ${account} is already not voting for son ${son}", ("account", voting_account)("son", son));
}
account_update_operation account_update_op;
account_update_op.account = voting_account_object.id;
@ -2237,7 +2234,7 @@ public:
tx.validate();
return sign_transaction( tx, broadcast );
} FC_CAPTURE_AND_RETHROW( (voting_account)(son_member)(approve)(broadcast) ) }
} FC_CAPTURE_AND_RETHROW( (voting_account)(son)(approve)(broadcast) ) }
signed_transaction update_son_votes(string voting_account,
std::vector<std::string> sons_to_approve,
@ -4331,11 +4328,11 @@ signed_transaction wallet_api::vote_for_committee_member(string voting_account,
}
signed_transaction wallet_api::vote_for_son(string voting_account,
string son_member,
string son,
bool approve,
bool broadcast /* = false */)
{
return my->vote_for_son(voting_account, son_member, approve, broadcast);
return my->vote_for_son(voting_account, son, approve, broadcast);
}
signed_transaction wallet_api::update_son_votes(string voting_account,

View file

@ -175,7 +175,7 @@ try {
obj = idx.find( alice_id );
// not deleting
BOOST_REQUIRE( obj != idx.end() );
BOOST_CHECK( obj->son_member_account.instance == alice_id.instance);
BOOST_CHECK( obj->son_account.instance == alice_id.instance);
}
catch (fc::exception &e) {
edump((e.to_detail_string()));