Skip to content

Commit a530417

Browse files
committed
add chainname
1 parent 420244d commit a530417

File tree

5 files changed

+78
-14
lines changed

5 files changed

+78
-14
lines changed

docs/docs.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,31 @@ const docTemplate = `{
9898
},
9999
"/disputegames/calculate/claim": {
100100
"post": {
101-
"description": "calculate dispute game honest claim by postion",
101+
"description": "calculate dispute game honest claim by position",
102102
"consumes": [
103103
"application/json"
104104
],
105105
"produces": [
106106
"application/json"
107107
],
108+
"summary": "calculate claim by position",
109+
"responses": {
110+
"200": {
111+
"description": "OK"
112+
}
113+
}
114+
}
115+
},
116+
"/disputegames/chainname": {
117+
"get": {
118+
"description": "get current block chain name",
119+
"consumes": [
120+
"application/json"
121+
],
122+
"produces": [
123+
"application/json"
124+
],
125+
"summary": "get current block chain name",
108126
"responses": {
109127
"200": {
110128
"description": "OK"

docs/swagger.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,31 @@
8787
},
8888
"/disputegames/calculate/claim": {
8989
"post": {
90-
"description": "calculate dispute game honest claim by postion",
90+
"description": "calculate dispute game honest claim by position",
9191
"consumes": [
9292
"application/json"
9393
],
9494
"produces": [
9595
"application/json"
9696
],
97+
"summary": "calculate claim by position",
98+
"responses": {
99+
"200": {
100+
"description": "OK"
101+
}
102+
}
103+
}
104+
},
105+
"/disputegames/chainname": {
106+
"get": {
107+
"description": "get current block chain name",
108+
"consumes": [
109+
"application/json"
110+
],
111+
"produces": [
112+
"application/json"
113+
],
114+
"summary": "get current block chain name",
97115
"responses": {
98116
"200": {
99117
"description": "OK"

docs/swagger.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,24 @@ paths:
8989
post:
9090
consumes:
9191
- application/json
92-
description: calculate dispute game honest claim by postion
92+
description: calculate dispute game honest claim by position
9393
produces:
9494
- application/json
9595
responses:
9696
"200":
9797
description: OK
98+
summary: calculate claim by position
99+
/disputegames/chainname:
100+
get:
101+
consumes:
102+
- application/json
103+
description: get current block chain name
104+
produces:
105+
- application/json
106+
responses:
107+
"200":
108+
description: OK
109+
summary: get current block chain name
98110
/disputegames/claimroot/:blockNumber:
99111
get:
100112
consumes:

internal/api/dispute_game_handler.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import (
77
"net/http"
88

99
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
10-
"github.com/ethereum/go-ethereum/accounts/abi/bind"
11-
"github.com/optimism-java/dispute-explorer/pkg/contract"
12-
1310
"github.com/ethereum-optimism/optimism/op-service/eth"
1411
"github.com/ethereum-optimism/optimism/op-service/predeploys"
12+
"github.com/ethereum/go-ethereum/accounts/abi/bind"
1513
"github.com/ethereum/go-ethereum/common"
1614
"github.com/ethereum/go-ethereum/ethclient"
15+
config "github.com/optimism-java/dispute-explorer/internal/types"
16+
"github.com/optimism-java/dispute-explorer/pkg/contract"
1717
"github.com/pkg/errors"
1818

1919
"github.com/spf13/cast"
@@ -25,16 +25,18 @@ import (
2525
)
2626

2727
type DisputeGameHandler struct {
28-
DB *gorm.DB
29-
L1RPC *ethclient.Client
30-
L2RPC *ethclient.Client
28+
Config *config.Config
29+
DB *gorm.DB
30+
L1RPC *ethclient.Client
31+
L2RPC *ethclient.Client
3132
}
3233

33-
func NewDisputeGameHandler(db *gorm.DB, l1rpc *ethclient.Client, l2rpc *ethclient.Client) *DisputeGameHandler {
34+
func NewDisputeGameHandler(db *gorm.DB, l1rpc *ethclient.Client, l2rpc *ethclient.Client, config *config.Config) *DisputeGameHandler {
3435
return &DisputeGameHandler{
35-
DB: db,
36-
L1RPC: l1rpc,
37-
L2RPC: l2rpc,
36+
DB: db,
37+
L1RPC: l1rpc,
38+
L2RPC: l2rpc,
39+
Config: config,
3840
}
3941
}
4042

@@ -378,3 +380,16 @@ func (h DisputeGameHandler) gamesClaimByPosition(req *CalculateClaim) (string, e
378380
}
379381
return root, nil
380382
}
383+
384+
// @Summary get current block chain name
385+
// @Schemes
386+
// @Description get current block chain name
387+
// @Accept json
388+
// @Produce json
389+
// @Success 200
390+
// @Router /disputegames/chainname [get]
391+
func (h DisputeGameHandler) GetCurrentBlockChain(c *gin.Context) {
392+
c.JSON(http.StatusOK, gin.H{
393+
"blockchain": h.Config.Blockchain,
394+
})
395+
}

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func main() {
2525
handler.Run(sCtx)
2626
log.Info("listener running...\n")
2727
router := gin.Default()
28-
disputeGameHandler := api.NewDisputeGameHandler(sCtx.DB, sCtx.L1RPC, sCtx.L2RPC)
28+
disputeGameHandler := api.NewDisputeGameHandler(sCtx.DB, sCtx.L1RPC, sCtx.L2RPC, cfg)
2929
docs.SwaggerInfo.Title = "Dispute Game Swagger API"
3030
docs.SwaggerInfo.Description = "This is a dispute-explorer server."
3131
docs.SwaggerInfo.BasePath = "/"
@@ -41,6 +41,7 @@ func main() {
4141
router.GET("/disputegames/events", disputeGameHandler.ListGameEvents)
4242
router.GET("/disputegames/claimroot/:blockNumber", disputeGameHandler.GetClaimRoot)
4343
router.POST("/disputegames/calculate/claim", disputeGameHandler.GetGamesClaimByPosition)
44+
router.GET("/disputegames/chainname", disputeGameHandler.GetCurrentBlockChain)
4445

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

0 commit comments

Comments
 (0)