forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
op-challenger: Read created game address from receipt (ethereum-optim…
…ism#10277) Extracts the game creation logic into reusable code.
- Loading branch information
Showing
7 changed files
with
275 additions
and
17 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,44 @@ | ||
package tools | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts" | ||
"github.com/ethereum-optimism/optimism/op-service/txmgr" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
type GameCreator struct { | ||
contract *contracts.DisputeGameFactoryContract | ||
txMgr txmgr.TxManager | ||
} | ||
|
||
func NewGameCreator(contract *contracts.DisputeGameFactoryContract, txMgr txmgr.TxManager) *GameCreator { | ||
return &GameCreator{ | ||
contract: contract, | ||
txMgr: txMgr, | ||
} | ||
} | ||
|
||
func (g *GameCreator) CreateGame(ctx context.Context, outputRoot common.Hash, traceType uint64, l2BlockNum uint64) (common.Address, error) { | ||
txCandidate, err := g.contract.CreateTx(ctx, uint32(traceType), outputRoot, l2BlockNum) | ||
if err != nil { | ||
return common.Address{}, fmt.Errorf("failed to create tx: %w", err) | ||
} | ||
|
||
rct, err := g.txMgr.Send(ctx, txCandidate) | ||
if err != nil { | ||
return common.Address{}, fmt.Errorf("failed to send tx: %w", err) | ||
} | ||
if rct.Status != types.ReceiptStatusSuccessful { | ||
return common.Address{}, fmt.Errorf("game creation transaction (%v) reverted", rct.TxHash.Hex()) | ||
} | ||
|
||
gameAddr, _, _, err := g.contract.DecodeDisputeGameCreatedLog(rct) | ||
if err != nil { | ||
return common.Address{}, fmt.Errorf("failed to decode game created: %w", err) | ||
} | ||
return gameAddr, 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
Oops, something went wrong.