mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
fix cycle import
This commit is contained in:
parent
4042a9ba1b
commit
5c514f6bcc
4 changed files with 138 additions and 104 deletions
|
|
@ -28,7 +28,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethclient/gethclient"
|
clienttypes "github.com/ethereum/go-ethereum/ethclient/types"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -831,16 +831,16 @@ type SimulateOptions struct {
|
||||||
|
|
||||||
// SimulateBlock represents a batch of calls to be simulated.
|
// SimulateBlock represents a batch of calls to be simulated.
|
||||||
type SimulateBlock struct {
|
type SimulateBlock struct {
|
||||||
BlockOverrides *gethclient.BlockOverrides `json:"blockOverrides,omitempty"`
|
BlockOverrides *clienttypes.BlockOverrides `json:"blockOverrides,omitempty"`
|
||||||
StateOverrides *map[common.Address]gethclient.OverrideAccount `json:"stateOverrides,omitempty"`
|
StateOverrides *map[common.Address]clienttypes.OverrideAccount `json:"stateOverrides,omitempty"`
|
||||||
Calls []ethereum.CallMsg `json:"calls"`
|
Calls []ethereum.CallMsg `json:"calls"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON implements json.Marshaler for SimulateBlock.
|
// MarshalJSON implements json.Marshaler for SimulateBlock.
|
||||||
func (s SimulateBlock) MarshalJSON() ([]byte, error) {
|
func (s SimulateBlock) MarshalJSON() ([]byte, error) {
|
||||||
type Alias struct {
|
type Alias struct {
|
||||||
BlockOverrides *gethclient.BlockOverrides `json:"blockOverrides,omitempty"`
|
BlockOverrides *clienttypes.BlockOverrides `json:"blockOverrides,omitempty"`
|
||||||
StateOverrides *map[common.Address]gethclient.OverrideAccount `json:"stateOverrides,omitempty"`
|
StateOverrides *map[common.Address]clienttypes.OverrideAccount `json:"stateOverrides,omitempty"`
|
||||||
Calls []interface{} `json:"calls"`
|
Calls []interface{} `json:"calls"`
|
||||||
}
|
}
|
||||||
calls := make([]interface{}, len(s.Calls))
|
calls := make([]interface{}, len(s.Calls))
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
||||||
"github.com/ethereum/go-ethereum/ethclient"
|
"github.com/ethereum/go-ethereum/ethclient"
|
||||||
"github.com/ethereum/go-ethereum/ethclient/gethclient"
|
clienttypes "github.com/ethereum/go-ethereum/ethclient/types"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
|
@ -851,7 +851,7 @@ func TestSimulateV1WithBlockOverrides(t *testing.T) {
|
||||||
opts := ethclient.SimulateOptions{
|
opts := ethclient.SimulateOptions{
|
||||||
BlockStateCalls: []ethclient.SimulateBlock{
|
BlockStateCalls: []ethclient.SimulateBlock{
|
||||||
{
|
{
|
||||||
BlockOverrides: &gethclient.BlockOverrides{
|
BlockOverrides: &clienttypes.BlockOverrides{
|
||||||
Time: timestamp,
|
Time: timestamp,
|
||||||
},
|
},
|
||||||
Calls: []ethereum.CallMsg{
|
Calls: []ethereum.CallMsg{
|
||||||
|
|
@ -912,7 +912,7 @@ func TestSimulateV1WithStateOverrides(t *testing.T) {
|
||||||
balance := new(big.Int)
|
balance := new(big.Int)
|
||||||
balance.SetString(balanceStr, 10)
|
balance.SetString(balanceStr, 10)
|
||||||
|
|
||||||
stateOverrides := map[common.Address]gethclient.OverrideAccount{
|
stateOverrides := map[common.Address]clienttypes.OverrideAccount{
|
||||||
from: {
|
from: {
|
||||||
Balance: balance,
|
Balance: balance,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ package gethclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -30,6 +29,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/eth/tracers"
|
"github.com/ethereum/go-ethereum/eth/tracers"
|
||||||
|
clienttypes "github.com/ethereum/go-ethereum/ethclient/types"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
)
|
)
|
||||||
|
|
@ -280,97 +280,10 @@ func toCallArg(msg ethereum.CallMsg) interface{} {
|
||||||
return arg
|
return arg
|
||||||
}
|
}
|
||||||
|
|
||||||
// OverrideAccount specifies the state of an account to be overridden.
|
// OverrideAccount is an alias for ethclient/types.OverrideAccount.
|
||||||
type OverrideAccount struct {
|
// Deprecated: Use ethclienttypes.OverrideAccount instead.
|
||||||
// Nonce sets nonce of the account. Note: the nonce override will only
|
type OverrideAccount = clienttypes.OverrideAccount
|
||||||
// be applied when it is set to a non-zero value.
|
|
||||||
Nonce uint64
|
|
||||||
|
|
||||||
// Code sets the contract code. The override will be applied
|
// BlockOverrides is an alias for ethclient/types.BlockOverrides.
|
||||||
// when the code is non-nil, i.e. setting empty code is possible
|
// Deprecated: Use ethclienttypes.BlockOverrides instead.
|
||||||
// using an empty slice.
|
type BlockOverrides = clienttypes.BlockOverrides
|
||||||
Code []byte
|
|
||||||
|
|
||||||
// Balance sets the account balance.
|
|
||||||
Balance *big.Int
|
|
||||||
|
|
||||||
// State sets the complete storage. The override will be applied
|
|
||||||
// when the given map is non-nil. Using an empty map wipes the
|
|
||||||
// entire contract storage during the call.
|
|
||||||
State map[common.Hash]common.Hash
|
|
||||||
|
|
||||||
// StateDiff allows overriding individual storage slots.
|
|
||||||
StateDiff map[common.Hash]common.Hash
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a OverrideAccount) MarshalJSON() ([]byte, error) {
|
|
||||||
type acc struct {
|
|
||||||
Nonce hexutil.Uint64 `json:"nonce,omitempty"`
|
|
||||||
Code string `json:"code,omitempty"`
|
|
||||||
Balance *hexutil.Big `json:"balance,omitempty"`
|
|
||||||
State interface{} `json:"state,omitempty"`
|
|
||||||
StateDiff map[common.Hash]common.Hash `json:"stateDiff,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
output := acc{
|
|
||||||
Nonce: hexutil.Uint64(a.Nonce),
|
|
||||||
Balance: (*hexutil.Big)(a.Balance),
|
|
||||||
StateDiff: a.StateDiff,
|
|
||||||
}
|
|
||||||
if a.Code != nil {
|
|
||||||
output.Code = hexutil.Encode(a.Code)
|
|
||||||
}
|
|
||||||
if a.State != nil {
|
|
||||||
output.State = a.State
|
|
||||||
}
|
|
||||||
return json.Marshal(output)
|
|
||||||
}
|
|
||||||
|
|
||||||
// BlockOverrides specifies the set of header fields to override.
|
|
||||||
type BlockOverrides struct {
|
|
||||||
// Number overrides the block number.
|
|
||||||
Number *big.Int
|
|
||||||
// Difficulty overrides the block difficulty.
|
|
||||||
Difficulty *big.Int
|
|
||||||
// Time overrides the block timestamp. Time is applied only when
|
|
||||||
// it is non-zero.
|
|
||||||
Time uint64
|
|
||||||
// GasLimit overrides the block gas limit. GasLimit is applied only when
|
|
||||||
// it is non-zero.
|
|
||||||
GasLimit uint64
|
|
||||||
// Coinbase overrides the block coinbase. Coinbase is applied only when
|
|
||||||
// it is different from the zero address.
|
|
||||||
Coinbase common.Address
|
|
||||||
// Random overrides the block extra data which feeds into the RANDOM opcode.
|
|
||||||
// Random is applied only when it is a non-zero hash.
|
|
||||||
Random common.Hash
|
|
||||||
// BaseFee overrides the block base fee.
|
|
||||||
BaseFee *big.Int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o BlockOverrides) MarshalJSON() ([]byte, error) {
|
|
||||||
type override struct {
|
|
||||||
Number *hexutil.Big `json:"number,omitempty"`
|
|
||||||
Difficulty *hexutil.Big `json:"difficulty,omitempty"`
|
|
||||||
Time hexutil.Uint64 `json:"time,omitempty"`
|
|
||||||
GasLimit hexutil.Uint64 `json:"gasLimit,omitempty"`
|
|
||||||
Coinbase *common.Address `json:"feeRecipient,omitempty"`
|
|
||||||
Random *common.Hash `json:"prevRandao,omitempty"`
|
|
||||||
BaseFee *hexutil.Big `json:"baseFeePerGas,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
output := override{
|
|
||||||
Number: (*hexutil.Big)(o.Number),
|
|
||||||
Difficulty: (*hexutil.Big)(o.Difficulty),
|
|
||||||
Time: hexutil.Uint64(o.Time),
|
|
||||||
GasLimit: hexutil.Uint64(o.GasLimit),
|
|
||||||
BaseFee: (*hexutil.Big)(o.BaseFee),
|
|
||||||
}
|
|
||||||
if o.Coinbase != (common.Address{}) {
|
|
||||||
output.Coinbase = &o.Coinbase
|
|
||||||
}
|
|
||||||
if o.Random != (common.Hash{}) {
|
|
||||||
output.Random = &o.Random
|
|
||||||
}
|
|
||||||
return json.Marshal(output)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
121
ethclient/types/overrides.go
Normal file
121
ethclient/types/overrides.go
Normal file
|
|
@ -0,0 +1,121 @@
|
||||||
|
// Copyright 2021 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Package types contains common types.
|
||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
// OverrideAccount specifies the state of an account to be overridden.
|
||||||
|
type OverrideAccount struct {
|
||||||
|
// Nonce sets nonce of the account. Note: the nonce override will only
|
||||||
|
// be applied when it is set to a non-zero value.
|
||||||
|
Nonce uint64
|
||||||
|
|
||||||
|
// Code sets the contract code. The override will be applied
|
||||||
|
// when the code is non-nil, i.e. setting empty code is possible
|
||||||
|
// using an empty slice.
|
||||||
|
Code []byte
|
||||||
|
|
||||||
|
// Balance sets the account balance.
|
||||||
|
Balance *big.Int
|
||||||
|
|
||||||
|
// State sets the complete storage. The override will be applied
|
||||||
|
// when the given map is non-nil. Using an empty map wipes the
|
||||||
|
// entire contract storage during the call.
|
||||||
|
State map[common.Hash]common.Hash
|
||||||
|
|
||||||
|
// StateDiff allows overriding individual storage slots.
|
||||||
|
StateDiff map[common.Hash]common.Hash
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a OverrideAccount) MarshalJSON() ([]byte, error) {
|
||||||
|
type acc struct {
|
||||||
|
Nonce hexutil.Uint64 `json:"nonce,omitempty"`
|
||||||
|
Code string `json:"code,omitempty"`
|
||||||
|
Balance *hexutil.Big `json:"balance,omitempty"`
|
||||||
|
State interface{} `json:"state,omitempty"`
|
||||||
|
StateDiff map[common.Hash]common.Hash `json:"stateDiff,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
output := acc{
|
||||||
|
Nonce: hexutil.Uint64(a.Nonce),
|
||||||
|
Balance: (*hexutil.Big)(a.Balance),
|
||||||
|
StateDiff: a.StateDiff,
|
||||||
|
}
|
||||||
|
if a.Code != nil {
|
||||||
|
output.Code = hexutil.Encode(a.Code)
|
||||||
|
}
|
||||||
|
if a.State != nil {
|
||||||
|
output.State = a.State
|
||||||
|
}
|
||||||
|
return json.Marshal(output)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BlockOverrides specifies the set of header fields to override.
|
||||||
|
type BlockOverrides struct {
|
||||||
|
// Number overrides the block number.
|
||||||
|
Number *big.Int
|
||||||
|
// Difficulty overrides the block difficulty.
|
||||||
|
Difficulty *big.Int
|
||||||
|
// Time overrides the block timestamp. Time is applied only when
|
||||||
|
// it is non-zero.
|
||||||
|
Time uint64
|
||||||
|
// GasLimit overrides the block gas limit. GasLimit is applied only when
|
||||||
|
// it is non-zero.
|
||||||
|
GasLimit uint64
|
||||||
|
// Coinbase overrides the block coinbase. Coinbase is applied only when
|
||||||
|
// it is different from the zero address.
|
||||||
|
Coinbase common.Address
|
||||||
|
// Random overrides the block extra data which feeds into the RANDOM opcode.
|
||||||
|
// Random is applied only when it is a non-zero hash.
|
||||||
|
Random common.Hash
|
||||||
|
// BaseFee overrides the block base fee.
|
||||||
|
BaseFee *big.Int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o BlockOverrides) MarshalJSON() ([]byte, error) {
|
||||||
|
type override struct {
|
||||||
|
Number *hexutil.Big `json:"number,omitempty"`
|
||||||
|
Difficulty *hexutil.Big `json:"difficulty,omitempty"`
|
||||||
|
Time hexutil.Uint64 `json:"time,omitempty"`
|
||||||
|
GasLimit hexutil.Uint64 `json:"gasLimit,omitempty"`
|
||||||
|
Coinbase *common.Address `json:"feeRecipient,omitempty"`
|
||||||
|
Random *common.Hash `json:"prevRandao,omitempty"`
|
||||||
|
BaseFee *hexutil.Big `json:"baseFeePerGas,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
output := override{
|
||||||
|
Number: (*hexutil.Big)(o.Number),
|
||||||
|
Difficulty: (*hexutil.Big)(o.Difficulty),
|
||||||
|
Time: hexutil.Uint64(o.Time),
|
||||||
|
GasLimit: hexutil.Uint64(o.GasLimit),
|
||||||
|
BaseFee: (*hexutil.Big)(o.BaseFee),
|
||||||
|
}
|
||||||
|
if o.Coinbase != (common.Address{}) {
|
||||||
|
output.Coinbase = &o.Coinbase
|
||||||
|
}
|
||||||
|
if o.Random != (common.Hash{}) {
|
||||||
|
output.Random = &o.Random
|
||||||
|
}
|
||||||
|
return json.Marshal(output)
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue