Commit 384e2dc7 authored by Adrian Sutton's avatar Adrian Sutton Committed by GitHub

challenger: Allow interrupting subcommands. (#10765)

parent c04ca0c4
...@@ -76,6 +76,6 @@ var CreateGameCommand = &cli.Command{ ...@@ -76,6 +76,6 @@ var CreateGameCommand = &cli.Command{
Name: "create-game", Name: "create-game",
Usage: "Creates a dispute game via the factory", Usage: "Creates a dispute game via the factory",
Description: "Creates a dispute game via the factory", Description: "Creates a dispute game via the factory",
Action: CreateGame, Action: Interruptible(CreateGame),
Flags: createGameFlags(), Flags: createGameFlags(),
} }
...@@ -112,6 +112,6 @@ var ListCreditsCommand = &cli.Command{ ...@@ -112,6 +112,6 @@ var ListCreditsCommand = &cli.Command{
Name: "list-credits", Name: "list-credits",
Usage: "List the credits in a dispute game", Usage: "List the credits in a dispute game",
Description: "Lists the credits in a dispute game", Description: "Lists the credits in a dispute game",
Action: ListCredits, Action: Interruptible(ListCredits),
Flags: listCreditsFlags(), Flags: listCreditsFlags(),
} }
...@@ -198,6 +198,6 @@ var ListClaimsCommand = &cli.Command{ ...@@ -198,6 +198,6 @@ var ListClaimsCommand = &cli.Command{
Name: "list-claims", Name: "list-claims",
Usage: "List the claims in a dispute game", Usage: "List the claims in a dispute game",
Description: "Lists the claims in a dispute game", Description: "Lists the claims in a dispute game",
Action: ListClaims, Action: Interruptible(ListClaims),
Flags: listClaimsFlags(), Flags: listClaimsFlags(),
} }
...@@ -183,6 +183,6 @@ var ListGamesCommand = &cli.Command{ ...@@ -183,6 +183,6 @@ var ListGamesCommand = &cli.Command{
Name: "list-games", Name: "list-games",
Usage: "List the games created by a dispute game factory", Usage: "List the games created by a dispute game factory",
Description: "Lists the games created by a dispute game factory", Description: "Lists the games created by a dispute game factory",
Action: ListGames, Action: Interruptible(ListGames),
Flags: listGamesFlags(), Flags: listGamesFlags(),
} }
...@@ -97,6 +97,6 @@ var MoveCommand = &cli.Command{ ...@@ -97,6 +97,6 @@ var MoveCommand = &cli.Command{
Name: "move", Name: "move",
Usage: "Creates and sends a move transaction to the dispute game", Usage: "Creates and sends a move transaction to the dispute game",
Description: "Creates and sends a move transaction to the dispute game", Description: "Creates and sends a move transaction to the dispute game",
Action: Move, Action: Interruptible(Move),
Flags: moveFlags(), Flags: moveFlags(),
} }
...@@ -46,6 +46,6 @@ var ResolveCommand = &cli.Command{ ...@@ -46,6 +46,6 @@ var ResolveCommand = &cli.Command{
Name: "resolve", Name: "resolve",
Usage: "Resolves the specified dispute game if possible", Usage: "Resolves the specified dispute game if possible",
Description: "Resolves the specified dispute game if possible", Description: "Resolves the specified dispute game if possible",
Action: Resolve, Action: Interruptible(Resolve),
Flags: resolveFlags(), Flags: resolveFlags(),
} }
...@@ -66,6 +66,6 @@ var ResolveClaimCommand = &cli.Command{ ...@@ -66,6 +66,6 @@ var ResolveClaimCommand = &cli.Command{
Name: "resolve-claim", Name: "resolve-claim",
Usage: "Resolves the specified claim if possible", Usage: "Resolves the specified claim if possible",
Description: "Resolves the specified claim if possible", Description: "Resolves the specified claim if possible",
Action: ResolveClaim, Action: Interruptible(ResolveClaim),
Flags: resolveClaimFlags(), Flags: resolveClaimFlags(),
} }
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
contractMetrics "github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts/metrics" contractMetrics "github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts/metrics"
opservice "github.com/ethereum-optimism/optimism/op-service" opservice "github.com/ethereum-optimism/optimism/op-service"
"github.com/ethereum-optimism/optimism/op-service/dial" "github.com/ethereum-optimism/optimism/op-service/dial"
"github.com/ethereum-optimism/optimism/op-service/opio"
"github.com/ethereum-optimism/optimism/op-service/sources/batching" "github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum-optimism/optimism/op-service/txmgr/metrics" "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
...@@ -17,6 +18,12 @@ import ( ...@@ -17,6 +18,12 @@ import (
type ContractCreator[T any] func(context.Context, contractMetrics.ContractMetricer, common.Address, *batching.MultiCaller) (T, error) type ContractCreator[T any] func(context.Context, contractMetrics.ContractMetricer, common.Address, *batching.MultiCaller) (T, error)
func Interruptible(action cli.ActionFunc) cli.ActionFunc {
return func(ctx *cli.Context) error {
ctx.Context = opio.CancelOnInterrupt(ctx.Context)
return action(ctx)
}
}
func AddrFromFlag(flagName string) func(ctx *cli.Context) (common.Address, error) { func AddrFromFlag(flagName string) func(ctx *cli.Context) (common.Address, error) {
return func(ctx *cli.Context) (common.Address, error) { return func(ctx *cli.Context) (common.Address, error) {
gameAddr, err := opservice.ParseAddress(ctx.String(flagName)) gameAddr, err := opservice.ParseAddress(ctx.String(flagName))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment