From 392d808af0cae7d427d56ff6a0e3f7fde2e1d149 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Tue, 25 Apr 2023 12:29:09 +0200 Subject: [PATCH] feat: `GetAccountsByKeyUID` endpoint added --- services/accounts/accounts.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/services/accounts/accounts.go b/services/accounts/accounts.go index b8a08f886..ce931c751 100644 --- a/services/accounts/accounts.go +++ b/services/accounts/accounts.go @@ -48,12 +48,7 @@ func (api *API) SaveAccount(ctx context.Context, account *accounts.Account) erro return nil } -func (api *API) GetAccounts(ctx context.Context) ([]*accounts.Account, error) { - accounts, err := api.db.GetAccounts() - if err != nil { - return nil, err - } - +func (api *API) checkDerivedFromField(accounts []*accounts.Account) ([]*accounts.Account, error) { for i := range accounts { account := accounts[i] if account.Wallet && account.DerivedFrom == "" { @@ -64,10 +59,27 @@ func (api *API) GetAccounts(ctx context.Context) ([]*accounts.Account, error) { account.DerivedFrom = address.Hex() } } - return accounts, nil } +func (api *API) GetAccounts(ctx context.Context) ([]*accounts.Account, error) { + accounts, err := api.db.GetAccounts() + if err != nil { + return nil, err + } + + return api.checkDerivedFromField(accounts) +} + +func (api *API) GetAccountsByKeyUID(ctx context.Context, keyUID string) ([]*accounts.Account, error) { + accounts, err := api.db.GetAccountsByKeyUID(keyUID) + if err != nil { + return nil, err + } + + return api.checkDerivedFromField(accounts) +} + func (api *API) DeleteAccount(ctx context.Context, address types.Address, password string) error { acc, err := api.db.GetAccountByAddress(address) if err != nil {