commit inicial do projeto

This commit is contained in:
Júnior
2025-05-23 10:44:32 -03:00
commit 8f04473c0b
106 changed files with 5673 additions and 0 deletions

View File

@ -0,0 +1,31 @@
package api
import (
"net/http"
"strconv"
"github.com/gorilla/mux"
)
func (h *Handler) ListBlocks(w http.ResponseWriter, r *http.Request) {
blocks, err := h.Store.ListBlocks()
if err != nil {
WriteError(w, http.StatusInternalServerError, "Erro ao listar blocos")
return
}
WriteJSON(w, blocks)
}
func (h *Handler) GetBlockByHeight(w http.ResponseWriter, r *http.Request) {
heightStr := mux.Vars(r)["height"]
height, err := strconv.Atoi(heightStr)
if err != nil {
WriteError(w, http.StatusBadRequest, "Altura inválida")
return
}
block, err := h.Store.LoadBlock(height)
if err != nil {
WriteError(w, http.StatusNotFound, "Bloco não encontrado")
return
}
WriteJSON(w, block)
}