WIP, SON operations, cli_wallet commands and RPC

- claim_registered_son
- some renaming, to follow existing naming convention
This commit is contained in:
Srdjan Obucina 2019-10-02 18:28:07 +02:00
parent 3a65102e56
commit 44f185e0c2
8 changed files with 54 additions and 19 deletions

View file

@ -1613,7 +1613,7 @@ fc::optional<son_object> database_api::get_son_by_account(account_id_type accoun
fc::optional<son_object> database_api_impl::get_son_by_account(account_id_type account) const fc::optional<son_object> database_api_impl::get_son_by_account(account_id_type account) const
{ {
const auto& idx = _db.get_index_type<son_member_index>().indices().get<by_account>(); const auto& idx = _db.get_index_type<son_index>().indices().get<by_account>();
auto itr = idx.find(account); auto itr = idx.find(account);
if( itr != idx.end() ) if( itr != idx.end() )
return *itr; return *itr;
@ -1628,7 +1628,7 @@ map<string, son_id_type> database_api::lookup_son_accounts(const string& lower_b
map<string, son_id_type> database_api_impl::lookup_son_accounts(const string& lower_bound_name, uint32_t limit)const map<string, son_id_type> database_api_impl::lookup_son_accounts(const string& lower_bound_name, uint32_t limit)const
{ {
FC_ASSERT( limit <= 1000 ); FC_ASSERT( limit <= 1000 );
const auto& sons_by_id = _db.get_index_type<son_member_index>().indices().get<by_id>(); 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 // 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_member_index doesn't have a quick way to access it.
@ -1655,7 +1655,7 @@ uint64_t database_api::get_son_count()const
uint64_t database_api_impl::get_son_count()const uint64_t database_api_impl::get_son_count()const
{ {
return _db.get_index_type<son_member_index>().indices().size(); return _db.get_index_type<son_index>().indices().size();
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@ -1677,7 +1677,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& 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& 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& against_worker_idx = _db.get_index_type<worker_index>().indices().get<by_vote_against>();
const auto& son_idx = _db.get_index_type<son_member_index>().indices().get<by_vote_id>(); const auto& son_idx = _db.get_index_type<son_index>().indices().get<by_vote_id>();
vector<variant> result; vector<variant> result;
result.reserve( votes.size() ); result.reserve( votes.size() );

View file

@ -305,7 +305,7 @@ void database::initialize_indexes()
add_index< primary_index<pending_dividend_payout_balance_for_holder_object_index > >(); add_index< primary_index<pending_dividend_payout_balance_for_holder_object_index > >();
add_index< primary_index<total_distributed_dividend_balance_object_index > >(); add_index< primary_index<total_distributed_dividend_balance_object_index > >();
add_index< primary_index<son_member_index> >(); add_index< primary_index<son_index> >();
} }
void database::init_genesis(const genesis_state_type& genesis_state) void database::init_genesis(const genesis_state_type& genesis_state)

View file

@ -53,7 +53,7 @@ namespace graphene { namespace chain {
flat_set<witness_id_type> active_witnesses; // updated once per maintenance interval flat_set<witness_id_type> active_witnesses; // updated once per maintenance interval
// n.b. witness scheduling is done by witness_schedule object // n.b. witness scheduling is done by witness_schedule object
flat_set<son_id_type> active_son_members; // updated once per maintenance interval flat_set<son_id_type> active_sons; // updated once per maintenance interval
}; };
/** /**

View file

@ -42,7 +42,7 @@ namespace graphene { namespace chain {
> >
> >
>; >;
using son_member_index = generic_index<son_object, son_member_multi_index_type>; using son_index = generic_index<son_object, son_member_multi_index_type>;
} } // graphene::chain } } // graphene::chain
FC_REFLECT_DERIVED( graphene::chain::son_object, (graphene::db::object), FC_REFLECT_DERIVED( graphene::chain::son_object, (graphene::db::object),

View file

@ -35,14 +35,14 @@ void_result update_son_evaluator::do_evaluate(const son_update_operation& op)
{ try { { 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().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_member_account == op.owner_account);
const auto& idx = db().get_index_type<son_member_index>().indices().get<by_id>(); const auto& idx = db().get_index_type<son_index>().indices().get<by_id>();
FC_ASSERT( idx.find(op.son_id) != idx.end() ); FC_ASSERT( idx.find(op.son_id) != idx.end() );
return void_result(); return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) } } FC_CAPTURE_AND_RETHROW( (op) ) }
object_id_type update_son_evaluator::do_apply(const son_update_operation& op) object_id_type update_son_evaluator::do_apply(const son_update_operation& op)
{ try { { try {
const auto& idx = db().get_index_type<son_member_index>().indices().get<by_id>(); const auto& idx = db().get_index_type<son_index>().indices().get<by_id>();
auto itr = idx.find(op.son_id); auto itr = idx.find(op.son_id);
if(itr != idx.end()) if(itr != idx.end())
{ {
@ -60,14 +60,14 @@ void_result delete_son_evaluator::do_evaluate(const son_delete_operation& op)
{ try { { 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().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_member_account == op.owner_account);
const auto& idx = db().get_index_type<son_member_index>().indices().get<by_id>(); const auto& idx = db().get_index_type<son_index>().indices().get<by_id>();
FC_ASSERT( idx.find(op.son_id) != idx.end() ); FC_ASSERT( idx.find(op.son_id) != idx.end() );
return void_result(); return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) } } FC_CAPTURE_AND_RETHROW( (op) ) }
void_result delete_son_evaluator::do_apply(const son_delete_operation& op) void_result delete_son_evaluator::do_apply(const son_delete_operation& op)
{ try { { try {
const auto& idx = db().get_index_type<son_member_index>().indices().get<by_id>(); const auto& idx = db().get_index_type<son_index>().indices().get<by_id>();
db().remove(*idx.find(op.son_id)); db().remove(*idx.find(op.son_id));
return void_result(); return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) } } FC_CAPTURE_AND_RETHROW( (op) ) }

View file

@ -188,6 +188,7 @@ struct wallet_data
// incomplete account regs // incomplete account regs
map<string, vector<string> > pending_account_registrations; map<string, vector<string> > pending_account_registrations;
map<string, string> pending_witness_registrations; map<string, string> pending_witness_registrations;
map<string, string> pending_son_registrations;
key_label_index_type labeled_keys; key_label_index_type labeled_keys;
blind_receipt_index_type blind_receipts; blind_receipt_index_type blind_receipts;
@ -1932,7 +1933,7 @@ FC_REFLECT( graphene::wallet::wallet_data,
(my_accounts) (my_accounts)
(cipher_keys) (cipher_keys)
(extra_keys) (extra_keys)
(pending_account_registrations)(pending_witness_registrations) (pending_account_registrations)(pending_witness_registrations)(pending_son_registrations)
(labeled_keys) (labeled_keys)
(blind_receipts) (blind_receipts)
(committed_game_moves) (committed_game_moves)

View file

@ -292,6 +292,23 @@ private:
_wallet.pending_account_registrations.erase( it ); _wallet.pending_account_registrations.erase( it );
} }
// after a son registration succeeds, this saves the private key in the wallet permanently
//
void claim_registered_son(const std::string& son_name)
{
auto iter = _wallet.pending_son_registrations.find(son_name);
FC_ASSERT(iter != _wallet.pending_son_registrations.end());
std::string wif_key = iter->second;
// get the list key id this key is registered with in the chain
fc::optional<fc::ecc::private_key> son_private_key = wif_to_key(wif_key);
FC_ASSERT(son_private_key);
auto pub_key = son_private_key->get_public_key();
_keys[pub_key] = wif_key;
_wallet.pending_son_registrations.erase(iter);
}
// after a witness registration succeeds, this saves the private key in the wallet permanently // after a witness registration succeeds, this saves the private key in the wallet permanently
// //
void claim_registered_witness(const std::string& witness_name) void claim_registered_witness(const std::string& witness_name)
@ -353,6 +370,24 @@ private:
claim_registered_witness(optional_account->name); claim_registered_witness(optional_account->name);
} }
} }
if (!_wallet.pending_son_registrations.empty())
{
// make a vector of the owner accounts for sons pending registration
std::vector<string> pending_son_names = boost::copy_range<std::vector<string> >(boost::adaptors::keys(_wallet.pending_son_registrations));
// look up the owners on the blockchain
std::vector<fc::optional<graphene::chain::account_object>> owner_account_objects = _remote_db->lookup_account_names(pending_son_names);
// if any of them have registered sons, claim them
for( const fc::optional<graphene::chain::account_object>& optional_account : owner_account_objects )
if (optional_account)
{
fc::optional<son_object> son_obj = _remote_db->get_son_by_account(optional_account->id);
if (son_obj)
claim_registered_son(optional_account->name);
}
}
} }
// return true if any of my_accounts are players in this tournament // return true if any of my_accounts are players in this tournament
@ -665,6 +700,7 @@ public:
result["participation"] = (100*dynamic_props.recent_slots_filled.popcount()) / 128.0; result["participation"] = (100*dynamic_props.recent_slots_filled.popcount()) / 128.0;
result["active_witnesses"] = global_props.active_witnesses; result["active_witnesses"] = global_props.active_witnesses;
result["active_committee_members"] = global_props.active_committee_members; result["active_committee_members"] = global_props.active_committee_members;
result["active_sons"] = global_props.active_sons;
result["entropy"] = dynamic_props.random; result["entropy"] = dynamic_props.random;
return result; return result;
} }
@ -1807,8 +1843,6 @@ public:
secret_hash_type::encoder enc; secret_hash_type::encoder enc;
fc::raw::pack(enc, son_private_key); fc::raw::pack(enc, son_private_key);
fc::raw::pack(enc, secret_hash_type()); fc::raw::pack(enc, secret_hash_type());
//son_create_op.initial_secret = secret_hash_type::hash(enc.result());
if (_remote_db->get_son_by_account(son_create_op.owner_account)) if (_remote_db->get_son_by_account(son_create_op.owner_account))
FC_THROW("Account ${owner_account} is already a SON", ("owner_account", owner_account)); FC_THROW("Account ${owner_account} is already a SON", ("owner_account", owner_account));
@ -1818,7 +1852,7 @@ public:
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees); set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate(); tx.validate();
//_wallet.pending_witness_registrations[owner_account] = key_to_wif(son_private_key); _wallet.pending_son_registrations[owner_account] = key_to_wif(son_private_key);
return sign_transaction( tx, broadcast ); return sign_transaction( tx, broadcast );
} FC_CAPTURE_AND_RETHROW( (owner_account)(broadcast) ) } } FC_CAPTURE_AND_RETHROW( (owner_account)(broadcast) ) }

View file

@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE( create_son_test ) {
} }
generate_block(); generate_block();
const auto& idx = db.get_index_type<son_member_index>().indices().get<by_account>(); const auto& idx = db.get_index_type<son_index>().indices().get<by_account>();
BOOST_REQUIRE( idx.size() == 1 ); BOOST_REQUIRE( idx.size() == 1 );
auto obj = idx.find( alice_id ); auto obj = idx.find( alice_id );
BOOST_REQUIRE( obj != idx.end() ); BOOST_REQUIRE( obj != idx.end() );
@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE( update_son_test ) {
} }
generate_block(); generate_block();
const auto& idx = db.get_index_type<son_member_index>().indices().get<by_account>(); const auto& idx = db.get_index_type<son_index>().indices().get<by_account>();
BOOST_REQUIRE( idx.size() == 1 ); BOOST_REQUIRE( idx.size() == 1 );
auto obj = idx.find( alice_id ); auto obj = idx.find( alice_id );
BOOST_REQUIRE( obj != idx.end() ); BOOST_REQUIRE( obj != idx.end() );
@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE( delete_son_test ) {
} }
generate_block(); generate_block();
const auto& idx = db.get_index_type<son_member_index>().indices().get<by_account>(); const auto& idx = db.get_index_type<son_index>().indices().get<by_account>();
BOOST_REQUIRE( idx.empty() ); BOOST_REQUIRE( idx.empty() );
} }
@ -153,7 +153,7 @@ try {
set_expiration(db, trx); set_expiration(db, trx);
trx.clear(); trx.clear();
const auto& idx = db.get_index_type<son_member_index>().indices().get<by_account>(); const auto& idx = db.get_index_type<son_index>().indices().get<by_account>();
auto obj = idx.find( alice_id ); auto obj = idx.find( alice_id );
BOOST_REQUIRE( obj != idx.end() ); BOOST_REQUIRE( obj != idx.end() );
// not changing // not changing