github.com/koko1123/flow-go-1@v0.29.6/engine/access/rest/transactions.go (about) 1 package rest 2 3 import ( 4 "github.com/koko1123/flow-go-1/access" 5 "github.com/koko1123/flow-go-1/engine/access/rest/models" 6 "github.com/koko1123/flow-go-1/engine/access/rest/request" 7 ) 8 9 // GetTransactionByID gets a transaction by requested ID. 10 func GetTransactionByID(r *request.Request, backend access.API, link models.LinkGenerator) (interface{}, error) { 11 req, err := r.GetTransactionRequest() 12 if err != nil { 13 return nil, NewBadRequestError(err) 14 } 15 16 tx, err := backend.GetTransaction(r.Context(), req.ID) 17 if err != nil { 18 return nil, err 19 } 20 21 var txr *access.TransactionResult 22 // only lookup result if transaction result is to be expanded 23 if req.ExpandsResult { 24 txr, err = backend.GetTransactionResult(r.Context(), req.ID) 25 if err != nil { 26 return nil, err 27 } 28 } 29 30 var response models.Transaction 31 response.Build(tx, txr, link) 32 return response, nil 33 } 34 35 // GetTransactionResultByID retrieves transaction result by the transaction ID. 36 func GetTransactionResultByID(r *request.Request, backend access.API, link models.LinkGenerator) (interface{}, error) { 37 req, err := r.GetTransactionResultRequest() 38 if err != nil { 39 return nil, NewBadRequestError(err) 40 } 41 42 txr, err := backend.GetTransactionResult(r.Context(), req.ID) 43 if err != nil { 44 return nil, err 45 } 46 47 var response models.TransactionResult 48 response.Build(txr, req.ID, link) 49 return response, nil 50 } 51 52 // CreateTransaction creates a new transaction from provided payload. 53 func CreateTransaction(r *request.Request, backend access.API, link models.LinkGenerator) (interface{}, error) { 54 req, err := r.CreateTransactionRequest() 55 if err != nil { 56 return nil, NewBadRequestError(err) 57 } 58 59 err = backend.SendTransaction(r.Context(), &req.Transaction) 60 if err != nil { 61 return nil, err 62 } 63 64 var response models.Transaction 65 response.Build(&req.Transaction, nil, link) 66 return response, nil 67 }