@@ -921,6 +921,50 @@ func (p *PostgresStorage) GetSyncStatus(ctx context.Context, dbTx interface{}) (
921921 return status , nil
922922}
923923
924+ // ResetDeposits resets the state to a depositCount.
925+ func (p * PostgresStorage ) ResetDeposits (ctx context.Context , depositCount uint32 , networkID uint32 , dbTx interface {}) error {
926+ if networkID == 0 {
927+ return errors .New ("cannot reset L1 deposits" )
928+ }
929+ const resetSQL = "DELETE FROM sync.deposit WHERE deposit_cnt >= $1 AND network_id = $2"
930+ e := p .getExecQuerier (dbTx )
931+ _ , err := e .Exec (ctx , resetSQL , depositCount , networkID )
932+ return err
933+ }
934+
935+ // AddBackwardLET adds a new BackwardLET event to the db.
936+ func (p * PostgresStorage ) AddBackwardLET (ctx context.Context , backwardLET * etherman.BackwardLET , dbTx interface {}) error {
937+ const addExitRootSQL = "INSERT INTO sync.backward_let(block_id, previous_deposit_cnt, previous_root, new_deposit_cnt, new_root) VALUES ($1, $2, $3, $4, $5)"
938+ e := p .getExecQuerier (dbTx )
939+ _ , err := e .Exec (ctx , addExitRootSQL , backwardLET .BlockID , backwardLET .PreviousDepositCount , backwardLET .PreviousRoot , backwardLET .NewDepositCount , backwardLET .NewRoot )
940+ return err
941+ }
942+
943+ // AddSetClaim adds a new SetClaim event to the db.
944+ func (p * PostgresStorage ) AddSetClaim (ctx context.Context , setClaim * etherman.SetClaim , dbTx interface {}) error {
945+ return p .addSetUnsetClaim (ctx , "SET" , setClaim .BlockID , setClaim .MainnetFlag , setClaim .RollupIndex , setClaim .Index , setClaim .GlobalIndex , dbTx )
946+ }
947+
948+ // AddUnsetClaim adds a new UnsetClaim event to the db.
949+ func (p * PostgresStorage ) AddUnsetClaim (ctx context.Context , unsetClaim * etherman.UnsetClaim , dbTx interface {}) error {
950+ return p .addSetUnsetClaim (ctx , "UNSET" , unsetClaim .BlockID , unsetClaim .MainnetFlag , unsetClaim .RollupIndex , unsetClaim .Index , unsetClaim .GlobalIndex , dbTx )
951+ }
952+
953+ func (p * PostgresStorage ) addSetUnsetClaim (ctx context.Context , eventType string , blockID uint64 , mainnetFlag bool , rollupIndex , index uint32 , globalIndex * big.Int , dbTx interface {}) error {
954+ const addExitRootSQL = "INSERT INTO sync.set_unset_claim(block_id, mainnet_flag, rollup_index, index, global_index, type) VALUES($1, $2, $3, $4, $5, $6)"
955+ e := p .getExecQuerier (dbTx )
956+ _ , err := e .Exec (ctx , addExitRootSQL , blockID , mainnetFlag , rollupIndex , index , globalIndex .String (), eventType )
957+ return err
958+ }
959+
960+ // DeleteClaimByGlobalIndex resets the state to a depositCount.
961+ func (p * PostgresStorage ) DeleteClaimByGlobalIndex (ctx context.Context , globalIndex * big.Int , networkID uint32 , dbTx interface {}) error {
962+ const resetSQL = "DELETE FROM sync.claim WHERE global_index = $1 AND network_id = $2"
963+ e := p .getExecQuerier (dbTx )
964+ _ , err := e .Exec (ctx , resetSQL , globalIndex .String (), networkID )
965+ return err
966+ }
967+
924968// UpdateDepositsStatusForTesting updates the ready_for_claim status of all deposits for testing.
925969func (p * PostgresStorage ) UpdateDepositsStatusForTesting (ctx context.Context , dbTx interface {}) error {
926970 const updateDepositsStatusSQL = "UPDATE sync.deposit SET ready_for_claim = true;"
0 commit comments