-
Notifications
You must be signed in to change notification settings - Fork 0
/
puzzle_api.go
50 lines (42 loc) · 1.52 KB
/
puzzle_api.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
package main
import (
"github.com/gofiber/fiber/v2"
)
type GetPuzzleArgs struct {
Puzzle_hash string `json:"puzzle_hash" example:"6b665c0e059050f71a1c3e8a7d5b58e4e1d7abbd02d937e9b5ab5abfd7f8eaba"`
} // @name GetPuzzleArgs
type _ struct {
Success bool `json:"success" example:"true"`
Results int `json:"results" example:"1"`
Result SwaggerPuzzle `json:"result"`
} // @name GetPuzzleResponse
// GetPuzzle godoc
// @Summary returns the stored puzzle for a given puzzle_hash
// @Description Beta stores all revealed inner puzzles of singletons. Use this method to get it from the corresponding puzzle hash. The puzzle will be returned as a hex string.
// @Tags Puzzles
// @Accept json
// @Produce json
// @Param Body body GetPuzzleArgs true "The inner puzzle hash"
// @Success 200 {object} GetPuzzleResponse
// @Failure 401 {object} NoAPIKeyResponse
// @Failure 500 {object} ErrorResponse
// @Security ApiKeyAuth
// @Router /get_puzzle [post]
func GetPuzzle(c *fiber.Ctx) error {
args := new(GetPuzzleArgs)
if err := c.BodyParser(args); err != nil {
return MakeErrorResponse(c, err.Error())
}
if len(args.Puzzle_hash) != 64 {
return MakeErrorResponse(c, "puzzle_hash is not 64 characters long :(")
}
var p Puzzle
result := DB.First(&p, "puzzle_hash = ?", args.Puzzle_hash)
if result.Error != nil {
return MakeErrorResponse(c, result.Error.Error())
}
return MakeSuccessResponseForSingleObject(c, "result", PuzzleToJSON(p))
}
func SetupPuzzleAPIRoutes(app *fiber.App) { // more like route lol
app.Post("/get_puzzle", GetPuzzle)
}