From b0b23076a01bfe04603be6f720da0499616c803e Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Fri, 21 Oct 2022 10:01:31 +0200 Subject: [PATCH] feat: `GetDerivedAddressDetails` added to accounts api --- services/wallet/api.go | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/services/wallet/api.go b/services/wallet/api.go index 8a20de734..f7c25c80c 100644 --- a/services/wallet/api.go +++ b/services/wallet/api.go @@ -363,31 +363,44 @@ func (api *API) GetDerivedAddressForPrivateKey(ctx context.Context, privateKey s return derivedAddresses, err } - addressExists, err := api.s.accountsDB.AddressExists(types.Address(common.HexToAddress(info.Address))) + derivedAddress, err := api.GetDerivedAddressDetails(ctx, info.Address) if err != nil { return derivedAddresses, err } + + derivedAddresses = append(derivedAddresses, derivedAddress) + + return derivedAddresses, nil +} + +func (api *API) GetDerivedAddressDetails(ctx context.Context, address string) (*DerivedAddress, error) { + var derivedAddress *DerivedAddress + + commonAddr := common.HexToAddress(address) + addressExists, err := api.s.accountsDB.AddressExists(types.Address(commonAddr)) + if err != nil { + return derivedAddress, err + } if addressExists { - return derivedAddresses, fmt.Errorf("account already exists") + return derivedAddress, fmt.Errorf("account already exists") } - transactions, err := api.s.transferController.GetTransfersByAddress(ctx, api.s.rpcClient.UpstreamChainID, common.HexToAddress(info.Address), nil, (*hexutil.Big)(big.NewInt(1)), false) + transactions, err := api.s.transferController.GetTransfersByAddress(ctx, api.s.rpcClient.UpstreamChainID, commonAddr, nil, (*hexutil.Big)(big.NewInt(1)), false) if err != nil { - return derivedAddresses, err + return derivedAddress, err } hasActivity := int64(len(transactions)) > 0 - derivedAddress := &DerivedAddress{ - Address: common.HexToAddress(info.Address), + derivedAddress = &DerivedAddress{ + Address: commonAddr, Path: "", HasActivity: hasActivity, AlreadyCreated: addressExists, } - derivedAddresses = append(derivedAddresses, derivedAddress) - return derivedAddresses, nil + return derivedAddress, nil } func (api *API) getDerivedAddresses(ctx context.Context, id string, path string, pageSize int, pageNumber int) ([]*DerivedAddress, error) {