github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/modules/vm/wasmapi/handler/gen_proof.go (about)

     1  package handler
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  
     7  	"github.com/gin-gonic/gin"
     8  	"github.com/gin-gonic/gin/binding"
     9  	"github.com/pkg/errors"
    10  
    11  	"github.com/machinefi/w3bstream/pkg/depends/kit/logr"
    12  	"github.com/machinefi/w3bstream/pkg/modules/vm/risc0vm"
    13  	"github.com/machinefi/w3bstream/pkg/types"
    14  )
    15  
    16  func (h *Handler) GenRisc0Proof(c *gin.Context) {
    17  	// l := types.MustLoggerFromContext(c.Request.Context())
    18  	_, l := logr.Start(c, "vm.Handler.GenRisc0Proof")
    19  	defer l.End()
    20  
    21  	var req risc0vm.CreateProofReq
    22  	if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
    23  		l.Error(errors.Wrap(err, "decode http request failed"))
    24  		c.JSON(http.StatusBadRequest, newErrResp(err))
    25  		return
    26  	}
    27  
    28  	prj := types.MustProjectFromContext(c.Request.Context())
    29  
    30  	l = l.WithValues("ProjectID", prj.ProjectID)
    31  
    32  	if err := h.setAsync(c); err != nil {
    33  		l.Error(err)
    34  		c.JSON(http.StatusInternalServerError, newErrResp(err))
    35  		return
    36  	}
    37  
    38  	c.Status(http.StatusOK)
    39  }
    40  
    41  func (h *Handler) GenRisc0ProofAsync(c *gin.Context) {
    42  	// l := types.MustLoggerFromContext(c.Request.Context())
    43  	_, l := logr.Start(c, "vm.Handler.GenRisc0ProofAsync")
    44  	defer l.End()
    45  
    46  	var req risc0vm.CreateProofReq
    47  	c.ShouldBindJSON(&req)
    48  
    49  	prj := types.MustProjectFromContext(c.Request.Context())
    50  
    51  	l = l.WithValues("ProjectID", prj.ProjectID)
    52  
    53  	rsp, err := risc0vm.CreateProof(c.Request.Context(), &req, h.risc0Conf.Websocket, h.risc0Conf.CreateProofPath)
    54  	if err != nil {
    55  		l.Error(errors.Wrap(err, fmt.Sprintf("send risc0 server request %s failed", h.risc0Conf.CreateProofPath)))
    56  		c.JSON(http.StatusInternalServerError, newErrResp(err))
    57  		return
    58  	}
    59  
    60  	c.JSON(http.StatusOK, &rsp)
    61  }