feat: `AddressExists` endpoint added

This commit is contained in:
Sale Djenic 2023-05-25 11:53:15 +02:00 committed by saledjenic
parent ee4003279a
commit 03d9af0b95
1 changed files with 10 additions and 12 deletions

View File

@ -477,36 +477,34 @@ func (api *API) getDerivedAddresses(id string, paths []string) ([]*DerivedAddres
return derivedAddresses, nil return derivedAddresses, nil
} }
func (api *API) AddressExists(ctx context.Context, address types.Address) (bool, error) {
return api.s.accountsDB.AddressExists(address)
}
// Returns details for the passed address (response doesn't include derivation path) // Returns details for the passed address (response doesn't include derivation path)
func (api *API) GetAddressDetails(ctx context.Context, chainID uint64, address string) (*DerivedAddress, error) { func (api *API) GetAddressDetails(ctx context.Context, chainID uint64, address string) (*DerivedAddress, error) {
var derivedAddress *DerivedAddress
commonAddr := common.HexToAddress(address) commonAddr := common.HexToAddress(address)
addressExists, err := api.s.accountsDB.AddressExists(types.Address(commonAddr)) addressExists, err := api.s.accountsDB.AddressExists(types.Address(commonAddr))
if err != nil { if err != nil {
return derivedAddress, err return nil, err
} }
chainClient, err := api.s.rpcClient.EthClient(chainID) chainClient, err := api.s.rpcClient.EthClient(chainID)
if err != nil { if err != nil {
return derivedAddress, err return nil, err
} }
balance, err := api.s.tokenManager.GetChainBalance(ctx, chainClient, commonAddr) balance, err := api.s.tokenManager.GetChainBalance(ctx, chainClient, commonAddr)
if err != nil { if err != nil {
return derivedAddress, err return nil, err
} }
hasActivity := balance.Cmp(big.NewInt(0)) != 0 return &DerivedAddress{
derivedAddress = &DerivedAddress{
Address: commonAddr, Address: commonAddr,
Path: "", Path: "",
HasActivity: hasActivity,
AlreadyCreated: addressExists, AlreadyCreated: addressExists,
} HasActivity: balance.Cmp(big.NewInt(0)) != 0,
}, nil
return derivedAddress, nil
} }
func (api *API) CreateMultiTransaction(ctx context.Context, multiTransaction *transfer.MultiTransaction, data []*bridge.TransactionBridge, password string) (*transfer.MultiTransactionResult, error) { func (api *API) CreateMultiTransaction(ctx context.Context, multiTransaction *transfer.MultiTransaction, data []*bridge.TransactionBridge, password string) (*transfer.MultiTransactionResult, error) {