|
| 1 | +package handler |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "net/http" |
| 6 | + |
| 7 | + "github.com/gnolang/gno/pkgs/bft/rpc/client" |
| 8 | +) |
| 9 | + |
| 10 | +func GnoRenderQueryHandler(cli client.ABCIClient) http.HandlerFunc { |
| 11 | + return func(w http.ResponseWriter, r *http.Request) { |
| 12 | + params := r.URL.Query() |
| 13 | + data := []byte(fmt.Sprintf("%s\n%s", params.Get("realm"), params.Get("query"))) |
| 14 | + res, err := cli.ABCIQuery("vm/qrender", data) |
| 15 | + if err != nil { |
| 16 | + writeError(w, err) |
| 17 | + return |
| 18 | + } |
| 19 | + |
| 20 | + if res.Response.Error != nil { |
| 21 | + writeError(w, res.Response.Error) |
| 22 | + return |
| 23 | + } |
| 24 | + |
| 25 | + w.WriteHeader(http.StatusOK) |
| 26 | + fmt.Fprint(w, string(res.Response.Data)) |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +func GnoEvalQueryHandler(cli client.ABCIClient) http.HandlerFunc { |
| 31 | + return func(w http.ResponseWriter, r *http.Request) { |
| 32 | + params := r.URL.Query() |
| 33 | + data := []byte(fmt.Sprintf("%s\n%s", params.Get("realm"), params.Get("func"))) |
| 34 | + res, err := cli.ABCIQuery("vm/qeval", data) |
| 35 | + if err != nil { |
| 36 | + writeError(w, err) |
| 37 | + return |
| 38 | + } |
| 39 | + |
| 40 | + if res.Response.Error != nil { |
| 41 | + writeError(w, res.Response.Error) |
| 42 | + return |
| 43 | + } |
| 44 | + |
| 45 | + w.WriteHeader(http.StatusOK) |
| 46 | + fmt.Fprint(w, string(res.Response.Data)) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +func GnoFuncsQueryHandler(cli client.ABCIClient) http.HandlerFunc { |
| 51 | + return func(w http.ResponseWriter, r *http.Request) { |
| 52 | + params := r.URL.Query() |
| 53 | + data := []byte(params.Get("realm")) |
| 54 | + res, err := cli.ABCIQuery("vm/qeval", data) |
| 55 | + if err != nil { |
| 56 | + writeError(w, err) |
| 57 | + return |
| 58 | + } |
| 59 | + |
| 60 | + if res.Response.Error != nil { |
| 61 | + writeError(w, res.Response.Error) |
| 62 | + return |
| 63 | + } |
| 64 | + |
| 65 | + w.WriteHeader(http.StatusOK) |
| 66 | + w.Header().Set("Content-Type", "application/json") |
| 67 | + fmt.Fprint(w, string(res.Response.Data)) |
| 68 | + } |
| 69 | +} |
0 commit comments