github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/access/rest/routes/scripts.go (about) 1 package routes 2 3 import ( 4 "github.com/onflow/flow-go/access" 5 "github.com/onflow/flow-go/engine/access/rest/models" 6 "github.com/onflow/flow-go/engine/access/rest/request" 7 "github.com/onflow/flow-go/model/flow" 8 ) 9 10 // ExecuteScript handler sends the script from the request to be executed. 11 func ExecuteScript(r *request.Request, backend access.API, _ models.LinkGenerator) (interface{}, error) { 12 req, err := r.GetScriptRequest() 13 if err != nil { 14 return nil, models.NewBadRequestError(err) 15 } 16 17 if req.BlockID != flow.ZeroID { 18 return backend.ExecuteScriptAtBlockID(r.Context(), req.BlockID, req.Script.Source, req.Script.Args) 19 } 20 21 // default to sealed height 22 if req.BlockHeight == request.SealedHeight || req.BlockHeight == request.EmptyHeight { 23 return backend.ExecuteScriptAtLatestBlock(r.Context(), req.Script.Source, req.Script.Args) 24 } 25 26 if req.BlockHeight == request.FinalHeight { 27 finalBlock, _, err := backend.GetLatestBlockHeader(r.Context(), false) 28 if err != nil { 29 return nil, err 30 } 31 req.BlockHeight = finalBlock.Height 32 } 33 34 return backend.ExecuteScriptAtBlockHeight(r.Context(), req.BlockHeight, req.Script.Source, req.Script.Args) 35 }