-
Notifications
You must be signed in to change notification settings - Fork 178
/
accounts.go
33 lines (28 loc) · 1.02 KB
/
accounts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package rest
import (
"github.com/onflow/flow-go/access"
"github.com/onflow/flow-go/engine/access/rest/models"
"github.com/onflow/flow-go/engine/access/rest/request"
)
// GetAccount handler retrieves account by address and returns the response
func GetAccount(r *request.Request, backend access.API, link models.LinkGenerator) (interface{}, error) {
req, err := r.GetAccountRequest()
if err != nil {
return nil, NewBadRequestError(err)
}
// in case we receive special height values 'final' and 'sealed', fetch that height and overwrite request with it
if req.Height == request.FinalHeight || req.Height == request.SealedHeight {
header, err := backend.GetLatestBlockHeader(r.Context(), req.Height == request.SealedHeight)
if err != nil {
return nil, err
}
req.Height = header.Height
}
account, err := backend.GetAccountAtBlockHeight(r.Context(), req.Address, req.Height)
if err != nil {
return nil, err
}
var response models.Account
err = response.Build(account, link, r.ExpandFields)
return response, err
}