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