Commit 0ea5e054 authored by Mark Tyneway's avatar Mark Tyneway

op-wheel: typesafe flag parsing

parent ad4a4ff2
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/eth" "github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus/beacon" "github.com/ethereum/go-ethereum/consensus/beacon"
"github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
...@@ -379,9 +380,9 @@ func SetBalance(addr common.Address, amount *big.Int) HeadFn { ...@@ -379,9 +380,9 @@ func SetBalance(addr common.Address, amount *big.Int) HeadFn {
} }
} }
func SetCode(addr common.Address, code string) HeadFn { func SetCode(addr common.Address, code hexutil.Bytes) HeadFn {
return func(headState *state.StateDB) error { return func(headState *state.StateDB) error {
headState.SetCode(addr, common.FromHex(code)) headState.SetCode(addr, code)
return nil return nil
} }
} }
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"time" "time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
...@@ -179,6 +180,10 @@ func addrFlag(name string, usage string) cli.GenericFlag { ...@@ -179,6 +180,10 @@ func addrFlag(name string, usage string) cli.GenericFlag {
return textFlag[*common.Address](name, usage, new(common.Address)) return textFlag[*common.Address](name, usage, new(common.Address))
} }
func bytesFlag(name string, usage string) cli.GenericFlag {
return textFlag[*hexutil.Bytes](name, usage, new(hexutil.Bytes))
}
func hashFlag(name string, usage string) cli.GenericFlag { func hashFlag(name string, usage string) cli.GenericFlag {
return textFlag[*common.Hash](name, usage, new(common.Hash)) return textFlag[*common.Hash](name, usage, new(common.Hash))
} }
...@@ -191,6 +196,10 @@ func addrFlagValue(name string, ctx *cli.Context) common.Address { ...@@ -191,6 +196,10 @@ func addrFlagValue(name string, ctx *cli.Context) common.Address {
return *ctx.Generic(name).(*TextFlag[*common.Address]).Value return *ctx.Generic(name).(*TextFlag[*common.Address]).Value
} }
func bytesFlagValue(name string, ctx *cli.Context) hexutil.Bytes {
return *ctx.Generic(name).(*TextFlag[*hexutil.Bytes]).Value
}
func hashFlagValue(name string, ctx *cli.Context) common.Hash { func hashFlagValue(name string, ctx *cli.Context) common.Hash {
return *ctx.Generic(name).(*TextFlag[*common.Hash]).Value return *ctx.Generic(name).(*TextFlag[*common.Hash]).Value
} }
...@@ -276,10 +285,10 @@ var ( ...@@ -276,10 +285,10 @@ var (
Flags: []cli.Flag{ Flags: []cli.Flag{
DataDirFlag, DataDirFlag,
addrFlag("address", "Address to change code of"), addrFlag("address", "Address to change code of"),
cli.StringFlag{Name: "code", Usage: "New code of the account"}, bytesFlag("code", "New code of the account"),
}, },
Action: CheatAction(false, func(ctx *cli.Context, ch *cheat.Cheater) error { Action: CheatAction(false, func(ctx *cli.Context, ch *cheat.Cheater) error {
return ch.RunAndClose(cheat.SetCode(addrFlagValue("address", ctx), ctx.String("code"))) return ch.RunAndClose(cheat.SetCode(addrFlagValue("address", ctx), bytesFlagValue("code", ctx)))
}), }),
} }
CheatSetNonceCmd = cli.Command{ CheatSetNonceCmd = cli.Command{
......
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