From 2491a75f6c7e7f1183565abca6bf7176b2248cbe Mon Sep 17 00:00:00 2001 From: Gui Iribarren Date: Wed, 7 Aug 2024 13:19:57 +0200 Subject: [PATCH] api: endpoint /accounts/{accountId} now includes transfersCount and feesCount --- api/accounts.go | 26 +++++++++++++++++++------- api/api_types.go | 18 ++++++++++-------- api/errors.go | 1 + 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/api/accounts.go b/api/accounts.go index baab86251..5e82e6741 100644 --- a/api/accounts.go +++ b/api/accounts.go @@ -193,15 +193,27 @@ func (a *API) accountHandler(_ *apirest.APIdata, ctx *httprouter.HTTPContext) er return ErrGettingSIK.WithErr(err) } + _, transfersCount, err := a.indexer.TokenTransfersList(1, 0, hex.EncodeToString(addr.Bytes()), "", "") + if err != nil { + return ErrCantFetchTokenTransfers.WithErr(err) + } + + _, feesCount, err := a.indexer.TokenFeesList(1, 0, "", "", hex.EncodeToString(addr.Bytes())) + if err != nil { + return ErrCantFetchTokenFees.WithErr(err) + } + var data []byte if data, err = json.Marshal(Account{ - Address: addr.Bytes(), - Nonce: acc.GetNonce(), - Balance: acc.GetBalance(), - ElectionIndex: acc.GetProcessIndex(), - InfoURL: acc.GetInfoURI(), - Metadata: accMetadata, - SIK: types.HexBytes(sik), + Address: addr.Bytes(), + Nonce: acc.GetNonce(), + Balance: acc.GetBalance(), + ElectionIndex: acc.GetProcessIndex(), + TransfersCount: transfersCount, + FeesCount: feesCount, + InfoURL: acc.GetInfoURI(), + Metadata: accMetadata, + SIK: types.HexBytes(sik), }); err != nil { return err } diff --git a/api/api_types.go b/api/api_types.go index 778b8a9cc..e3b3ddd1c 100644 --- a/api/api_types.go +++ b/api/api_types.go @@ -305,14 +305,16 @@ type ChainInfo struct { } type Account struct { - Address types.HexBytes `json:"address" ` - Nonce uint32 `json:"nonce"` - Balance uint64 `json:"balance"` - ElectionIndex uint32 `json:"electionIndex"` - InfoURL string `json:"infoURL,omitempty"` - Token *uuid.UUID `json:"token,omitempty" swaggerignore:"true"` - Metadata *AccountMetadata `json:"metadata,omitempty"` - SIK types.HexBytes `json:"sik"` + Address types.HexBytes `json:"address" ` + Nonce uint32 `json:"nonce"` + Balance uint64 `json:"balance"` + ElectionIndex uint32 `json:"electionIndex"` + TransfersCount uint64 `json:"transfersCount,omitempty"` + FeesCount uint64 `json:"feesCount,omitempty"` + InfoURL string `json:"infoURL,omitempty"` + Token *uuid.UUID `json:"token,omitempty" swaggerignore:"true"` + Metadata *AccountMetadata `json:"metadata,omitempty"` + SIK types.HexBytes `json:"sik"` } type AccountsList struct { diff --git a/api/errors.go b/api/errors.go index f4df72b7c..3d4e4c31b 100644 --- a/api/errors.go +++ b/api/errors.go @@ -115,4 +115,5 @@ var ( ErrGettingSIK = apirest.APIerror{Code: 5031, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error getting SIK")} ErrCensusBuild = apirest.APIerror{Code: 5032, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error building census")} ErrIndexerQueryFailed = apirest.APIerror{Code: 5033, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("indexer query failed")} + ErrCantFetchTokenFees = apirest.APIerror{Code: 5034, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot fetch token fees")} )