utils

package
v0.0.0-...-f5e5c7e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2017 License: GPL-3.0 Imports: 39 Imported by: 3

Documentation

Overview

Package utils contains internal helper functions for go-earthdollar commands.

Index

Constants

This section is empty.

Variables

View Source
var (
	// General settings
	DataDirFlag = DirectoryFlag{
		Name:  "datadir",
		Usage: "Data directory for the databases and keystore",
		Value: DirectoryString{common.DefaultDataDir()},
	}
	KeyStoreDirFlag = DirectoryFlag{
		Name:  "keystore",
		Usage: "Directory for the keystore (default = inside the datadir)",
	}
	NetworkIdFlag = cli.IntFlag{
		Name:  "networkid",
		Usage: "Network identifier (integer, 0=Olympic, 1=Homestead, 2=Morden)",
		Value: ed.NetworkId,
	}
	OlympicFlag = cli.BoolFlag{
		Name:  "olympic",
		Usage: "Olympic network: pre-configured pre-release test network",
	}
	TestNetFlag = cli.BoolFlag{
		Name:  "testnet",
		Usage: "Morden network: pre-configured test network with modified starting nonces (replay protection)",
	}
	DevModeFlag = cli.BoolFlag{
		Name:  "dev",
		Usage: "Developer mode: pre-configured private network with several debugging flags",
	}
	IdentityFlag = cli.StringFlag{
		Name:  "identity",
		Usage: "Custom node name",
	}
	NatspecEnabledFlag = cli.BoolFlag{
		Name:  "natspec",
		Usage: "Enable NatSpec confirmation notice",
	}
	DocRootFlag = DirectoryFlag{
		Name:  "docroot",
		Usage: "Document Root for HTTPClient file scheme",
		Value: DirectoryString{common.HomeDir()},
	}
	CacheFlag = cli.IntFlag{
		Name:  "cache",
		Usage: "Megabytes of memory allocated to internal caching (min 16MB / database forced)",
		Value: 128,
	}
	BlockchainVersionFlag = cli.IntFlag{
		Name:  "blockchainversion",
		Usage: "Blockchain version (integer)",
		Value: core.BlockChainVersion,
	}
	FastSyncFlag = cli.BoolFlag{
		Name:  "fast",
		Usage: "Enable fast syncing through state downloads",
	}
	LightKDFFlag = cli.BoolFlag{
		Name:  "lightkdf",
		Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength",
	}
	// Network Split settings
	ETFChain = cli.BoolFlag{
		Name:  "etf",
		Usage: "Updates the chain rules to use the ETF hard-fork blockchain",
	}
	// Miner settings
	// TODO Refactor CPU vs GPU mining flags
	MiningEnabledFlag = cli.BoolFlag{
		Name:  "mine",
		Usage: "Enable mining",
	}
	MinerThreadsFlag = cli.IntFlag{
		Name:  "minerthreads",
		Usage: "Number of CPU threads to use for mining",
		Value: runtime.NumCPU(),
	}
	MiningGPUFlag = cli.StringFlag{
		Name:  "minergpus",
		Usage: "List of GPUs to use for mining (e.g. '0,1' will use the first two GPUs found)",
	}
	TargetGasLimitFlag = cli.StringFlag{
		Name:  "targetgaslimit",
		Usage: "Target gas limit sets the artificial target gas floor for the blocks to mine",
		Value: params.GenesisGasLimit.String(),
	}
	AutoDAGFlag = cli.BoolFlag{
		Name:  "autodag",
		Usage: "Enable automatic DAG pregeneration",
	}
	EarthbaseFlag = cli.StringFlag{
		Name:  "earthbase",
		Usage: "Public address for block mining rewards (default = first account created)",
		Value: "0",
	}
	GasPriceFlag = cli.StringFlag{
		Name:  "gasprice",
		Usage: "Minimal gas price to accept for mining a transactions",
		Value: new(big.Int).Mul(big.NewInt(20), common.Shannon).String(),
	}
	ExtraDataFlag = cli.StringFlag{
		Name:  "extradata",
		Usage: "Block extra data set by the miner (default = client version)",
	}
	// Account settings
	UnlockedAccountFlag = cli.StringFlag{
		Name:  "unlock",
		Usage: "Comma separated list of accounts to unlock",
		Value: "",
	}
	PasswordFileFlag = cli.StringFlag{
		Name:  "password",
		Usage: "Password file to use for non-inteactive password input",
		Value: "",
	}

	VMForceJitFlag = cli.BoolFlag{
		Name:  "forcejit",
		Usage: "Force the JIT VM to take precedence",
	}
	VMJitCacheFlag = cli.IntFlag{
		Name:  "jitcache",
		Usage: "Amount of cached JIT VM programs",
		Value: 64,
	}
	VMEnableJitFlag = cli.BoolFlag{
		Name:  "jitvm",
		Usage: "Enable the JIT VM",
	}

	// logging and debug settings
	MetricsFlag = cli.StringFlag{
		Name:  "metrics",
		Usage: "Enables metrics reporting. When the value is a path, either relative or absolute, then a log is written to the respective file.",
	}
	FakePoWFlag = cli.BoolFlag{
		Name:  "fakepow",
		Usage: "Disables proof-of-work verification",
	}

	// RPC settings
	RPCEnabledFlag = cli.BoolFlag{
		Name:  "rpc",
		Usage: "Enable the HTTP-RPC server",
	}
	RPCListenAddrFlag = cli.StringFlag{
		Name:  "rpcaddr",
		Usage: "HTTP-RPC server listening interface",
		Value: common.DefaultHTTPHost,
	}
	RPCPortFlag = cli.IntFlag{
		Name:  "rpcport",
		Usage: "HTTP-RPC server listening port",
		Value: common.DefaultHTTPPort,
	}
	RPCCORSDomainFlag = cli.StringFlag{
		Name:  "rpccorsdomain",
		Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)",
		Value: "",
	}
	RPCApiFlag = cli.StringFlag{
		Name:  "rpcapi",
		Usage: "API's offered over the HTTP-RPC interface",
		Value: rpc.DefaultHTTPApis,
	}
	IPCDisabledFlag = cli.BoolFlag{
		Name:  "ipcdisable",
		Usage: "Disable the IPC-RPC server",
	}
	IPCApiFlag = cli.StringFlag{
		Name:  "ipcapi",
		Usage: "API's offered over the IPC-RPC interface",
		Value: rpc.DefaultIPCApis,
	}
	IPCPathFlag = DirectoryFlag{
		Name:  "ipcpath",
		Usage: "Filename for IPC socket/pipe within the datadir (explicit paths escape it)",
		Value: DirectoryString{common.DefaultIPCSocket},
	}
	WSEnabledFlag = cli.BoolFlag{
		Name:  "ws",
		Usage: "Enable the WS-RPC server",
	}
	WSListenAddrFlag = cli.StringFlag{
		Name:  "wsaddr",
		Usage: "WS-RPC server listening interface",
		Value: common.DefaultWSHost,
	}
	WSPortFlag = cli.IntFlag{
		Name:  "wsport",
		Usage: "WS-RPC server listening port",
		Value: common.DefaultWSPort,
	}
	WSApiFlag = cli.StringFlag{
		Name:  "wsapi",
		Usage: "API's offered over the WS-RPC interface",
		Value: rpc.DefaultHTTPApis,
	}
	WSAllowedOriginsFlag = cli.StringFlag{
		Name:  "wsorigins",
		Usage: "Origins from which to accept websockets requests",
		Value: "",
	}
	ExecFlag = cli.StringFlag{
		Name:  "exec",
		Usage: "Execute JavaScript statement (only in combination with console/attach)",
	}
	PreloadJSFlag = cli.StringFlag{
		Name:  "preload",
		Usage: "Comma separated list of JavaScript files to preload into the console",
	}

	// Network Settings
	MaxPeersFlag = cli.IntFlag{
		Name:  "maxpeers",
		Usage: "Maximum number of network peers (network disabled if set to 0)",
		Value: 25,
	}
	MaxPendingPeersFlag = cli.IntFlag{
		Name:  "maxpendpeers",
		Usage: "Maximum number of pending connection attempts (defaults used if set to 0)",
		Value: 0,
	}
	ListenPortFlag = cli.IntFlag{
		Name:  "port",
		Usage: "Network listening port",
		Value: 20203,
	}
	BootnodesFlag = cli.StringFlag{
		Name:  "bootnodes",
		Usage: "Comma separated enode URLs for P2P discovery bootstrap",
		Value: "",
	}
	NodeKeyFileFlag = cli.StringFlag{
		Name:  "nodekey",
		Usage: "P2P node key file",
	}
	NodeKeyHexFlag = cli.StringFlag{
		Name:  "nodekeyhex",
		Usage: "P2P node key as hex (for testing)",
	}
	NATFlag = cli.StringFlag{
		Name:  "nat",
		Usage: "NAT port mapping mechanism (any|none|upnp|pmp|extip:<IP>)",
		Value: "any",
	}
	NoDiscoverFlag = cli.BoolFlag{
		Name:  "nodiscover",
		Usage: "Disables the peer discovery mechanism (manual peer addition)",
	}
	WhisperEnabledFlag = cli.BoolFlag{
		Name:  "shh",
		Usage: "Enable Whisper",
	}
	// ATM the url is left to the user and deployment to
	JSpathFlag = cli.StringFlag{
		Name:  "jspath",
		Usage: "JavaScript root path for `loadScript` and document root for `admin.httpGet`",
		Value: ".",
	}
	SolcPathFlag = cli.StringFlag{
		Name:  "solc",
		Usage: "Solidity compiler command to be used",
		Value: "solc",
	}

	// Gas price oracle settings
	GpoMinGasPriceFlag = cli.StringFlag{
		Name:  "gpomin",
		Usage: "Minimum suggested gas price",
		Value: new(big.Int).Mul(big.NewInt(20), common.Shannon).String(),
	}
	GpoMaxGasPriceFlag = cli.StringFlag{
		Name:  "gpomax",
		Usage: "Maximum suggested gas price",
		Value: new(big.Int).Mul(big.NewInt(500), common.Shannon).String(),
	}
	GpoFullBlockRatioFlag = cli.IntFlag{
		Name:  "gpofull",
		Usage: "Full block threshold for gas price calculation (%)",
		Value: 80,
	}
	GpobaseStepDownFlag = cli.IntFlag{
		Name:  "gpobasedown",
		Usage: "Suggested gas price base step down ratio (1/1000)",
		Value: 10,
	}
	GpobaseStepUpFlag = cli.IntFlag{
		Name:  "gpobaseup",
		Usage: "Suggested gas price base step up ratio (1/1000)",
		Value: 100,
	}
	GpobaseCorrectionFactorFlag = cli.IntFlag{
		Name:  "gpobasecf",
		Usage: "Suggested gas price base correction factor (%)",
		Value: 110,
	}
	Unused1 = cli.BoolFlag{
		Name:  "oppose-dao-fork",
		Usage: "Use classic blockchain (always set, flag is unused and exists for compatibility only)",
	}
)
View Source
var HomesteadBootNodes = []*discover.Node{

	discover.MustParseNode("enode://ec8ae764f7cb0417bdfb009b9d0f18ab3818a3a4e8e7c67dd5f18971a93510a2e6f43cd0b69a27e439a9629457ea804104f37c85e41eed057d3faabbf7744cdf@13.74.157.139:30429"),
	discover.MustParseNode("enode://c2e1fceb3bf3be19dff71eec6cccf19f2dbf7567ee017d130240c670be8594bc9163353ca55dd8df7a4f161dd94b36d0615c17418b5a3cdcbb4e9d99dfa4de37@13.74.157.139:30430"),
	discover.MustParseNode("enode://fe29b82319b734ce1ec68b84657d57145fee237387e63273989d354486731e59f78858e452ef800a020559da22dcca759536e6aa5517c53930d29ce0b1029286@13.74.157.139:30431"),
}

HomesteadBootNodes are the enode URLs of the P2P bootstrap nodes running on the Homestead network.

View Source
var TestNetBootNodes = []*discover.Node{

	discover.MustParseNode("enode://1d7187e7bde45cf0bee489ce9852dd6d1a0d9aa67a33a6b8e6db8a4fbc6fcfa6f0f1a5419343671521b863b187d1c73bad3603bae66421d157ffef357669ddb8@13.74.157.139:30432"),

	discover.MustParseNode("enode://0e4cba800f7b1ee73673afa6a4acead4018f0149d2e3216be3f133318fd165b324cd71b81fbe1e80deac8dbf56e57a49db7be67f8b9bc81bd2b7ee496434fb5d@13.74.157.139:30433"),
}

TestNetBootNodes are the enode URLs of the P2P bootstrap nodes running on the Morden test network.

Functions

func ExportAppendChain

func ExportAppendChain(blockchain *core.BlockChain, fn string, first uint64, last uint64) error

func ExportChain

func ExportChain(blockchain *core.BlockChain, fn string) error

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf formats a message to standard error and exits the program. The message is also printed to standard output if standard error is redirected to a different file.

func ImportChain

func ImportChain(chain *core.BlockChain, fn string) error

func MakeAccountManager

func MakeAccountManager(ctx *cli.Context) *accounts.Manager

MakeAccountManager creates an account manager from set command line flags.

func MakeAddress

func MakeAddress(accman *accounts.Manager, account string) (accounts.Account, error)

MakeAddress converts an account specified directly as a hex encoded string or a key index in the key store to an internal account representation.

func MakeBootstrapNodes

func MakeBootstrapNodes(ctx *cli.Context) []*discover.Node

MakeBootstrapNodes creates a list of bootstrap nodes from the command line flags, reverting to pre-configured ones if none have been specified.

func MakeChain

func MakeChain(ctx *cli.Context) (chain *core.BlockChain, chainDb ethdb.Database)

MakeChain creates a chain manager from set command line flags.

func MakeChainDatabase

func MakeChainDatabase(ctx *cli.Context) ethdb.Database

MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.

func MakeConsolePreloads

func MakeConsolePreloads(ctx *cli.Context) []string

MakeConsolePreloads retrieves the absolute paths for the console JavaScript scripts to preload before starting.

func MakeDatabaseHandles

func MakeDatabaseHandles() int

MakeDatabaseHandles raises out the number of allowed file handles per process for Ged and returns half of the allowance to assign to the database.

func MakeEarthbase

func MakeEarthbase(accman *accounts.Manager, ctx *cli.Context) common.Address

MakeEarthbase retrieves the earthbase either from the directly specified command line flags or from the keystore if CLI indexed.

func MakeHTTPRpcHost

func MakeHTTPRpcHost(ctx *cli.Context) string

MakeHTTPRpcHost creates the HTTP RPC listener interface string from the set command line flags, returning empty if the HTTP endpoint is disabled.

func MakeIPCPath

func MakeIPCPath(ctx *cli.Context) string

MakeIPCPath creates an IPC path configuration from the set command line flags, returning an empty string if IPC was explicitly disabled, or the set path.

func MakeListenAddress

func MakeListenAddress(ctx *cli.Context) string

MakeListenAddress creates a TCP listening address string from set command line flags.

func MakeMinerExtra

func MakeMinerExtra(extra []byte, ctx *cli.Context) []byte

MakeMinerExtra resolves extradata for the miner from the set command line flags or returns a default one composed on the client, runtime and OS metadata.

func MakeNAT

func MakeNAT(ctx *cli.Context) nat.Interface

MakeNAT creates a port mapper from set command line flags.

func MakeNodeKey

func MakeNodeKey(ctx *cli.Context) *ecdsa.PrivateKey

MakeNodeKey creates a node key from set command line flags, either loading it from a file or as a specified hex value. If neither flags were provided, this method returns nil and an emphemeral key is to be generated.

func MakeNodeName

func MakeNodeName(client, version string, ctx *cli.Context) string

MakeNodeName creates a node name from a base set and the command line flags.

func MakePasswordList

func MakePasswordList(ctx *cli.Context) []string

MakePasswordList reads password lines from the file specified by --password.

func MakeRPCModules

func MakeRPCModules(input string) []string

MakeRPCModules splits input separated by a comma and trims excessive white space from the substrings.

func MakeSystemNode

func MakeSystemNode(name, version string, relconf release.Config, extra []byte, ctx *cli.Context) *node.Node

MakeSystemNode sets up a local node, configures the services to launch and assembles the P2P protocol stack.

func MakeWSRpcHost

func MakeWSRpcHost(ctx *cli.Context) string

MakeWSRpcHost creates the WebSocket RPC listener interface string from the set command line flags, returning empty if the HTTP endpoint is disabled.

func MustMakeChainConfig

func MustMakeChainConfig(ctx *cli.Context) *core.ChainConfig

MustMakeChainConfig reads the chain configuration from the database in ctx.Datadir.

func MustMakeChainConfigFromDb

func MustMakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainConfig

MustMakeChainConfigFromDb reads the chain configuration from the given database.

func MustMakeDataDir

func MustMakeDataDir(ctx *cli.Context) string

MustMakeDataDir retrieves the currently requested data directory, terminating if none (or the empty string) is specified. If the node is starting a testnet, the a subdirectory of the specified datadir will be used.

func NewApp

func NewApp(version, usage string) *cli.App

NewApp creates an app with sane defaults.

func NewRemoteRPCClient

func NewRemoteRPCClient(ctx *cli.Context) (rpc.Client, error)

NewRemoteRPCClient returns a RPC client which connects to a running ged instance. Depending on the given context this can either be a IPC or a HTTP client.

func NewRemoteRPCClientFromString

func NewRemoteRPCClientFromString(endpoint string) (rpc.Client, error)

NewRemoteRPCClientFromString returns a RPC client which connects to the given endpoint. It must start with either `ipc:` or `rpc:` (HTTP).

func SetupNetwork

func SetupNetwork(ctx *cli.Context)

SetupNetwork configures the system for either the main net or some test network.

func StartNode

func StartNode(stack *node.Node)

Types

type DirectoryFlag

type DirectoryFlag struct {
	cli.GenericFlag
	Name   string
	Value  DirectoryString
	Usage  string
	EnvVar string
}

Custom cli.Flag type which expand the received string to an absolute path. e.g. ~/.earthdollar -> /home/username/.earthdollar

func (DirectoryFlag) Apply

func (self DirectoryFlag) Apply(set *flag.FlagSet)

called by cli library, grabs variable from environment (if in env) and adds variable to flag set for parsing.

func (*DirectoryFlag) Set

func (self *DirectoryFlag) Set(value string)

func (DirectoryFlag) String

func (self DirectoryFlag) String() string

type DirectoryString

type DirectoryString struct {
	Value string
}

Custom type which is registered in the flags library which cli uses for argument parsing. This allows us to expand Value to an absolute path when the argument is parsed

func (*DirectoryString) Set

func (self *DirectoryString) Set(value string) error

func (*DirectoryString) String

func (self *DirectoryString) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL