Skip to content

Commit

Permalink
add chainname
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouop0 committed Sep 20, 2024
1 parent 420244d commit a530417
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 14 deletions.
20 changes: 19 additions & 1 deletion docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,31 @@ const docTemplate = `{
},
"/disputegames/calculate/claim": {
"post": {
"description": "calculate dispute game honest claim by postion",
"description": "calculate dispute game honest claim by position",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "calculate claim by position",
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/disputegames/chainname": {
"get": {
"description": "get current block chain name",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "get current block chain name",
"responses": {
"200": {
"description": "OK"
Expand Down
20 changes: 19 additions & 1 deletion docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,31 @@
},
"/disputegames/calculate/claim": {
"post": {
"description": "calculate dispute game honest claim by postion",
"description": "calculate dispute game honest claim by position",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "calculate claim by position",
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/disputegames/chainname": {
"get": {
"description": "get current block chain name",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "get current block chain name",
"responses": {
"200": {
"description": "OK"
Expand Down
14 changes: 13 additions & 1 deletion docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,24 @@ paths:
post:
consumes:
- application/json
description: calculate dispute game honest claim by postion
description: calculate dispute game honest claim by position
produces:
- application/json
responses:
"200":
description: OK
summary: calculate claim by position
/disputegames/chainname:
get:
consumes:
- application/json
description: get current block chain name
produces:
- application/json
responses:
"200":
description: OK
summary: get current block chain name
/disputegames/claimroot/:blockNumber:
get:
consumes:
Expand Down
35 changes: 25 additions & 10 deletions internal/api/dispute_game_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"net/http"

"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/optimism-java/dispute-explorer/pkg/contract"

"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/predeploys"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
config "github.com/optimism-java/dispute-explorer/internal/types"
"github.com/optimism-java/dispute-explorer/pkg/contract"
"github.com/pkg/errors"

"github.com/spf13/cast"
Expand All @@ -25,16 +25,18 @@ import (
)

type DisputeGameHandler struct {
DB *gorm.DB
L1RPC *ethclient.Client
L2RPC *ethclient.Client
Config *config.Config
DB *gorm.DB
L1RPC *ethclient.Client
L2RPC *ethclient.Client
}

func NewDisputeGameHandler(db *gorm.DB, l1rpc *ethclient.Client, l2rpc *ethclient.Client) *DisputeGameHandler {
func NewDisputeGameHandler(db *gorm.DB, l1rpc *ethclient.Client, l2rpc *ethclient.Client, config *config.Config) *DisputeGameHandler {
return &DisputeGameHandler{
DB: db,
L1RPC: l1rpc,
L2RPC: l2rpc,
DB: db,
L1RPC: l1rpc,
L2RPC: l2rpc,
Config: config,
}
}

Expand Down Expand Up @@ -378,3 +380,16 @@ func (h DisputeGameHandler) gamesClaimByPosition(req *CalculateClaim) (string, e
}
return root, nil
}

// @Summary get current block chain name
// @Schemes
// @Description get current block chain name
// @Accept json
// @Produce json
// @Success 200
// @Router /disputegames/chainname [get]
func (h DisputeGameHandler) GetCurrentBlockChain(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"blockchain": h.Config.Blockchain,
})
}
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func main() {
handler.Run(sCtx)
log.Info("listener running...\n")
router := gin.Default()
disputeGameHandler := api.NewDisputeGameHandler(sCtx.DB, sCtx.L1RPC, sCtx.L2RPC)
disputeGameHandler := api.NewDisputeGameHandler(sCtx.DB, sCtx.L1RPC, sCtx.L2RPC, cfg)
docs.SwaggerInfo.Title = "Dispute Game Swagger API"
docs.SwaggerInfo.Description = "This is a dispute-explorer server."
docs.SwaggerInfo.BasePath = "/"
Expand All @@ -41,6 +41,7 @@ func main() {
router.GET("/disputegames/events", disputeGameHandler.ListGameEvents)
router.GET("/disputegames/claimroot/:blockNumber", disputeGameHandler.GetClaimRoot)
router.POST("/disputegames/calculate/claim", disputeGameHandler.GetGamesClaimByPosition)
router.GET("/disputegames/chainname", disputeGameHandler.GetCurrentBlockChain)

router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

Expand Down

0 comments on commit a530417

Please sign in to comment.