Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrorInvalidHeight = func(height string) string { return fmt.Sprintf("invalid height %s", height) } ErrorBlockNotFound = func(height string) string { return fmt.Sprintf("block %s not found... yet.", height) } )
View Source
var (
EndpointGETBlocksHeight = "/index/blocks/{height}"
)
View Source
var IndexBlock = indexer.CreateIndexer(func(indexerDB tmdb.Batch, block *tm.Block, blockID *tm.BlockID, _ *mantlemint.EventCollector) error { defer fmt.Printf("[indexer/block] indexing done for height %d\n", block.Height) record := BlockRecord{ Block: block, BlockID: blockID, } recordJSON, recordErr := tmjson.Marshal(record) if recordErr != nil { return recordErr } return indexerDB.Set(getKey(uint64(block.Height)), recordJSON) })
View Source
var RegisterRESTRoute = indexer.CreateRESTRoute(func(router *mux.Router, indexerDB tmdb.DB) { router.HandleFunc(EndpointGETBlocksHeight, func(writer http.ResponseWriter, request *http.Request) { vars := mux.Vars(request) height, ok := vars["height"] if !ok { http.Error(writer, ErrorInvalidHeight(height), 400) return } if block, err := blockByHeightHandler(indexerDB, height); err != nil { http.Error(writer, indexer.ErrorInternal(err), 500) return } else if block == nil { http.Error(writer, ErrorBlockNotFound(height), 400) return } else { writer.WriteHeader(200) writer.Write(block) return } }).Methods("GET") })
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.