Merge pull request #215 from peerplays-network/feature/SON-150
[SON-150] list_active_sons wallet_api call
This commit is contained in:
commit
36c93a586c
3 changed files with 90 additions and 0 deletions
|
|
@ -1363,6 +1363,13 @@ class wallet_api
|
||||||
*/
|
*/
|
||||||
map<string, son_id_type> list_sons(const string& lowerbound, uint32_t limit);
|
map<string, son_id_type> list_sons(const string& lowerbound, uint32_t limit);
|
||||||
|
|
||||||
|
/** Lists active at the moment SONs.
|
||||||
|
* This returns a list of all account names that own active SON, and the associated SON id,
|
||||||
|
* sorted by name.
|
||||||
|
* @returns a list of active SONs mapping SON names to SON ids
|
||||||
|
*/
|
||||||
|
map<string, son_id_type> list_active_sons();
|
||||||
|
|
||||||
/** Creates a witness object owned by the given account.
|
/** Creates a witness object owned by the given account.
|
||||||
*
|
*
|
||||||
* An account can have at most one witness object.
|
* An account can have at most one witness object.
|
||||||
|
|
|
||||||
|
|
@ -1932,6 +1932,28 @@ public:
|
||||||
return sign_transaction( tx, broadcast );
|
return sign_transaction( tx, broadcast );
|
||||||
} FC_CAPTURE_AND_RETHROW( (owner_account)(broadcast) ) }
|
} FC_CAPTURE_AND_RETHROW( (owner_account)(broadcast) ) }
|
||||||
|
|
||||||
|
map<string, son_id_type> list_active_sons()
|
||||||
|
{ try {
|
||||||
|
global_property_object gpo = get_global_properties();
|
||||||
|
std::vector<fc::optional<son_object>> son_objects = _remote_db->get_sons(gpo.active_sons);
|
||||||
|
vector<account_id_type> owners;
|
||||||
|
owners.resize(son_objects.size());
|
||||||
|
std::transform(son_objects.begin(), son_objects.end(), owners.begin(),
|
||||||
|
[](const fc::optional<son_object>& obj) {
|
||||||
|
FC_ASSERT(obj, "Invalid active SONs list in global properties.");
|
||||||
|
return obj->son_account;
|
||||||
|
});
|
||||||
|
vector<fc::optional<account_object>> accs = _remote_db->get_accounts(owners);
|
||||||
|
map<string, son_id_type> result;
|
||||||
|
std::transform(accs.begin(), accs.end(), gpo.active_sons.begin(),
|
||||||
|
std::inserter(result, result.end()),
|
||||||
|
[](fc::optional<account_object>& acct, son_id_type& sid) {
|
||||||
|
FC_ASSERT(acct, "Invalid active SONs list in global properties.");
|
||||||
|
return std::make_pair<string, son_id_type>(string(acct->name), std::move(sid));
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
} FC_CAPTURE_AND_RETHROW() }
|
||||||
|
|
||||||
signed_transaction create_witness(string owner_account,
|
signed_transaction create_witness(string owner_account,
|
||||||
string url,
|
string url,
|
||||||
bool broadcast /* = false */)
|
bool broadcast /* = false */)
|
||||||
|
|
@ -4303,6 +4325,11 @@ map<string, son_id_type> wallet_api::list_sons(const string& lowerbound, uint32_
|
||||||
return my->_remote_db->lookup_son_accounts(lowerbound, limit);
|
return my->_remote_db->lookup_son_accounts(lowerbound, limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
map<string, son_id_type> wallet_api::list_active_sons()
|
||||||
|
{
|
||||||
|
return my->list_active_sons();
|
||||||
|
}
|
||||||
|
|
||||||
signed_transaction wallet_api::create_witness(string owner_account,
|
signed_transaction wallet_api::create_witness(string owner_account,
|
||||||
string url,
|
string url,
|
||||||
bool broadcast /* = false */)
|
bool broadcast /* = false */)
|
||||||
|
|
|
||||||
|
|
@ -530,6 +530,62 @@ BOOST_AUTO_TEST_CASE( related_functions )
|
||||||
BOOST_TEST_MESSAGE("SON-related functions cli wallet tests end");
|
BOOST_TEST_MESSAGE("SON-related functions cli wallet tests end");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_CASE( cli_list_active_sons, cli_fixture )
|
||||||
|
{
|
||||||
|
BOOST_TEST_MESSAGE("SON cli wallet tests for list_active_sons begin");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
son_test_helper sth(*this);
|
||||||
|
|
||||||
|
signed_transaction vote_tx;
|
||||||
|
global_property_object gpo;
|
||||||
|
|
||||||
|
gpo = con.wallet_api_ptr->get_global_properties();
|
||||||
|
unsigned int son_number = gpo.parameters.maximum_son_count;
|
||||||
|
|
||||||
|
// create son accounts
|
||||||
|
for(unsigned int i = 0; i < son_number + 1; i++)
|
||||||
|
{
|
||||||
|
sth.create_son("sonaccount" + fc::to_pretty_string(i),
|
||||||
|
"http://son" + fc::to_pretty_string(i), false);
|
||||||
|
}
|
||||||
|
BOOST_CHECK(generate_maintenance_block());
|
||||||
|
|
||||||
|
BOOST_TEST_MESSAGE("Voting for SONs");
|
||||||
|
for(unsigned int i = 1; i < son_number + 1; i++)
|
||||||
|
{
|
||||||
|
std::string name = "sonaccount" + fc::to_pretty_string(i);
|
||||||
|
vote_tx = con.wallet_api_ptr->vote_for_son(name, name, true, true);
|
||||||
|
}
|
||||||
|
BOOST_CHECK(generate_maintenance_block());
|
||||||
|
|
||||||
|
for(unsigned int i = 1; i < son_number; i++)
|
||||||
|
{
|
||||||
|
std::string name1 = "sonaccount" + fc::to_pretty_string(i);
|
||||||
|
std::string name2 = "sonaccount" + fc::to_pretty_string(i + 1);
|
||||||
|
vote_tx = con.wallet_api_ptr->vote_for_son(name1, name2, true, true);
|
||||||
|
}
|
||||||
|
BOOST_CHECK(generate_maintenance_block());
|
||||||
|
gpo = con.wallet_api_ptr->get_global_properties();
|
||||||
|
BOOST_TEST_MESSAGE("gpo: " << gpo.active_sons.size());
|
||||||
|
|
||||||
|
BOOST_CHECK(gpo.active_sons.size() == son_number);
|
||||||
|
|
||||||
|
map<string, son_id_type> active_sons = con.wallet_api_ptr->list_active_sons();
|
||||||
|
BOOST_CHECK(active_sons.size() == son_number);
|
||||||
|
for(unsigned int i = 1; i < son_number + 1; i++)
|
||||||
|
{
|
||||||
|
std::string name = "sonaccount" + fc::to_pretty_string(i);
|
||||||
|
BOOST_CHECK(active_sons.find(name) != active_sons.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch( fc::exception& e ) {
|
||||||
|
BOOST_TEST_MESSAGE("SON cli wallet tests exception");
|
||||||
|
edump((e.to_detail_string()));
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
BOOST_TEST_MESSAGE("SON cli wallet tests for list_active_sons end");
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue