-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(relayer): MessageStatusChanged events (#13272)
Co-authored-by: David <[email protected]>
- Loading branch information
1 parent
cc5f5c4
commit f5f4fc4
Showing
16 changed files
with
415 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
packages/relayer/indexer/save_message_status_changed_events.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package indexer | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/pkg/errors" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/taikoxyz/taiko-mono/packages/relayer" | ||
"github.com/taikoxyz/taiko-mono/packages/relayer/contracts/bridge" | ||
) | ||
|
||
func (svc *Service) saveMessageStatusChangedEvents( | ||
ctx context.Context, | ||
chainID *big.Int, | ||
events *bridge.BridgeMessageStatusChangedIterator, | ||
) error { | ||
if !events.Next() { | ||
log.Infof("no messageStatusChanged events") | ||
return nil | ||
} | ||
|
||
for { | ||
event := events.Event | ||
log.Infof("messageStatusChanged: %v", common.Hash(event.MsgHash).Hex()) | ||
|
||
if err := svc.saveMessageStatusChangedEvent(ctx, chainID, event); err != nil { | ||
return errors.Wrap(err, "svc.saveMessageStatusChangedEvent") | ||
} | ||
|
||
if !events.Next() { | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
func (svc *Service) saveMessageStatusChangedEvent( | ||
ctx context.Context, | ||
chainID *big.Int, | ||
event *bridge.BridgeMessageStatusChanged, | ||
) error { | ||
marshaled, err := json.Marshal(event) | ||
if err != nil { | ||
return errors.Wrap(err, "json.Marshal(event)") | ||
} | ||
|
||
// get the previous MessageSent event or other message status changed events, | ||
// so we can find out the previous owner of this msg hash, | ||
// to save to the db. | ||
previousEvents, err := svc.eventRepo.FindAllByMsgHash(ctx, common.Hash(event.MsgHash).Hex()) | ||
if err != nil { | ||
return errors.Wrap(err, "svc.eventRepo.FindAllByMsgHash") | ||
} | ||
|
||
if len(previousEvents) == 0 { | ||
return errors.Wrap(err, "svc.eventRepo.FindAllByMsgHash") | ||
} | ||
|
||
_, err = svc.eventRepo.Save(ctx, relayer.SaveEventOpts{ | ||
Name: relayer.EventNameMessageStatusChanged, | ||
Data: string(marshaled), | ||
ChainID: chainID, | ||
Status: relayer.EventStatus(event.Status), | ||
MessageOwner: previousEvents[0].MessageOwner, | ||
MsgHash: common.Hash(event.MsgHash).Hex(), | ||
}) | ||
if err != nil { | ||
return errors.Wrap(err, "svc.eventRepo.Save") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.