34 lines
746 B
Go
34 lines
746 B
Go
package api
|
|
|
|
import (
|
|
"dejo_node/internal/transactions"
|
|
"net/http"
|
|
)
|
|
|
|
func (h *Handler) SubmitTransaction(w http.ResponseWriter, r *http.Request) {
|
|
var tx transactions.Transaction
|
|
err := ReadJSON(r, &tx)
|
|
if err != nil {
|
|
WriteError(w, http.StatusBadRequest, "Transação inválida")
|
|
return
|
|
}
|
|
|
|
err = h.Mempool.Add(&tx)
|
|
if err != nil {
|
|
WriteError(w, http.StatusInternalServerError, "Erro ao adicionar transação")
|
|
return
|
|
}
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
}
|
|
|
|
func (h *Handler) GetTransaction(w http.ResponseWriter, r *http.Request) {
|
|
hash := r.URL.Query().Get("hash")
|
|
tx := h.Mempool.GetByHash(hash)
|
|
if tx == nil {
|
|
WriteError(w, http.StatusNotFound, "Transação não encontrada")
|
|
return
|
|
}
|
|
WriteJSON(w, http.StatusOK, tx)
|
|
}
|