Skip to content

Commit

Permalink
api: endpoint /accounts/{accountId} now includes transfersCount and f…
Browse files Browse the repository at this point in the history
…eesCount
  • Loading branch information
altergui committed Aug 7, 2024
1 parent 1acfb35 commit 2491a75
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
26 changes: 19 additions & 7 deletions api/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
18 changes: 10 additions & 8 deletions api/api_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")}
)

0 comments on commit 2491a75

Please sign in to comment.