Skip to content

Commit

Permalink
add init monitored contract
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouop0 committed Jun 21, 2024
1 parent e17de93 commit cf0ff22
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
6 changes: 1 addition & 5 deletions internal/handler/disputeGame.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ func (r *RetryDisputeGameClient) addDisputeGame(ctx context.Context, evt *schema
if err != nil {
return fmt.Errorf("[addDisputeGame] GET game L2BlockNumber err: %s", err)
}
status, err := r.Client.RetryStatus(ctx, &bind.CallOpts{})
if err != nil {
return fmt.Errorf("[addDisputeGame] GET game status err: %s", err)
}
claimData, err := r.Client.RetryClaimData(ctx, &bind.CallOpts{}, big.NewInt(0))
if err != nil {
return fmt.Errorf("[addDisputeGame] GET index 0 ClaimData err: %s", err)
Expand Down Expand Up @@ -170,7 +166,7 @@ func (r *RetryDisputeGameClient) addDisputeGame(ctx context.Context, evt *schema
GameContract: strings.ToLower(disputeGame.DisputeProxy),
GameType: disputeGame.GameType,
L2BlockNumber: l2Block.Int64(),
Status: status,
Status: schema.DisputeGameStatusInProgress,
}
err = r.DB.Transaction(func(tx *gorm.DB) error {
err = tx.Save(gameClaim).Error
Expand Down
15 changes: 15 additions & 0 deletions internal/handler/syncEvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
)

func SyncEvent(ctx *svc.ServiceContext) {
log.Infof("Initializes the monitored contract address...\n")
initMonitoredContract(ctx)
for {
var blocks []schema.SyncBlock
err := ctx.DB.Where("status=? OR status=?", schema.BlockPending, schema.BlockRollback).Order("block_number").Limit(50).Find(&blocks).Error
Expand Down Expand Up @@ -142,3 +144,16 @@ func HandleRollbackBlock(ctx *svc.ServiceContext, block schema.SyncBlock) error
}
return nil
}

func initMonitoredContract(s *svc.ServiceContext) {
//var disputeGames []schema.DisputeGame

Check failure on line 149 in internal/handler/syncEvent.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
//err := s.DB.Where("status=?", uint8(0)).Find(disputeGames).Error
var disputeGames []schema.DisputeGame
err := s.DB.Where("status = ? ", 0).Order("block_number").Find(&disputeGames).Error
if err != nil && err != gorm.ErrRecordNotFound {
panic(err)
}
for _, game := range disputeGames {
blockchain.AddContract(game.GameContract)
}
}
3 changes: 0 additions & 3 deletions internal/schema/dispute_game.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ const (
DisputeGameStatusInProgress = 0
DisputeGameStatusChallengerWin = 1
DisputeGameStatusDefenderWin = 2

DisputeGameInit = 0
DisputeGameComplete = 1
)

type DisputeGame struct {
Expand Down
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"

Check failure on line 4 in main.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

File is not `gofumpt`-ed (gofumpt)

"github.com/gin-gonic/gin"
"github.com/optimism-java/dispute-explorer/internal/api"
"github.com/optimism-java/dispute-explorer/internal/handler"
Expand All @@ -20,7 +19,6 @@ func main() {
handler.Run(sCtx)
log.Info("listener running...\n")
router := gin.Default()

disputeGameHandler := api.NewDisputeGameHandler(sCtx.DB)

router.GET("/disputegames", disputeGameHandler.ListDisputeGames)
Expand Down

0 comments on commit cf0ff22

Please sign in to comment.