diff --git a/internal/handler/disputeGame.go b/internal/handler/disputeGame.go index 2c59e43..ff0627a 100644 --- a/internal/handler/disputeGame.go +++ b/internal/handler/disputeGame.go @@ -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) @@ -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 diff --git a/internal/handler/syncEvent.go b/internal/handler/syncEvent.go index 1d83297..42fdb3d 100644 --- a/internal/handler/syncEvent.go +++ b/internal/handler/syncEvent.go @@ -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 @@ -142,3 +144,16 @@ func HandleRollbackBlock(ctx *svc.ServiceContext, block schema.SyncBlock) error } return nil } + +func initMonitoredContract(s *svc.ServiceContext) { + //var disputeGames []schema.DisputeGame + //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) + } +} diff --git a/internal/schema/dispute_game.go b/internal/schema/dispute_game.go index 9df2bae..df02876 100644 --- a/internal/schema/dispute_game.go +++ b/internal/schema/dispute_game.go @@ -6,9 +6,6 @@ const ( DisputeGameStatusInProgress = 0 DisputeGameStatusChallengerWin = 1 DisputeGameStatusDefenderWin = 2 - - DisputeGameInit = 0 - DisputeGameComplete = 1 ) type DisputeGame struct { diff --git a/main.go b/main.go index 3107f27..e46cf71 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "context" - "github.com/gin-gonic/gin" "github.com/optimism-java/dispute-explorer/internal/api" "github.com/optimism-java/dispute-explorer/internal/handler" @@ -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)