Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SON related operations, cli_wallet commands and RPC #160

Merged
merged 37 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
988a177
Added SON object
pixelplex-dev Jul 26, 2019
d36168b
Merge commit 'refs/pull/48/head' of https://github.com/peerplays-netw…
oxarbitrage Sep 18, 2019
7d6b215
rename and move stuff
oxarbitrage Sep 19, 2019
38ec553
remove member from operation names
oxarbitrage Sep 19, 2019
52e9c2a
remove not needed library
oxarbitrage Sep 19, 2019
ba77a33
rename object, add update operation skeleton
oxarbitrage Sep 20, 2019
5dcb55c
add modify logic, test case, modify delete
oxarbitrage Sep 21, 2019
6efbf84
change indentation of the son tests
oxarbitrage Sep 21, 2019
0a5d694
add hardfork guards
oxarbitrage Sep 21, 2019
723c802
minor clean
oxarbitrage Sep 21, 2019
3a4445b
add missing SON hardfork file
oxarbitrage Sep 24, 2019
17dfc6a
add protection to delete and modify son object only if owner
oxarbitrage Sep 25, 2019
4d0a5b6
add son vote type to lookup_vote_ids
oxarbitrage Sep 27, 2019
e2c579b
add additional fields to son object and operations
oxarbitrage Sep 28, 2019
3a65102
WIP, SON operations, cli_wallet commands and RPC
obucina Oct 1, 2019
44f185e
WIP, SON operations, cli_wallet commands and RPC
obucina Oct 2, 2019
457c8b9
WIP, SON related operations, cli_wallet commands and RPC
obucina Oct 2, 2019
49564af
WIP, SON related operations, cli_wallet commands and RPC
obucina Oct 2, 2019
53666a9
Merge branch 'feature/SON-operations' of https://github.com/peerplays…
obucina Oct 2, 2019
e0ff813
WIP, SON operations, cli_wallet commands and RPC
obucina Oct 2, 2019
203ee89
WIP, SON operations, cli_wallet commands and RPC
obucina Oct 2, 2019
ecfcd8e
WIP, SON operations, cli_wallet commands and RPC
obucina Oct 3, 2019
4d1bec0
WIP, SON operations, cli_wallet commands and RPC
obucina Oct 3, 2019
5ecbba8
WIP, SON operations, cli_wallet commands and RPC
obucina Oct 3, 2019
e4bf00e
WIP, SON operations, cli_wallet commands and RPC
obucina Oct 3, 2019
8bc204c
WIP, SON operations, cli_wallet commands and RPC
obucina Oct 4, 2019
3e4322b
WIP, SON operations, cli_wallet commands and RPC
obucina Oct 6, 2019
3b167ff
Merge branch 'feature/SONs-base' into feature/SON-operations
obucina Oct 8, 2019
7b6562e
Some renaming to follow existing naming convention, code cleanup
obucina Oct 8, 2019
d06b236
Add newline at the end of SON.hf
obucina Oct 8, 2019
659bfcb
Add missing comma in operations.hpp
obucina Oct 8, 2019
896b4df
Add missing parenthesis in libraries/chain/db_notify.cpp
obucina Oct 8, 2019
54599cc
Add missing parenthesis in ../../libraries/app/impacted.cpp
obucina Oct 8, 2019
bdfbf5c
Minor code cleanup
obucina Oct 9, 2019
388d00b
Fix build error, add missing parameter
obucina Oct 9, 2019
af0e0e4
Add missing #include
obucina Oct 9, 2019
d8e4a9a
Fix build error, remove undeclared field
obucina Oct 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ build:
- tests/
tags:
- builder

test:
stage: test
dependencies:
dependencies:
- build
script:
- ./tests/betting_test
- ./tests/chain_test
- ./tests/cli_test
tags:
- builder

code_quality:
stage: test
image: docker:stable
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,12 @@ namespace graphene { namespace app {
} case balance_object_type:{
/** these are free from any accounts */
break;
}
} case son_object_type:{
const auto& aobj = dynamic_cast<const son_object*>(obj);
assert( aobj != nullptr );
accounts.insert( aobj->son_account );
break;
}
case sport_object_type:
case event_group_object_type:
case event_object_type:
Expand Down
92 changes: 92 additions & 0 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
fc::optional<committee_member_object> get_committee_member_by_account(account_id_type account)const;
map<string, committee_member_id_type> lookup_committee_member_accounts(const string& lower_bound_name, uint32_t limit)const;

// SON members
vector<optional<son_object>> get_sons(const vector<son_id_type>& son_ids)const;
fc::optional<son_object> get_son_by_account(account_id_type account)const;
map<string, son_id_type> lookup_son_accounts(const string& lower_bound_name, uint32_t limit)const;
uint64_t get_son_count()const;

// Votes
vector<variant> lookup_vote_ids( const vector<vote_id_type>& votes )const;

Expand Down Expand Up @@ -1682,6 +1688,81 @@ map<string, committee_member_id_type> database_api_impl::lookup_committee_member
return committee_members_by_account_name;
}

//////////////////////////////////////////////////////////////////////
// //
// SON members //
// //
//////////////////////////////////////////////////////////////////////

vector<optional<son_object>> database_api::get_sons(const vector<son_id_type>& son_ids)const
{
return my->get_sons( son_ids );
}

vector<optional<son_object>> database_api_impl::get_sons(const vector<son_id_type>& son_ids)const
{
vector<optional<son_object>> result; result.reserve(son_ids.size());
std::transform(son_ids.begin(), son_ids.end(), std::back_inserter(result),
[this](son_id_type id) -> optional<son_object> {
if(auto o = _db.find(id))
return *o;
return {};
});
return result;
}

fc::optional<son_object> database_api::get_son_by_account(account_id_type account)const
{
return my->get_son_by_account( account );
}

fc::optional<son_object> database_api_impl::get_son_by_account(account_id_type account) const
{
const auto& idx = _db.get_index_type<son_index>().indices().get<by_account>();
auto itr = idx.find(account);
if( itr != idx.end() )
return *itr;
return {};
}

map<string, son_id_type> database_api::lookup_son_accounts(const string& lower_bound_name, uint32_t limit)const
{
return my->lookup_son_accounts( lower_bound_name, limit );
}

map<string, son_id_type> database_api_impl::lookup_son_accounts(const string& lower_bound_name, uint32_t limit)const
{
FC_ASSERT( limit <= 1000 );
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_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_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));

auto end_iter = sons_by_account_name.begin();
while (end_iter != sons_by_account_name.end() && limit--)
++end_iter;
sons_by_account_name.erase(end_iter, sons_by_account_name.end());
return sons_by_account_name;
}

uint64_t database_api::get_son_count()const
{
return my->get_son_count();
}

uint64_t database_api_impl::get_son_count()const
{
return _db.get_index_type<son_index>().indices().size();
}

//////////////////////////////////////////////////////////////////////
// //
// Votes //
Expand All @@ -1701,6 +1782,7 @@ vector<variant> database_api_impl::lookup_vote_ids( const vector<vote_id_type>&
const auto& committee_idx = _db.get_index_type<committee_member_index>().indices().get<by_vote_id>();
const auto& for_worker_idx = _db.get_index_type<worker_index>().indices().get<by_vote_for>();
const auto& against_worker_idx = _db.get_index_type<worker_index>().indices().get<by_vote_against>();
const auto& son_idx = _db.get_index_type<son_index>().indices().get<by_vote_id>();

vector<variant> result;
result.reserve( votes.size() );
Expand Down Expand Up @@ -1743,6 +1825,16 @@ vector<variant> database_api_impl::lookup_vote_ids( const vector<vote_id_type>&
}
break;
}
case vote_id_type::son:
{
auto itr = son_idx.find( id );
if( itr != son_idx.end() )
result.emplace_back( variant( *itr, 1 ) );
else
result.emplace_back( variant() );
break;
}

case vote_id_type::VOTE_TYPE_COUNT: break; // supress unused enum value warnings
default:
FC_CAPTURE_AND_THROW( fc::out_of_range_exception, (id) );
Expand Down
9 changes: 9 additions & 0 deletions libraries/app/impacted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,15 @@ struct get_impacted_account_visitor
void operator()( const sweeps_vesting_claim_operation& op ) {
_impacted.insert( op.account );
}
void operator()( const son_create_operation& op ){
_impacted.insert( op.owner_account );
}
void operator()( const son_update_operation& op ){
_impacted.insert( op.owner_account );
}
void operator()( const son_delete_operation& op ){
_impacted.insert( op.owner_account );
}
};

void operation_get_impacted_accounts( const operation& op, flat_set<account_id_type>& result )
Expand Down
39 changes: 39 additions & 0 deletions libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <graphene/chain/event_object.hpp>
#include <graphene/chain/betting_market_object.hpp>
#include <graphene/chain/global_betting_statistics_object.hpp>
#include <graphene/chain/son_object.hpp>

#include <graphene/chain/worker_object.hpp>
#include <graphene/chain/witness_object.hpp>
Expand Down Expand Up @@ -568,6 +569,38 @@ class database_api
*/
map<string, committee_member_id_type> lookup_committee_member_accounts(const string& lower_bound_name, uint32_t limit)const;

/////////////////
// SON members //
/////////////////

/**
* @brief Get a list of SONs by ID
* @param son_ids IDs of the SONs to retrieve
* @return The SONs corresponding to the provided IDs
*
* This function has semantics identical to @ref get_objects
*/
vector<optional<son_object>> get_sons(const vector<son_id_type>& son_ids)const;

/**
* @brief Get the SON owned by a given account
* @param account The ID of the account whose SON should be retrieved
* @return The SON object, or null if the account does not have a SON
*/
fc::optional<son_object> get_son_by_account(account_id_type account)const;

/**
* @brief Get names and IDs for registered SONs
* @param lower_bound_name Lower bound of the first name to return
* @param limit Maximum number of results to return -- must not exceed 1000
* @return Map of SON names to corresponding IDs
*/
map<string, son_id_type> lookup_son_accounts(const string& lower_bound_name, uint32_t limit)const;

/**
* @brief Get the total number of SONs registered with the blockchain
*/
uint64_t get_son_count()const;

/// WORKERS

Expand Down Expand Up @@ -775,6 +808,12 @@ FC_API(graphene::app::database_api,
(get_committee_member_by_account)
(lookup_committee_member_accounts)

// SON members
(get_sons)
(get_son_by_account)
(lookup_son_accounts)
(get_son_count)

// workers
(get_workers_by_account)
// Votes
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ add_library( graphene_chain

affiliate_payout.cpp

son_evaluator.cpp

${HEADERS}
${PROTOCOL_HEADERS}
"${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp"
Expand Down
8 changes: 6 additions & 2 deletions libraries/chain/db_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@
#include <graphene/chain/tournament_object.hpp>
#include <graphene/chain/match_object.hpp>
#include <graphene/chain/game_object.hpp>


#include <graphene/chain/sport_object.hpp>
#include <graphene/chain/event_group_object.hpp>
#include <graphene/chain/event_object.hpp>
#include <graphene/chain/betting_market_object.hpp>
#include <graphene/chain/global_betting_statistics_object.hpp>
#include <graphene/chain/son_object.hpp>

#include <graphene/chain/account_evaluator.hpp>
#include <graphene/chain/asset_evaluator.hpp>
Expand All @@ -77,6 +76,7 @@
#include <graphene/chain/event_evaluator.hpp>
#include <graphene/chain/betting_market_evaluator.hpp>
#include <graphene/chain/tournament_evaluator.hpp>
#include <graphene/chain/son_evaluator.hpp>

#include <graphene/chain/protocol/fee_schedule.hpp>

Expand Down Expand Up @@ -243,6 +243,9 @@ void database::initialize_evaluators()
register_evaluator<lottery_reward_evaluator>();
register_evaluator<lottery_end_evaluator>();
register_evaluator<sweeps_vesting_claim_evaluator>();
register_evaluator<create_son_evaluator>();
register_evaluator<update_son_evaluator>();
register_evaluator<delete_son_evaluator>();
}

void database::initialize_indexes()
Expand All @@ -259,6 +262,7 @@ 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<limit_order_index > >();
add_index< primary_index<call_order_index > >();
Expand Down
Loading