From a530417c3cabc8a84d3c1d6723d1190805a7b087 Mon Sep 17 00:00:00 2001 From: zhouop0 <11733741+zhouop0@users.noreply.github.com> Date: Fri, 20 Sep 2024 16:31:04 +0800 Subject: [PATCH] add chainname --- docs/docs.go | 20 +++++++++++++++- docs/swagger.json | 20 +++++++++++++++- docs/swagger.yaml | 14 ++++++++++- internal/api/dispute_game_handler.go | 35 ++++++++++++++++++++-------- main.go | 3 ++- 5 files changed, 78 insertions(+), 14 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index 34439b9..12ba27a 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -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" diff --git a/docs/swagger.json b/docs/swagger.json index 8af9c21..35ada80 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -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" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 4cb068f..1dd9d36 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -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: diff --git a/internal/api/dispute_game_handler.go b/internal/api/dispute_game_handler.go index 9016f85..11c567c 100644 --- a/internal/api/dispute_game_handler.go +++ b/internal/api/dispute_game_handler.go @@ -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" @@ -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, } } @@ -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, + }) +} diff --git a/main.go b/main.go index 57a920c..98f7aee 100644 --- a/main.go +++ b/main.go @@ -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 = "/" @@ -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))