From e170676ff94477d935a29513ca48f8cbaf391fb5 Mon Sep 17 00:00:00 2001 From: obucina <11353193+obucina@users.noreply.github.com> Date: Fri, 27 Mar 2020 14:40:37 +0100 Subject: [PATCH] [SON-312] Refactor create_son to assign owner account public key as a signing_key remove key derivation from create son (#323) Co-authored-by: Alfredo Garcia --- .../wallet/include/graphene/wallet/wallet.hpp | 3 +- libraries/wallet/wallet.cpp | 42 +------------------ 2 files changed, 2 insertions(+), 43 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 364fb20b..277d1f23 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -188,7 +188,6 @@ 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; @@ -2121,7 +2120,7 @@ FC_REFLECT( graphene::wallet::wallet_data, (my_accounts) (cipher_keys) (extra_keys) - (pending_account_registrations)(pending_witness_registrations)(pending_son_registrations) + (pending_account_registrations)(pending_witness_registrations) (labeled_keys) (blind_receipts) (committed_game_moves) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index ea2434f6..2a7a038b 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -294,23 +294,6 @@ 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) @@ -372,24 +355,6 @@ 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 @@ -1870,10 +1835,7 @@ public: { try { fc::scoped_lock lock(_resync_mutex); account_object son_account = get_account(owner_account); - fc::ecc::private_key active_private_key = get_private_key_for_account(son_account); - int son_key_index = find_first_unused_derived_key_index(active_private_key); - fc::ecc::private_key son_private_key = derive_private_key(key_to_wif(active_private_key), son_key_index); - graphene::chain::public_key_type son_public_key = son_private_key.get_public_key(); + auto son_public_key = son_account.active.get_keys()[0]; son_create_operation son_create_op; son_create_op.owner_account = son_account.id; @@ -1891,8 +1853,6 @@ public: set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees); tx.validate(); - _wallet.pending_son_registrations[owner_account] = key_to_wif(son_private_key); - return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (owner_account)(broadcast) ) }