diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index facf6d14..52640d88 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -1613,7 +1613,7 @@ fc::optional database_api::get_son_by_account(account_id_type accoun fc::optional database_api_impl::get_son_by_account(account_id_type account) const { - const auto& idx = _db.get_index_type().indices().get(); + const auto& idx = _db.get_index_type().indices().get(); auto itr = idx.find(account); if( itr != idx.end() ) return *itr; @@ -1628,7 +1628,7 @@ map database_api::lookup_son_accounts(const string& lower_b map 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().indices().get(); + const auto& sons_by_id = _db.get_index_type().indices().get(); // 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. @@ -1655,7 +1655,7 @@ uint64_t database_api::get_son_count()const uint64_t database_api_impl::get_son_count()const { - return _db.get_index_type().indices().size(); + return _db.get_index_type().indices().size(); } ////////////////////////////////////////////////////////////////////// @@ -1677,7 +1677,7 @@ vector database_api_impl::lookup_vote_ids( const vector& const auto& committee_idx = _db.get_index_type().indices().get(); const auto& for_worker_idx = _db.get_index_type().indices().get(); const auto& against_worker_idx = _db.get_index_type().indices().get(); - const auto& son_idx = _db.get_index_type().indices().get(); + const auto& son_idx = _db.get_index_type().indices().get(); vector result; result.reserve( votes.size() ); diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 7c949c6f..5e7ab107 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -305,7 +305,7 @@ void database::initialize_indexes() add_index< primary_index >(); add_index< primary_index >(); - add_index< primary_index >(); + add_index< primary_index >(); } void database::init_genesis(const genesis_state_type& genesis_state) diff --git a/libraries/chain/include/graphene/chain/global_property_object.hpp b/libraries/chain/include/graphene/chain/global_property_object.hpp index 771e912c..b976eea0 100644 --- a/libraries/chain/include/graphene/chain/global_property_object.hpp +++ b/libraries/chain/include/graphene/chain/global_property_object.hpp @@ -53,7 +53,7 @@ namespace graphene { namespace chain { flat_set active_witnesses; // updated once per maintenance interval // n.b. witness scheduling is done by witness_schedule object - flat_set active_son_members; // updated once per maintenance interval + flat_set active_sons; // updated once per maintenance interval }; /** diff --git a/libraries/chain/include/graphene/chain/son_object.hpp b/libraries/chain/include/graphene/chain/son_object.hpp index 92d21b31..02224944 100644 --- a/libraries/chain/include/graphene/chain/son_object.hpp +++ b/libraries/chain/include/graphene/chain/son_object.hpp @@ -42,7 +42,7 @@ namespace graphene { namespace chain { > > >; - using son_member_index = generic_index; + using son_index = generic_index; } } // graphene::chain FC_REFLECT_DERIVED( graphene::chain::son_object, (graphene::db::object), diff --git a/libraries/chain/son_evaluator.cpp b/libraries/chain/son_evaluator.cpp index 8ac0cb24..821739bb 100644 --- a/libraries/chain/son_evaluator.cpp +++ b/libraries/chain/son_evaluator.cpp @@ -35,14 +35,14 @@ 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); - const auto& idx = db().get_index_type().indices().get(); + const auto& idx = db().get_index_type().indices().get(); FC_ASSERT( idx.find(op.son_id) != idx.end() ); return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } object_id_type update_son_evaluator::do_apply(const son_update_operation& op) { try { - const auto& idx = db().get_index_type().indices().get(); + const auto& idx = db().get_index_type().indices().get(); auto itr = idx.find(op.son_id); if(itr != idx.end()) { @@ -60,14 +60,14 @@ 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); - const auto& idx = db().get_index_type().indices().get(); + const auto& idx = db().get_index_type().indices().get(); FC_ASSERT( idx.find(op.son_id) != idx.end() ); return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } void_result delete_son_evaluator::do_apply(const son_delete_operation& op) { try { - const auto& idx = db().get_index_type().indices().get(); + const auto& idx = db().get_index_type().indices().get(); db().remove(*idx.find(op.son_id)); return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 741c1764..1005e634 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -188,6 +188,7 @@ struct wallet_data // incomplete account regs map > pending_account_registrations; map pending_witness_registrations; + map pending_son_registrations; key_label_index_type labeled_keys; blind_receipt_index_type blind_receipts; @@ -1932,7 +1933,7 @@ FC_REFLECT( graphene::wallet::wallet_data, (my_accounts) (cipher_keys) (extra_keys) - (pending_account_registrations)(pending_witness_registrations) + (pending_account_registrations)(pending_witness_registrations)(pending_son_registrations) (labeled_keys) (blind_receipts) (committed_game_moves) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 3f9c4eda..39a1998c 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -292,6 +292,23 @@ private: _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 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 // void claim_registered_witness(const std::string& witness_name) @@ -353,6 +370,24 @@ private: 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 pending_son_names = boost::copy_range >(boost::adaptors::keys(_wallet.pending_son_registrations)); + + // look up the owners on the blockchain + std::vector> owner_account_objects = _remote_db->lookup_account_names(pending_son_names); + + // if any of them have registered sons, claim them + for( const fc::optional& optional_account : owner_account_objects ) + if (optional_account) + { + fc::optional 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 @@ -665,6 +700,7 @@ public: result["participation"] = (100*dynamic_props.recent_slots_filled.popcount()) / 128.0; 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; } @@ -1807,8 +1843,6 @@ public: secret_hash_type::encoder enc; fc::raw::pack(enc, son_private_key); 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)) 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); 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 ); } FC_CAPTURE_AND_RETHROW( (owner_account)(broadcast) ) } diff --git a/tests/tests/son_operations_tests.cpp b/tests/tests/son_operations_tests.cpp index 75986ca7..1b8f1cbc 100644 --- a/tests/tests/son_operations_tests.cpp +++ b/tests/tests/son_operations_tests.cpp @@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE( create_son_test ) { } generate_block(); - const auto& idx = db.get_index_type().indices().get(); + const auto& idx = db.get_index_type().indices().get(); BOOST_REQUIRE( idx.size() == 1 ); auto obj = idx.find( alice_id ); BOOST_REQUIRE( obj != idx.end() ); @@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE( update_son_test ) { } generate_block(); - const auto& idx = db.get_index_type().indices().get(); + const auto& idx = db.get_index_type().indices().get(); BOOST_REQUIRE( idx.size() == 1 ); auto obj = idx.find( alice_id ); BOOST_REQUIRE( obj != idx.end() ); @@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE( delete_son_test ) { } generate_block(); - const auto& idx = db.get_index_type().indices().get(); + const auto& idx = db.get_index_type().indices().get(); BOOST_REQUIRE( idx.empty() ); } @@ -153,7 +153,7 @@ try { set_expiration(db, trx); trx.clear(); - const auto& idx = db.get_index_type().indices().get(); + const auto& idx = db.get_index_type().indices().get(); auto obj = idx.find( alice_id ); BOOST_REQUIRE( obj != idx.end() ); // not changing