@@ -127,12 +127,12 @@ func init() {
127127 handlerFunc : handleSearchTransaction ,
128128 },
129129 blockKey : {
130- regex : types .ReInteger ,
130+ regex : types .ReIntegerOrLatest ,
131131 responseType : string (blockKey ),
132132 handlerFunc : handleSearchBlock ,
133133 },
134134 slotKey : {
135- regex : types .ReInteger ,
135+ regex : types .ReIntegerOrLatest ,
136136 responseType : "slot" ,
137137 handlerFunc : handleSearchSlot ,
138138 },
@@ -147,7 +147,7 @@ func init() {
147147 handlerFunc : handleSearchSlotByStateRoot ,
148148 },
149149 epochKey : {
150- regex : types .ReInteger ,
150+ regex : types .ReIntegerOrLatest ,
151151 responseType : string (epochKey ),
152152 handlerFunc : handleSearchEpoch ,
153153 },
@@ -376,6 +376,13 @@ func handleSearchTransaction(ctx context.Context, h *HandlerService, input strin
376376}
377377
378378func handleSearchBlock (ctx context.Context , h * HandlerService , input string , chainId uint64 ) (* types.SearchResult , error ) {
379+ if input == "latest" {
380+ result , err := h .daService .GetLatestBlock (ctx )
381+ if err != nil {
382+ return nil , err
383+ }
384+ return asSearchResult (blockKey , chainId , & types.SearchBlock {BlockNumber : result }, nil )
385+ }
379386 blockNumber , err := strconv .ParseUint (input , 10 , 64 )
380387 if err != nil {
381388 return nil , err
@@ -385,6 +392,13 @@ func handleSearchBlock(ctx context.Context, h *HandlerService, input string, cha
385392}
386393
387394func handleSearchSlot (ctx context.Context , h * HandlerService , input string , chainId uint64 ) (* types.SearchResult , error ) {
395+ if input == "latest" {
396+ result , err := h .daService .GetLatestSlot (ctx )
397+ if err != nil {
398+ return nil , err
399+ }
400+ return asSearchResult (slotKey , chainId , & types.SearchSlot {Slot : result }, nil )
401+ }
388402 slot , err := strconv .ParseUint (input , 10 , 64 )
389403 if err != nil {
390404 return nil , err
@@ -412,6 +426,14 @@ func handleSearchSlotByStateRoot(ctx context.Context, h *HandlerService, input s
412426}
413427
414428func handleSearchEpoch (ctx context.Context , h * HandlerService , input string , chainId uint64 ) (* types.SearchResult , error ) {
429+ if input == "latest" {
430+ result , err := h .daService .GetLatestSlot (ctx )
431+ if err != nil {
432+ return nil , err
433+ }
434+ epoch := result / h .cfg .ClConfig .SlotsPerEpoch
435+ return asSearchResult (epochKey , chainId , & types.SearchEpoch {Epoch : epoch }, nil )
436+ }
415437 epoch , err := strconv .ParseUint (input , 10 , 64 )
416438 if err != nil {
417439 return nil , err
0 commit comments