mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
accounts/abi/bind/backends: fix review comments
This commit is contained in:
parent
b608a39b2f
commit
cb549c9455
1 changed files with 15 additions and 17 deletions
|
|
@ -28,7 +28,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
||||||
"github.com/ethereum/go-ethereum/eth/filters"
|
"github.com/ethereum/go-ethereum/eth/filters"
|
||||||
"github.com/ethereum/go-ethereum/ethclient"
|
"github.com/ethereum/go-ethereum/ethclient"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
|
|
@ -48,10 +47,10 @@ type SimulatedBackend struct {
|
||||||
// A simulated backend always uses chainID 1337.
|
// A simulated backend always uses chainID 1337.
|
||||||
func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
|
func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
|
||||||
// Setup the node object
|
// Setup the node object
|
||||||
nodeConf := &node.DefaultConfig
|
nodeConf := node.DefaultConfig
|
||||||
nodeConf.DataDir = ""
|
nodeConf.DataDir = ""
|
||||||
nodeConf.P2P = p2p.Config{DiscAddr: "", ListenAddr: ""}
|
nodeConf.P2P = p2p.Config{DiscAddr: "", ListenAddr: ""}
|
||||||
stack, err := node.New(nodeConf)
|
stack, err := node.New(&nodeConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// This should never happen, if it does, please open an issue
|
// This should never happen, if it does, please open an issue
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
@ -63,10 +62,10 @@ func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBac
|
||||||
GasLimit: gasLimit,
|
GasLimit: gasLimit,
|
||||||
Alloc: alloc,
|
Alloc: alloc,
|
||||||
}
|
}
|
||||||
conf := ðconfig.Defaults
|
conf := ethconfig.Defaults
|
||||||
conf.Genesis = &genesis
|
conf.Genesis = &genesis
|
||||||
conf.SyncMode = downloader.FullSync
|
conf.SyncMode = downloader.FullSync
|
||||||
sim, err := NewSimWithNode(stack, conf, math.MaxUint64)
|
sim, err := NewSimWithNode(stack, &conf, math.MaxUint64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// This should never happen, if it does, please open an issue
|
// This should never happen, if it does, please open an issue
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
@ -76,6 +75,7 @@ func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBac
|
||||||
|
|
||||||
// NewSimWithNode sets up a simulated backend on an existing node
|
// NewSimWithNode sets up a simulated backend on an existing node
|
||||||
// this allows users to do persistent simulations.
|
// this allows users to do persistent simulations.
|
||||||
|
// The provided node must not be started and will be started by NewSimWithNode
|
||||||
func NewSimWithNode(stack *node.Node, conf *eth.Config, blockPeriod uint64) (*SimulatedBackend, error) {
|
func NewSimWithNode(stack *node.Node, conf *eth.Config, blockPeriod uint64) (*SimulatedBackend, error) {
|
||||||
backend, err := eth.New(stack, conf)
|
backend, err := eth.New(stack, conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -113,16 +113,14 @@ func NewSimWithNode(stack *node.Node, conf *eth.Config, blockPeriod uint64) (*Si
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *SimulatedBackend) Close() error {
|
func (n *SimulatedBackend) Close() error {
|
||||||
|
if n.Client != nil {
|
||||||
n.Client.Close()
|
n.Client.Close()
|
||||||
return n.SimulatedBeacon.Stop()
|
n.Client = nil
|
||||||
}
|
}
|
||||||
|
if n.SimulatedBeacon != nil {
|
||||||
// Blockchain is needed for LES-tests
|
err := n.SimulatedBeacon.Stop()
|
||||||
func (n *SimulatedBackend) Blockchain() *core.BlockChain {
|
n.SimulatedBeacon = nil
|
||||||
return n.eth.BlockChain()
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
// ChainDB is needed for LES-tests
|
|
||||||
func (n *SimulatedBackend) ChainDB() ethdb.Database {
|
|
||||||
return n.eth.ChainDb()
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue