Skip to content

Commit ab4049d

Browse files
committed
fix
1 parent c8b6782 commit ab4049d

File tree

5 files changed

+109
-138
lines changed

5 files changed

+109
-138
lines changed

ethclient/ethclient.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/ethereum/go-ethereum/common"
2929
"github.com/ethereum/go-ethereum/common/hexutil"
3030
"github.com/ethereum/go-ethereum/core/types"
31-
clienttypes "github.com/ethereum/go-ethereum/ethclient/types"
3231
"github.com/ethereum/go-ethereum/rpc"
3332
)
3433

@@ -831,17 +830,17 @@ type SimulateOptions struct {
831830

832831
// SimulateBlock represents a batch of calls to be simulated.
833832
type SimulateBlock struct {
834-
BlockOverrides *clienttypes.BlockOverrides `json:"blockOverrides,omitempty"`
835-
StateOverrides *map[common.Address]clienttypes.OverrideAccount `json:"stateOverrides,omitempty"`
836-
Calls []ethereum.CallMsg `json:"calls"`
833+
BlockOverrides *ethereum.BlockOverrides `json:"blockOverrides,omitempty"`
834+
StateOverrides *map[common.Address]ethereum.OverrideAccount `json:"stateOverrides,omitempty"`
835+
Calls []ethereum.CallMsg `json:"calls"`
837836
}
838837

839838
// MarshalJSON implements json.Marshaler for SimulateBlock.
840839
func (s SimulateBlock) MarshalJSON() ([]byte, error) {
841840
type Alias struct {
842-
BlockOverrides *clienttypes.BlockOverrides `json:"blockOverrides,omitempty"`
843-
StateOverrides *map[common.Address]clienttypes.OverrideAccount `json:"stateOverrides,omitempty"`
844-
Calls []interface{} `json:"calls"`
841+
BlockOverrides *ethereum.BlockOverrides `json:"blockOverrides,omitempty"`
842+
StateOverrides *map[common.Address]ethereum.OverrideAccount `json:"stateOverrides,omitempty"`
843+
Calls []interface{} `json:"calls"`
845844
}
846845
calls := make([]interface{}, len(s.Calls))
847846
for i, call := range s.Calls {

ethclient/ethclient_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
"github.com/ethereum/go-ethereum/eth"
3838
"github.com/ethereum/go-ethereum/eth/ethconfig"
3939
"github.com/ethereum/go-ethereum/ethclient"
40-
clienttypes "github.com/ethereum/go-ethereum/ethclient/types"
4140
"github.com/ethereum/go-ethereum/node"
4241
"github.com/ethereum/go-ethereum/params"
4342
"github.com/ethereum/go-ethereum/rpc"
@@ -851,7 +850,7 @@ func TestSimulateV1WithBlockOverrides(t *testing.T) {
851850
opts := ethclient.SimulateOptions{
852851
BlockStateCalls: []ethclient.SimulateBlock{
853852
{
854-
BlockOverrides: &clienttypes.BlockOverrides{
853+
BlockOverrides: &ethereum.BlockOverrides{
855854
Time: timestamp,
856855
},
857856
Calls: []ethereum.CallMsg{
@@ -912,7 +911,7 @@ func TestSimulateV1WithStateOverrides(t *testing.T) {
912911
balance := new(big.Int)
913912
balance.SetString(balanceStr, 10)
914913

915-
stateOverrides := map[common.Address]clienttypes.OverrideAccount{
914+
stateOverrides := map[common.Address]ethereum.OverrideAccount{
916915
from: {
917916
Balance: balance,
918917
},

ethclient/gethclient/gethclient.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/ethereum/go-ethereum/common/hexutil"
3030
"github.com/ethereum/go-ethereum/core/types"
3131
"github.com/ethereum/go-ethereum/eth/tracers"
32-
clienttypes "github.com/ethereum/go-ethereum/ethclient/types"
3332
"github.com/ethereum/go-ethereum/p2p"
3433
"github.com/ethereum/go-ethereum/rpc"
3534
)
@@ -280,10 +279,8 @@ func toCallArg(msg ethereum.CallMsg) interface{} {
280279
return arg
281280
}
282281

283-
// OverrideAccount is an alias for ethclient/types.OverrideAccount.
284-
// Deprecated: Use clienttypes.OverrideAccount instead.
285-
type OverrideAccount = clienttypes.OverrideAccount
282+
// OverrideAccount is an alias for ethereum.OverrideAccount.
283+
type OverrideAccount = ethereum.OverrideAccount
286284

287-
// BlockOverrides is an alias for ethclient/types.BlockOverrides.
288-
// Deprecated: Use clienttypes.BlockOverrides instead.
289-
type BlockOverrides = clienttypes.BlockOverrides
285+
// BlockOverrides is an alias for ethereum.BlockOverrides.
286+
type BlockOverrides = ethereum.BlockOverrides

ethclient/types/overrides.go

Lines changed: 0 additions & 121 deletions
This file was deleted.

interfaces.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ package ethereum
1919

2020
import (
2121
"context"
22+
"encoding/json"
2223
"errors"
2324
"math/big"
2425

2526
"github.com/ethereum/go-ethereum/common"
27+
"github.com/ethereum/go-ethereum/common/hexutil"
2628
"github.com/ethereum/go-ethereum/core/types"
2729
)
2830

@@ -281,3 +283,98 @@ type BlockNumberReader interface {
281283
type ChainIDReader interface {
282284
ChainID(ctx context.Context) (*big.Int, error)
283285
}
286+
287+
// OverrideAccount specifies the state of an account to be overridden.
288+
type OverrideAccount struct {
289+
// Nonce sets nonce of the account. Note: the nonce override will only
290+
// be applied when it is set to a non-zero value.
291+
Nonce uint64
292+
293+
// Code sets the contract code. The override will be applied
294+
// when the code is non-nil, i.e. setting empty code is possible
295+
// using an empty slice.
296+
Code []byte
297+
298+
// Balance sets the account balance.
299+
Balance *big.Int
300+
301+
// State sets the complete storage. The override will be applied
302+
// when the given map is non-nil. Using an empty map wipes the
303+
// entire contract storage during the call.
304+
State map[common.Hash]common.Hash
305+
306+
// StateDiff allows overriding individual storage slots.
307+
StateDiff map[common.Hash]common.Hash
308+
}
309+
310+
func (a OverrideAccount) MarshalJSON() ([]byte, error) {
311+
type acc struct {
312+
Nonce hexutil.Uint64 `json:"nonce,omitempty"`
313+
Code string `json:"code,omitempty"`
314+
Balance *hexutil.Big `json:"balance,omitempty"`
315+
State interface{} `json:"state,omitempty"`
316+
StateDiff map[common.Hash]common.Hash `json:"stateDiff,omitempty"`
317+
}
318+
319+
output := acc{
320+
Nonce: hexutil.Uint64(a.Nonce),
321+
Balance: (*hexutil.Big)(a.Balance),
322+
StateDiff: a.StateDiff,
323+
}
324+
if a.Code != nil {
325+
output.Code = hexutil.Encode(a.Code)
326+
}
327+
if a.State != nil {
328+
output.State = a.State
329+
}
330+
return json.Marshal(output)
331+
}
332+
333+
// BlockOverrides specifies the set of header fields to override.
334+
type BlockOverrides struct {
335+
// Number overrides the block number.
336+
Number *big.Int
337+
// Difficulty overrides the block difficulty.
338+
Difficulty *big.Int
339+
// Time overrides the block timestamp. Time is applied only when
340+
// it is non-zero.
341+
Time uint64
342+
// GasLimit overrides the block gas limit. GasLimit is applied only when
343+
// it is non-zero.
344+
GasLimit uint64
345+
// Coinbase overrides the block coinbase. Coinbase is applied only when
346+
// it is different from the zero address.
347+
Coinbase common.Address
348+
// Random overrides the block extra data which feeds into the RANDOM opcode.
349+
// Random is applied only when it is a non-zero hash.
350+
Random common.Hash
351+
// BaseFee overrides the block base fee.
352+
BaseFee *big.Int
353+
}
354+
355+
func (o BlockOverrides) MarshalJSON() ([]byte, error) {
356+
type override struct {
357+
Number *hexutil.Big `json:"number,omitempty"`
358+
Difficulty *hexutil.Big `json:"difficulty,omitempty"`
359+
Time hexutil.Uint64 `json:"time,omitempty"`
360+
GasLimit hexutil.Uint64 `json:"gasLimit,omitempty"`
361+
Coinbase *common.Address `json:"feeRecipient,omitempty"`
362+
Random *common.Hash `json:"prevRandao,omitempty"`
363+
BaseFee *hexutil.Big `json:"baseFeePerGas,omitempty"`
364+
}
365+
366+
output := override{
367+
Number: (*hexutil.Big)(o.Number),
368+
Difficulty: (*hexutil.Big)(o.Difficulty),
369+
Time: hexutil.Uint64(o.Time),
370+
GasLimit: hexutil.Uint64(o.GasLimit),
371+
BaseFee: (*hexutil.Big)(o.BaseFee),
372+
}
373+
if o.Coinbase != (common.Address{}) {
374+
output.Coinbase = &o.Coinbase
375+
}
376+
if o.Random != (common.Hash{}) {
377+
output.Random = &o.Random
378+
}
379+
return json.Marshal(output)
380+
}

0 commit comments

Comments
 (0)