make setDefaults public

This commit is contained in:
codchen 2023-12-08 14:26:36 +08:00
parent 43497a4c38
commit 9ecc4274eb
4 changed files with 16 additions and 16 deletions

View file

@ -54,7 +54,7 @@ type Config struct {
}
// sets defaults on the config
func setDefaults(cfg *Config) {
func SetDefaults(cfg *Config) {
if cfg.ChainConfig == nil {
cfg.ChainConfig = &params.ChainConfig{
ChainID: big.NewInt(1),
@ -111,7 +111,7 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
if cfg == nil {
cfg = new(Config)
}
setDefaults(cfg)
SetDefaults(cfg)
if cfg.State == nil {
cfg.State, _ = state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
@ -145,7 +145,7 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) {
if cfg == nil {
cfg = new(Config)
}
setDefaults(cfg)
SetDefaults(cfg)
if cfg.State == nil {
cfg.State, _ = state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
@ -175,7 +175,7 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) {
// Call, unlike Execute, requires a config and also requires the State field to
// be set.
func Call(address common.Address, input []byte, cfg *Config) ([]byte, uint64, error) {
setDefaults(cfg)
SetDefaults(cfg)
var (
vmenv = NewEnv(cfg)

View file

@ -42,7 +42,7 @@ import (
func TestDefaults(t *testing.T) {
cfg := new(Config)
setDefaults(cfg)
SetDefaults(cfg)
if cfg.Difficulty == nil {
t.Error("expected difficulty to be non nil")
@ -326,7 +326,7 @@ func TestBlockhash(t *testing.T) {
// state, this should not be used, since it does not reset the state between runs.
func benchmarkNonModifyingCode(gas uint64, code []byte, name string, tracerCode string, b *testing.B) {
cfg := new(Config)
setDefaults(cfg)
SetDefaults(cfg)
cfg.State, _ = state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
cfg.GasLimit = gas
if len(tracerCode) > 0 {

View file

@ -449,7 +449,7 @@ func (s *PersonalAccountAPI) signTransaction(ctx context.Context, args *Transact
return nil, err
}
// Set some sanity defaults and terminate on failure
if err := args.setDefaults(ctx, s.b); err != nil {
if err := args.SetDefaults(ctx, s.b); err != nil {
return nil, err
}
// Assemble the transaction and sign with the wallet
@ -1527,7 +1527,7 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
}
// Ensure any missing fields are filled, extract the recipient and input data
if err := args.setDefaults(ctx, b); err != nil {
if err := args.SetDefaults(ctx, b); err != nil {
return nil, 0, nil, err
}
var to common.Address
@ -1829,7 +1829,7 @@ func (s *TransactionAPI) SendTransaction(ctx context.Context, args TransactionAr
}
// Set some sanity defaults and terminate on failure
if err := args.setDefaults(ctx, s.b); err != nil {
if err := args.SetDefaults(ctx, s.b); err != nil {
return common.Hash{}, err
}
// Assemble the transaction and sign with the wallet
@ -1847,7 +1847,7 @@ func (s *TransactionAPI) SendTransaction(ctx context.Context, args TransactionAr
// processing (signing + broadcast).
func (s *TransactionAPI) FillTransaction(ctx context.Context, args TransactionArgs) (*SignTransactionResult, error) {
// Set some sanity defaults and terminate on failure
if err := args.setDefaults(ctx, s.b); err != nil {
if err := args.SetDefaults(ctx, s.b); err != nil {
return nil, err
}
// Assemble the transaction and obtain rlp
@ -1913,7 +1913,7 @@ func (s *TransactionAPI) SignTransaction(ctx context.Context, args TransactionAr
if args.Nonce == nil {
return nil, errors.New("nonce not specified")
}
if err := args.setDefaults(ctx, s.b); err != nil {
if err := args.SetDefaults(ctx, s.b); err != nil {
return nil, err
}
// Before actually sign the transaction, ensure the transaction fee is reasonable.
@ -1962,7 +1962,7 @@ func (s *TransactionAPI) Resend(ctx context.Context, sendArgs TransactionArgs, g
if sendArgs.Nonce == nil {
return common.Hash{}, errors.New("missing transaction nonce in transaction spec")
}
if err := sendArgs.setDefaults(ctx, s.b); err != nil {
if err := sendArgs.SetDefaults(ctx, s.b); err != nil {
return common.Hash{}, err
}
matchTx := sendArgs.toTransaction()

View file

@ -74,8 +74,8 @@ func (args *TransactionArgs) data() []byte {
return nil
}
// setDefaults fills in default values for unspecified tx fields.
func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
// SetDefaults fills in default values for unspecified tx fields.
func (args *TransactionArgs) SetDefaults(ctx context.Context, b Backend) error {
if err := args.setFeeDefaults(ctx, b); err != nil {
return err
}
@ -280,7 +280,7 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (*
}
// toTransaction converts the arguments to a transaction.
// This assumes that setDefaults has been called.
// This assumes that SetDefaults has been called.
func (args *TransactionArgs) toTransaction() *types.Transaction {
var data types.TxData
switch {
@ -325,7 +325,7 @@ func (args *TransactionArgs) toTransaction() *types.Transaction {
}
// ToTransaction converts the arguments to a transaction.
// This assumes that setDefaults has been called.
// This assumes that SetDefaults has been called.
func (args *TransactionArgs) ToTransaction() *types.Transaction {
return args.toTransaction()
}