Skip to content

Commit 5c514f6

Browse files
committed
fix cycle import
1 parent 4042a9b commit 5c514f6

File tree

4 files changed

+138
-104
lines changed

4 files changed

+138
-104
lines changed

ethclient/ethclient.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ 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-
"github.com/ethereum/go-ethereum/ethclient/gethclient"
31+
clienttypes "github.com/ethereum/go-ethereum/ethclient/types"
3232
"github.com/ethereum/go-ethereum/rpc"
3333
)
3434

@@ -831,17 +831,17 @@ type SimulateOptions struct {
831831

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

839839
// MarshalJSON implements json.Marshaler for SimulateBlock.
840840
func (s SimulateBlock) MarshalJSON() ([]byte, error) {
841841
type Alias struct {
842-
BlockOverrides *gethclient.BlockOverrides `json:"blockOverrides,omitempty"`
843-
StateOverrides *map[common.Address]gethclient.OverrideAccount `json:"stateOverrides,omitempty"`
844-
Calls []interface{} `json:"calls"`
842+
BlockOverrides *clienttypes.BlockOverrides `json:"blockOverrides,omitempty"`
843+
StateOverrides *map[common.Address]clienttypes.OverrideAccount `json:"stateOverrides,omitempty"`
844+
Calls []interface{} `json:"calls"`
845845
}
846846
calls := make([]interface{}, len(s.Calls))
847847
for i, call := range s.Calls {

ethclient/ethclient_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737
"github.com/ethereum/go-ethereum/eth"
3838
"github.com/ethereum/go-ethereum/eth/ethconfig"
3939
"github.com/ethereum/go-ethereum/ethclient"
40-
"github.com/ethereum/go-ethereum/ethclient/gethclient"
40+
clienttypes "github.com/ethereum/go-ethereum/ethclient/types"
4141
"github.com/ethereum/go-ethereum/node"
4242
"github.com/ethereum/go-ethereum/params"
4343
"github.com/ethereum/go-ethereum/rpc"
@@ -851,7 +851,7 @@ func TestSimulateV1WithBlockOverrides(t *testing.T) {
851851
opts := ethclient.SimulateOptions{
852852
BlockStateCalls: []ethclient.SimulateBlock{
853853
{
854-
BlockOverrides: &gethclient.BlockOverrides{
854+
BlockOverrides: &clienttypes.BlockOverrides{
855855
Time: timestamp,
856856
},
857857
Calls: []ethereum.CallMsg{
@@ -912,7 +912,7 @@ func TestSimulateV1WithStateOverrides(t *testing.T) {
912912
balance := new(big.Int)
913913
balance.SetString(balanceStr, 10)
914914

915-
stateOverrides := map[common.Address]gethclient.OverrideAccount{
915+
stateOverrides := map[common.Address]clienttypes.OverrideAccount{
916916
from: {
917917
Balance: balance,
918918
},

ethclient/gethclient/gethclient.go

Lines changed: 7 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package gethclient
1919

2020
import (
2121
"context"
22-
"encoding/json"
2322
"fmt"
2423
"math/big"
2524
"runtime"
@@ -30,6 +29,7 @@ import (
3029
"github.com/ethereum/go-ethereum/common/hexutil"
3130
"github.com/ethereum/go-ethereum/core/types"
3231
"github.com/ethereum/go-ethereum/eth/tracers"
32+
clienttypes "github.com/ethereum/go-ethereum/ethclient/types"
3333
"github.com/ethereum/go-ethereum/p2p"
3434
"github.com/ethereum/go-ethereum/rpc"
3535
)
@@ -280,97 +280,10 @@ func toCallArg(msg ethereum.CallMsg) interface{} {
280280
return arg
281281
}
282282

283-
// OverrideAccount specifies the state of an account to be overridden.
284-
type OverrideAccount struct {
285-
// Nonce sets nonce of the account. Note: the nonce override will only
286-
// be applied when it is set to a non-zero value.
287-
Nonce uint64
283+
// OverrideAccount is an alias for ethclient/types.OverrideAccount.
284+
// Deprecated: Use ethclienttypes.OverrideAccount instead.
285+
type OverrideAccount = clienttypes.OverrideAccount
288286

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

ethclient/types/overrides.go

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Copyright 2021 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
// Package types contains common types.
18+
package types
19+
20+
import (
21+
"encoding/json"
22+
"math/big"
23+
24+
"github.com/ethereum/go-ethereum/common"
25+
"github.com/ethereum/go-ethereum/common/hexutil"
26+
)
27+
28+
// OverrideAccount specifies the state of an account to be overridden.
29+
type OverrideAccount struct {
30+
// Nonce sets nonce of the account. Note: the nonce override will only
31+
// be applied when it is set to a non-zero value.
32+
Nonce uint64
33+
34+
// Code sets the contract code. The override will be applied
35+
// when the code is non-nil, i.e. setting empty code is possible
36+
// using an empty slice.
37+
Code []byte
38+
39+
// Balance sets the account balance.
40+
Balance *big.Int
41+
42+
// State sets the complete storage. The override will be applied
43+
// when the given map is non-nil. Using an empty map wipes the
44+
// entire contract storage during the call.
45+
State map[common.Hash]common.Hash
46+
47+
// StateDiff allows overriding individual storage slots.
48+
StateDiff map[common.Hash]common.Hash
49+
}
50+
51+
func (a OverrideAccount) MarshalJSON() ([]byte, error) {
52+
type acc struct {
53+
Nonce hexutil.Uint64 `json:"nonce,omitempty"`
54+
Code string `json:"code,omitempty"`
55+
Balance *hexutil.Big `json:"balance,omitempty"`
56+
State interface{} `json:"state,omitempty"`
57+
StateDiff map[common.Hash]common.Hash `json:"stateDiff,omitempty"`
58+
}
59+
60+
output := acc{
61+
Nonce: hexutil.Uint64(a.Nonce),
62+
Balance: (*hexutil.Big)(a.Balance),
63+
StateDiff: a.StateDiff,
64+
}
65+
if a.Code != nil {
66+
output.Code = hexutil.Encode(a.Code)
67+
}
68+
if a.State != nil {
69+
output.State = a.State
70+
}
71+
return json.Marshal(output)
72+
}
73+
74+
// BlockOverrides specifies the set of header fields to override.
75+
type BlockOverrides struct {
76+
// Number overrides the block number.
77+
Number *big.Int
78+
// Difficulty overrides the block difficulty.
79+
Difficulty *big.Int
80+
// Time overrides the block timestamp. Time is applied only when
81+
// it is non-zero.
82+
Time uint64
83+
// GasLimit overrides the block gas limit. GasLimit is applied only when
84+
// it is non-zero.
85+
GasLimit uint64
86+
// Coinbase overrides the block coinbase. Coinbase is applied only when
87+
// it is different from the zero address.
88+
Coinbase common.Address
89+
// Random overrides the block extra data which feeds into the RANDOM opcode.
90+
// Random is applied only when it is a non-zero hash.
91+
Random common.Hash
92+
// BaseFee overrides the block base fee.
93+
BaseFee *big.Int
94+
}
95+
96+
func (o BlockOverrides) MarshalJSON() ([]byte, error) {
97+
type override struct {
98+
Number *hexutil.Big `json:"number,omitempty"`
99+
Difficulty *hexutil.Big `json:"difficulty,omitempty"`
100+
Time hexutil.Uint64 `json:"time,omitempty"`
101+
GasLimit hexutil.Uint64 `json:"gasLimit,omitempty"`
102+
Coinbase *common.Address `json:"feeRecipient,omitempty"`
103+
Random *common.Hash `json:"prevRandao,omitempty"`
104+
BaseFee *hexutil.Big `json:"baseFeePerGas,omitempty"`
105+
}
106+
107+
output := override{
108+
Number: (*hexutil.Big)(o.Number),
109+
Difficulty: (*hexutil.Big)(o.Difficulty),
110+
Time: hexutil.Uint64(o.Time),
111+
GasLimit: hexutil.Uint64(o.GasLimit),
112+
BaseFee: (*hexutil.Big)(o.BaseFee),
113+
}
114+
if o.Coinbase != (common.Address{}) {
115+
output.Coinbase = &o.Coinbase
116+
}
117+
if o.Random != (common.Hash{}) {
118+
output.Random = &o.Random
119+
}
120+
return json.Marshal(output)
121+
}

0 commit comments

Comments
 (0)