2017-08-09 01:53:14 -07:00
|
|
|
// Copyright 2017 AMIS Technologies
|
|
|
|
// 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 container
|
|
|
|
|
|
|
|
import (
|
2017-08-17 03:04:35 -07:00
|
|
|
"crypto/ecdsa"
|
2017-08-11 01:18:35 -07:00
|
|
|
"fmt"
|
2017-09-01 01:52:08 -07:00
|
|
|
"net"
|
2017-08-11 01:18:35 -07:00
|
|
|
|
2017-08-18 00:24:35 -07:00
|
|
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
2017-08-09 01:53:14 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
type Option func(*ethereum)
|
|
|
|
|
2017-08-15 00:09:41 -07:00
|
|
|
func ImageRepository(repository string) Option {
|
2017-08-09 01:53:14 -07:00
|
|
|
return func(eth *ethereum) {
|
2017-08-15 00:09:41 -07:00
|
|
|
eth.imageRepository = repository
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ImageTag(tag string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.imageTag = tag
|
2017-08-09 01:53:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-01 01:52:08 -07:00
|
|
|
func DockerNetworkName(dockerNetworkName string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.dockerNetworkName = dockerNetworkName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-09 01:53:14 -07:00
|
|
|
func HostName(hostName string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.hostName = hostName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-10 23:03:12 -07:00
|
|
|
func HostDataDir(path string) Option {
|
|
|
|
return func(eth *ethereum) {
|
2017-08-17 03:04:35 -07:00
|
|
|
eth.dataDir = path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-01 01:52:08 -07:00
|
|
|
func HostIP(ip net.IP) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.ip = ip.String()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 03:04:35 -07:00
|
|
|
func HostPort(port int) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.port = fmt.Sprintf("%d", port)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func HostRPCPort(port int) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.rpcPort = fmt.Sprintf("%d", port)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func HostWebSocketPort(port int) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.wsPort = fmt.Sprintf("%d", port)
|
2017-08-10 23:03:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Logging(enabled bool) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.logging = enabled
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-05 00:53:15 -07:00
|
|
|
func IsQuorum(isQuorum bool) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.isQuorum = isQuorum
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func DockerEnv(env []string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.dockerEnv = env
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func DockerBinds(binds []string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.dockerBinds = binds
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-09 01:53:14 -07:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2017-08-17 03:04:35 -07:00
|
|
|
func Key(key *ecdsa.PrivateKey) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.key = key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-09 01:53:14 -07:00
|
|
|
func DataDir(dir string) Option {
|
|
|
|
return func(eth *ethereum) {
|
2017-08-17 03:04:35 -07:00
|
|
|
utils.DataDirFlag.Value = utils.DirectoryString{
|
|
|
|
Value: dir,
|
|
|
|
}
|
2017-08-09 01:53:14 -07:00
|
|
|
eth.flags = append(eth.flags, "--"+utils.DataDirFlag.Name)
|
|
|
|
eth.flags = append(eth.flags, dir)
|
2017-08-17 03:04:35 -07:00
|
|
|
|
2017-08-09 01:53:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Etherbase(etherbase string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.EtherbaseFlag.Name)
|
|
|
|
eth.flags = append(eth.flags, etherbase)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Identity(id string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.IdentityFlag.Name)
|
|
|
|
eth.flags = append(eth.flags, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-10 23:03:12 -07:00
|
|
|
func IPC(enabled bool) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
if !enabled {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.IPCDisabledFlag.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-09 01:53:14 -07:00
|
|
|
func KeyStore(dir string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.KeyStoreDirFlag.Name)
|
|
|
|
eth.flags = append(eth.flags, dir)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NetworkID(networkID string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.NetworkIdFlag.Name)
|
|
|
|
eth.flags = append(eth.flags, networkID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Mine() Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.MiningEnabledFlag.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NAT(nat string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.NATFlag.Name)
|
|
|
|
eth.flags = append(eth.flags, nat)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NodeKey(nodekey string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.NodeKeyFileFlag.Name)
|
|
|
|
eth.flags = append(eth.flags, nodekey)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NodeKeyHex(hex string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.NodeKeyHexFlag.Name)
|
|
|
|
eth.flags = append(eth.flags, hex)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NoDiscover() Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.NoDiscoverFlag.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 03:04:35 -07:00
|
|
|
func Port(port int) Option {
|
2017-08-09 01:53:14 -07:00
|
|
|
return func(eth *ethereum) {
|
2017-08-17 03:04:35 -07:00
|
|
|
utils.ListenPortFlag.Value = port
|
2017-08-09 01:53:14 -07:00
|
|
|
eth.flags = append(eth.flags, "--"+utils.ListenPortFlag.Name)
|
2017-08-17 03:04:35 -07:00
|
|
|
eth.flags = append(eth.flags, fmt.Sprintf("%d", port))
|
2017-08-09 01:53:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func RPC() Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.RPCEnabledFlag.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func RPCAddress(address string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.RPCListenAddrFlag.Name)
|
|
|
|
eth.flags = append(eth.flags, address)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func RPCAPI(apis string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.RPCApiFlag.Name)
|
|
|
|
eth.flags = append(eth.flags, apis)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 03:04:35 -07:00
|
|
|
func RPCPort(port int) Option {
|
2017-08-09 01:53:14 -07:00
|
|
|
return func(eth *ethereum) {
|
2017-08-17 03:04:35 -07:00
|
|
|
utils.RPCPortFlag.Value = port
|
2017-08-09 01:53:14 -07:00
|
|
|
eth.flags = append(eth.flags, "--"+utils.RPCPortFlag.Name)
|
2017-08-17 03:04:35 -07:00
|
|
|
eth.flags = append(eth.flags, fmt.Sprintf("%d", port))
|
2017-08-11 01:18:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 00:01:07 -07:00
|
|
|
func WebSocket() Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.WSEnabledFlag.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WebSocketAddress(address string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.WSListenAddrFlag.Name)
|
|
|
|
eth.flags = append(eth.flags, address)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WebSocketAPI(apis string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.WSApiFlag.Name)
|
|
|
|
eth.flags = append(eth.flags, apis)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 03:04:35 -07:00
|
|
|
func WebSocketPort(port int) Option {
|
2017-08-17 00:01:07 -07:00
|
|
|
return func(eth *ethereum) {
|
2017-08-17 03:04:35 -07:00
|
|
|
utils.WSPortFlag.Value = port
|
2017-08-17 00:01:07 -07:00
|
|
|
eth.flags = append(eth.flags, "--"+utils.WSPortFlag.Name)
|
2017-08-17 03:04:35 -07:00
|
|
|
eth.flags = append(eth.flags, fmt.Sprintf("%d", port))
|
2017-08-17 00:01:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WebSocketOrigin(origins string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.WSAllowedOriginsFlag.Name)
|
|
|
|
eth.flags = append(eth.flags, origins)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-11 01:18:35 -07:00
|
|
|
func Verbosity(verbosity int) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--verbosity")
|
|
|
|
eth.flags = append(eth.flags, fmt.Sprintf("%d", verbosity))
|
2017-08-09 01:53:14 -07:00
|
|
|
}
|
|
|
|
}
|
2017-08-24 01:09:59 -07:00
|
|
|
|
|
|
|
func FaultyMode(mode int) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--istanbul.faultymode")
|
|
|
|
eth.flags = append(eth.flags, fmt.Sprintf("%d", mode))
|
|
|
|
}
|
|
|
|
}
|
2017-08-30 18:45:14 -07:00
|
|
|
|
|
|
|
func SyncMode(mode string) Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.SyncModeFlag.Name)
|
|
|
|
eth.flags = append(eth.flags, mode)
|
2017-09-05 00:53:15 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NoUSB() Option {
|
|
|
|
return func(eth *ethereum) {
|
|
|
|
eth.flags = append(eth.flags, "--"+utils.NoUSBFlag.Name)
|
2017-08-30 18:45:14 -07:00
|
|
|
}
|
|
|
|
}
|