|
| 1 | +package blocktag |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "time" |
| 6 | + |
| 7 | + "github.com/morph-l2/go-ethereum/common" |
| 8 | + "github.com/urfave/cli" |
| 9 | + |
| 10 | + node "morph-l2/node/core" |
| 11 | + "morph-l2/node/flags" |
| 12 | +) |
| 13 | + |
| 14 | +const ( |
| 15 | + // DefaultSafeConfirmations is the default number of L1 blocks to wait before considering a batch as safe |
| 16 | + DefaultSafeConfirmations = 10 |
| 17 | + // DefaultPollInterval is the default interval to poll L1 for batch status updates |
| 18 | + DefaultPollInterval = 10 * time.Second |
| 19 | +) |
| 20 | + |
| 21 | +// Config holds the configuration for BlockTagService |
| 22 | +type Config struct { |
| 23 | + L1Addr string |
| 24 | + RollupAddress common.Address |
| 25 | + SafeConfirmations uint64 |
| 26 | + PollInterval time.Duration |
| 27 | +} |
| 28 | + |
| 29 | +// DefaultConfig returns the default configuration |
| 30 | +func DefaultConfig() *Config { |
| 31 | + return &Config{ |
| 32 | + SafeConfirmations: DefaultSafeConfirmations, |
| 33 | + PollInterval: DefaultPollInterval, |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +// SetCliContext sets the configuration from CLI context |
| 38 | +func (c *Config) SetCliContext(ctx *cli.Context) error { |
| 39 | + c.L1Addr = ctx.GlobalString(flags.L1NodeAddr.Name) |
| 40 | + |
| 41 | + // Determine RollupAddress: use explicit flag, or mainnet default, or error |
| 42 | + if ctx.GlobalBool(flags.MainnetFlag.Name) { |
| 43 | + c.RollupAddress = node.MainnetRollupContractAddress |
| 44 | + } else if ctx.GlobalIsSet(flags.RollupContractAddress.Name) { |
| 45 | + c.RollupAddress = common.HexToAddress(ctx.GlobalString(flags.RollupContractAddress.Name)) |
| 46 | + } else { |
| 47 | + return fmt.Errorf("rollup contract address is required: either specify --%s or use --%s for mainnet default", |
| 48 | + flags.RollupContractAddress.Name, flags.MainnetFlag.Name) |
| 49 | + } |
| 50 | + |
| 51 | + if ctx.GlobalIsSet(flags.BlockTagSafeConfirmations.Name) { |
| 52 | + c.SafeConfirmations = ctx.GlobalUint64(flags.BlockTagSafeConfirmations.Name) |
| 53 | + } |
| 54 | + return nil |
| 55 | +} |
0 commit comments