Skip to content

Commit

Permalink
code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zkokelj committed Nov 23, 2023
1 parent 7dd2351 commit dd679c9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
5 changes: 2 additions & 3 deletions tools/walletextension/container/walletextension_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,17 @@ func NewWalletExtensionContainerFromConfig(config config.Config, logger gethlog.
unAuthedClient, err := rpc.NewNetworkClient(hostRPCBindAddr)
if err != nil {
logger.Crit("unable to create temporary client for request ", log.ErrKey, err)
os.Exit(1)
}

// start the database
databaseStorage, err := storage.New(config.DBType, config.DBConnectionURL, config.DBPathOverride)
if err != nil {
logger.Crit("unable to create database to store viewing keys ", log.ErrKey, err)
os.Exit(1)
}
userAccountManager := useraccountmanager.NewUserAccountManager(unAuthedClient, logger, databaseStorage, hostRPCBindAddr)

// Get all the data from the database and add all the clients for all users
// todo (@ziga) - implement lazy loading for clients to reduce number of connections and speed up loading

// add default user (when no UserID is provided in the query parameter - for WE endpoints)
userAccountManager.AddAndReturnAccountManager(hex.EncodeToString([]byte(wecommon.DefaultUser)))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ func (m *UserAccountManager) GetUserAccountManager(userID string) (*accountmanag
}

// log that we don't have a storage, but still return existing userAccountManager
// this should never happen, but is useful for tests
if m.storage == nil {
m.logger.Error("storage is nil in UserAccountManager")
return userAccManager, nil
}

databseAccounts, err := m.storage.GetAccounts(userIDbytes)
databaseAccounts, err := m.storage.GetAccounts(userIDbytes)
if err != nil {
return nil, err
}
Expand All @@ -78,7 +79,7 @@ func (m *UserAccountManager) GetUserAccountManager(userID string) (*accountmanag
return nil, err
}

for _, account := range databseAccounts {
for _, account := range databaseAccounts {
addressHexString := common.BytesToAddress(account.AccountAddress).Hex()
// check if a client for the current address already exists (and skip it if it does)
if addressAlreadyExists(addressHexString, addressesWithClients) {
Expand Down
10 changes: 5 additions & 5 deletions tools/walletextension/wallet_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ func (w *WalletExtension) SubmitViewingKey(address gethcommon.Address, signature
signature[64] -= 27

vk.Signature = signature

err := w.storage.AddUser([]byte(common.DefaultUser), crypto.FromECDSA(vk.PrivateKey.ExportECDSA()))
if err != nil {
return fmt.Errorf("error saving user: %s", common.DefaultUser)
}
// create an encrypted RPC client with the signed VK and register it with the enclave
// todo (@ziga) - Create the clients lazily, to reduce connections to the host.
client, err := rpc.NewEncNetworkClient(w.hostAddr, vk, w.logger)
Expand All @@ -157,11 +162,6 @@ func (w *WalletExtension) SubmitViewingKey(address gethcommon.Address, signature

defaultAccountManager.AddClient(address, client)

err = w.storage.AddUser([]byte(common.DefaultUser), crypto.FromECDSA(vk.PrivateKey.ExportECDSA()))
if err != nil {
return fmt.Errorf("error saving user: %s", common.DefaultUser)
}

err = w.storage.AddAccount([]byte(common.DefaultUser), vk.Account.Bytes(), vk.Signature)
if err != nil {
return fmt.Errorf("error saving account %s for user %s", vk.Account.Hex(), common.DefaultUser)
Expand Down

0 comments on commit dd679c9

Please sign in to comment.