github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/admin/commands/storage/read_transactions.go (about) 1 package storage 2 3 import ( 4 "context" 5 6 "github.com/rs/zerolog/log" 7 8 "github.com/onflow/flow-go/admin" 9 "github.com/onflow/flow-go/admin/commands" 10 "github.com/onflow/flow-go/cmd/util/cmd/export-json-transactions/transactions" 11 "github.com/onflow/flow-go/state/protocol" 12 "github.com/onflow/flow-go/storage" 13 ) 14 15 var _ commands.AdminCommand = (*GetTransactionsCommand)(nil) 16 17 type heightRangeReqData struct { 18 startHeight uint64 19 endHeight uint64 20 } 21 22 func (d heightRangeReqData) Range() uint64 { 23 return d.endHeight - d.startHeight + 1 24 } 25 26 type GetTransactionsCommand struct { 27 state protocol.State 28 payloads storage.Payloads 29 collections storage.Collections 30 } 31 32 func NewGetTransactionsCommand(state protocol.State, payloads storage.Payloads, collections storage.Collections) *GetTransactionsCommand { 33 return &GetTransactionsCommand{ 34 state: state, 35 payloads: payloads, 36 collections: collections, 37 } 38 } 39 40 func (c *GetTransactionsCommand) Handler(ctx context.Context, req *admin.CommandRequest) (interface{}, error) { 41 data := req.ValidatorData.(*heightRangeReqData) 42 43 limit := uint64(10001) 44 if data.Range() > limit { 45 return nil, admin.NewInvalidAdminReqErrorf("getting transactions for more than %v blocks at a time might have an impact to node's performance and is not allowed", limit) 46 } 47 48 finder := &transactions.Finder{ 49 State: c.state, 50 Payloads: c.payloads, 51 Collections: c.collections, 52 } 53 54 log.Info().Str("module", "admin-tool").Msgf("get transactions for height range [%v, %v]", 55 data.startHeight, data.endHeight) 56 blocks, err := finder.GetByHeightRange(data.startHeight, data.endHeight) 57 if err != nil { 58 return nil, err 59 } 60 61 return commands.ConvertToInterfaceList(blocks) 62 } 63 64 // Validator validates the request. 65 // Returns admin.InvalidAdminReqError for invalid/malformed requests. 66 func (c *GetTransactionsCommand) Validator(req *admin.CommandRequest) error { 67 data, err := parseHeightRangeRequestData(req) 68 if err != nil { 69 return err 70 } 71 req.ValidatorData = data 72 return nil 73 }