-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8132b2f
commit 975a0be
Showing
9 changed files
with
590 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package crossl2inbox | ||
|
||
import ( | ||
_ "embed" | ||
"errors" | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/ethereum-optimism/optimism/op-service/predeploys" | ||
"github.com/ethereum-optimism/optimism/op-service/sources/batching" | ||
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots" | ||
"github.com/ethereum/go-ethereum/accounts/abi" | ||
"github.com/ethereum/go-ethereum/common" | ||
ethTypes "github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
const ( | ||
eventExecutingMessage = "ExecutingMessage" | ||
) | ||
|
||
var ( | ||
ErrEventNotFound = errors.New("event not found") | ||
) | ||
|
||
type ExecutingMessage struct { | ||
MsgHash [32]byte | ||
Identifier Identifier | ||
} | ||
|
||
type Identifier struct { | ||
Origin common.Address | ||
BlockNumber *big.Int | ||
LogIndex *big.Int | ||
Timestamp *big.Int | ||
ChainId *big.Int | ||
} | ||
|
||
type CrossL2Inbox struct { | ||
Contract *batching.BoundContract | ||
Abi abi.ABI | ||
} | ||
|
||
func NewCrossL2Inbox() *CrossL2Inbox { | ||
abi := snapshots.LoadCrossL2InboxABI() | ||
return &CrossL2Inbox{ | ||
Abi: *abi, | ||
Contract: batching.NewBoundContract(abi, predeploys.CrossL2InboxAddr), | ||
} | ||
} | ||
|
||
func (i *CrossL2Inbox) DecodeExecutingMessageLog(l *ethTypes.Log) (*ExecutingMessage, error) { | ||
if l.Address != i.Contract.Addr() { | ||
return nil, nil | ||
} | ||
name, result, err := i.Contract.DecodeEvent(l) | ||
if errors.Is(err, batching.ErrUnknownEvent) { | ||
return nil, fmt.Errorf("%w: %v", ErrEventNotFound, err.Error()) | ||
} else if err != nil { | ||
return nil, fmt.Errorf("failed to decode event: %w", err) | ||
} | ||
if name != eventExecutingMessage { | ||
return nil, nil | ||
} | ||
|
||
msgHash := result.GetBytes32(0) | ||
var messageIdentifier Identifier | ||
result.GetStruct(1, &messageIdentifier) | ||
|
||
return &ExecutingMessage{ | ||
MsgHash: msgHash, | ||
Identifier: messageIdentifier, | ||
}, nil | ||
} |
Oops, something went wrong.