feat: `GetAccountsByKeyUID` endpoint added

This commit is contained in:
Sale Djenic 2023-04-25 12:29:09 +02:00 committed by saledjenic
parent c8ef2c1a7f
commit 392d808af0
1 changed files with 19 additions and 7 deletions

View File

@ -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 {