simulated: add WithHTTPRPCServer config

Introduce a new WithHTTPRPCServer function to configure
the simulated backend with host, port, and modules:
- Enable HTTP-based RPC access for local testing
- Simplify node setup for developers and testers
This commit is contained in:
bruwbird 2025-02-27 10:27:51 +09:00
parent 939a804146
commit d721503da6
No known key found for this signature in database
GPG Key ID: 732FA57F481F577C
1 changed files with 14 additions and 0 deletions

View File

@ -53,3 +53,17 @@ func WithMinerMinTip(tip *big.Int) func(nodeConf *node.Config, ethConf *ethconfi
ethConf.Miner.GasPrice = tip ethConf.Miner.GasPrice = tip
} }
} }
// WithHTTPRPCServer configures the simulated backend so that the node runs an HTTP server
// on the specified host and port, and enables the specified HTTP modules.
// Example usage:
//
// NewBackend(alloc, WithHTTPRPCServer("localhost", 8545, []string{"eth", "net", "web3"}))
func WithHTTPRPCServer(host string, port int,
modules []string) func(nodeConf *node.Config, ethConf *ethconfig.Config) {
return func(nodeConf *node.Config, ethConf *ethconfig.Config) {
nodeConf.HTTPHost = host
nodeConf.HTTPPort = port
nodeConf.HTTPModules = modules
}
}