Merge branch 'develop' into rpcfrontier
Conflicts: rpc/api.go rpc/args.go
This commit is contained in:
@ -29,13 +29,10 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/eth"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
rpchttp "github.com/ethereum/go-ethereum/rpc/http"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
)
|
||||
|
||||
var clilogger = logger.NewLogger("CLI")
|
||||
@ -97,18 +94,10 @@ func initDataDir(Datadir string) {
|
||||
}
|
||||
}
|
||||
|
||||
func InitConfig(vmType int, ConfigFile string, Datadir string, EnvPrefix string) *ethutil.ConfigManager {
|
||||
initDataDir(Datadir)
|
||||
cfg := ethutil.ReadConfig(ConfigFile, Datadir, EnvPrefix)
|
||||
cfg.VmType = vmType
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
func exit(err error) {
|
||||
status := 0
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Fatal: ", err)
|
||||
fmt.Fprintln(os.Stderr, "Fatal:", err)
|
||||
status = 1
|
||||
}
|
||||
logger.Flush()
|
||||
@ -142,47 +131,6 @@ func StartEthereumForTest(ethereum *eth.Ethereum) {
|
||||
})
|
||||
}
|
||||
|
||||
func KeyTasks(keyManager *crypto.KeyManager, KeyRing string, GenAddr bool, SecretFile string, ExportDir string, NonInteractive bool) {
|
||||
var err error
|
||||
switch {
|
||||
case GenAddr:
|
||||
if NonInteractive || confirm("This action overwrites your old private key.") {
|
||||
err = keyManager.Init(KeyRing, 0, true)
|
||||
}
|
||||
exit(err)
|
||||
case len(SecretFile) > 0:
|
||||
SecretFile = ethutil.ExpandHomePath(SecretFile)
|
||||
|
||||
if NonInteractive || confirm("This action overwrites your old private key.") {
|
||||
err = keyManager.InitFromSecretsFile(KeyRing, 0, SecretFile)
|
||||
}
|
||||
exit(err)
|
||||
case len(ExportDir) > 0:
|
||||
err = keyManager.Init(KeyRing, 0, false)
|
||||
if err == nil {
|
||||
err = keyManager.Export(ExportDir)
|
||||
}
|
||||
exit(err)
|
||||
default:
|
||||
// Creates a keypair if none exists
|
||||
err = keyManager.Init(KeyRing, 0, false)
|
||||
if err != nil {
|
||||
exit(err)
|
||||
}
|
||||
}
|
||||
clilogger.Infof("Main address %x\n", keyManager.Address())
|
||||
}
|
||||
|
||||
func StartRpc(ethereum *eth.Ethereum, RpcListenAddress string, RpcPort int) {
|
||||
var err error
|
||||
ethereum.RpcServer, err = rpchttp.NewRpcHttpServer(xeth.New(ethereum, nil), RpcListenAddress, RpcPort)
|
||||
if err != nil {
|
||||
clilogger.Errorf("Could not start RPC interface (port %v): %v", RpcPort, err)
|
||||
} else {
|
||||
go ethereum.RpcServer.Start()
|
||||
}
|
||||
}
|
||||
|
||||
func FormatTransactionData(data string) []byte {
|
||||
d := ethutil.StringToByteFunc(data, func(s string) (ret []byte) {
|
||||
slice := regexp.MustCompile("\\n|\\s").Split(s, 1000000000)
|
||||
|
@ -2,10 +2,15 @@ package utils
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/eth"
|
||||
@ -15,8 +20,48 @@ import (
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/p2p/nat"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cli.AppHelpTemplate = `{{.Name}} {{if .Flags}}[global options] {{end}}command{{if .Flags}} [command options]{{end}} [arguments...]
|
||||
|
||||
VERSION:
|
||||
{{.Version}}
|
||||
|
||||
COMMANDS:
|
||||
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
|
||||
{{end}}{{if .Flags}}
|
||||
GLOBAL OPTIONS:
|
||||
{{range .Flags}}{{.}}
|
||||
{{end}}{{end}}
|
||||
`
|
||||
|
||||
cli.CommandHelpTemplate = `{{.Name}}{{if .Subcommands}} command{{end}}{{if .Flags}} [command options]{{end}} [arguments...]
|
||||
{{if .Description}}{{.Description}}
|
||||
{{end}}{{if .Subcommands}}
|
||||
SUBCOMMANDS:
|
||||
{{range .Subcommands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
|
||||
{{end}}{{end}}{{if .Flags}}
|
||||
OPTIONS:
|
||||
{{range .Flags}}{{.}}
|
||||
{{end}}{{end}}
|
||||
`
|
||||
}
|
||||
|
||||
// NewApp creates an app with sane defaults.
|
||||
func NewApp(version, usage string) *cli.App {
|
||||
app := cli.NewApp()
|
||||
app.Name = path.Base(os.Args[0])
|
||||
app.Author = ""
|
||||
app.Authors = nil
|
||||
app.Email = ""
|
||||
app.Version = version
|
||||
app.Usage = usage
|
||||
return app
|
||||
}
|
||||
|
||||
// These are all the command line flags we support.
|
||||
// If you add to this list, please remember to include the
|
||||
// flag in the appropriate command definition.
|
||||
@ -32,20 +77,14 @@ var (
|
||||
Usage: "Virtual Machine type: 0 is standard VM, 1 is debug VM",
|
||||
}
|
||||
*/
|
||||
UnlockedAccountFlag = cli.StringFlag{
|
||||
Name: "unlock",
|
||||
Usage: "Unlock a given account untill this programs exits (address:password)",
|
||||
}
|
||||
VMDebugFlag = cli.BoolFlag{
|
||||
Name: "vmdebug",
|
||||
Usage: "Virtual Machine debug output",
|
||||
}
|
||||
KeyRingFlag = cli.StringFlag{
|
||||
Name: "keyring",
|
||||
Usage: "Name of keyring to be used",
|
||||
Value: "",
|
||||
}
|
||||
KeyStoreFlag = cli.StringFlag{
|
||||
Name: "keystore",
|
||||
Usage: `Where to store keyrings: "db" or "file"`,
|
||||
Value: "db",
|
||||
}
|
||||
DataDirFlag = cli.StringFlag{
|
||||
Name: "datadir",
|
||||
Usage: "Data directory to be used",
|
||||
@ -149,30 +188,24 @@ func GetNodeKey(ctx *cli.Context) (key *ecdsa.PrivateKey) {
|
||||
return key
|
||||
}
|
||||
|
||||
func GetEthereum(clientID, version string, ctx *cli.Context) *eth.Ethereum {
|
||||
ethereum, err := eth.New(ð.Config{
|
||||
Name: p2p.MakeName(clientID, version),
|
||||
KeyStore: ctx.GlobalString(KeyStoreFlag.Name),
|
||||
DataDir: ctx.GlobalString(DataDirFlag.Name),
|
||||
LogFile: ctx.GlobalString(LogFileFlag.Name),
|
||||
LogLevel: ctx.GlobalInt(LogLevelFlag.Name),
|
||||
LogFormat: ctx.GlobalString(LogFormatFlag.Name),
|
||||
MinerThreads: ctx.GlobalInt(MinerThreadsFlag.Name),
|
||||
VmDebug: ctx.GlobalBool(VMDebugFlag.Name),
|
||||
|
||||
MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
|
||||
Port: ctx.GlobalString(ListenPortFlag.Name),
|
||||
NAT: GetNAT(ctx),
|
||||
NodeKey: GetNodeKey(ctx),
|
||||
KeyRing: ctx.GlobalString(KeyRingFlag.Name),
|
||||
Shh: true,
|
||||
Dial: true,
|
||||
BootNodes: ctx.GlobalString(BootnodesFlag.Name),
|
||||
func GetEthereum(clientID, version string, ctx *cli.Context) (*eth.Ethereum, error) {
|
||||
return eth.New(ð.Config{
|
||||
Name: p2p.MakeName(clientID, version),
|
||||
DataDir: ctx.GlobalString(DataDirFlag.Name),
|
||||
LogFile: ctx.GlobalString(LogFileFlag.Name),
|
||||
LogLevel: ctx.GlobalInt(LogLevelFlag.Name),
|
||||
LogFormat: ctx.GlobalString(LogFormatFlag.Name),
|
||||
MinerThreads: ctx.GlobalInt(MinerThreadsFlag.Name),
|
||||
AccountManager: GetAccountManager(ctx),
|
||||
VmDebug: ctx.GlobalBool(VMDebugFlag.Name),
|
||||
MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
|
||||
Port: ctx.GlobalString(ListenPortFlag.Name),
|
||||
NAT: GetNAT(ctx),
|
||||
NodeKey: GetNodeKey(ctx),
|
||||
Shh: true,
|
||||
Dial: true,
|
||||
BootNodes: ctx.GlobalString(BootnodesFlag.Name),
|
||||
})
|
||||
if err != nil {
|
||||
exit(err)
|
||||
}
|
||||
return ethereum
|
||||
}
|
||||
|
||||
func GetChain(ctx *cli.Context) (*core.ChainManager, ethutil.Database, ethutil.Database) {
|
||||
@ -188,3 +221,27 @@ func GetChain(ctx *cli.Context) (*core.ChainManager, ethutil.Database, ethutil.D
|
||||
}
|
||||
return core.NewChainManager(blockDb, stateDb, new(event.TypeMux)), blockDb, stateDb
|
||||
}
|
||||
|
||||
// Global account manager
|
||||
var km *accounts.Manager
|
||||
|
||||
func GetAccountManager(ctx *cli.Context) *accounts.Manager {
|
||||
dataDir := ctx.GlobalString(DataDirFlag.Name)
|
||||
if km == nil {
|
||||
ks := crypto.NewKeyStorePassphrase(path.Join(dataDir, "keys"))
|
||||
km = accounts.NewManager(ks)
|
||||
}
|
||||
return km
|
||||
}
|
||||
|
||||
func StartRPC(eth *eth.Ethereum, ctx *cli.Context) {
|
||||
addr := ctx.GlobalString(RPCListenAddrFlag.Name)
|
||||
port := ctx.GlobalInt(RPCPortFlag.Name)
|
||||
dataDir := ctx.GlobalString(DataDirFlag.Name)
|
||||
|
||||
l, err := net.Listen("tcp", fmt.Sprintf("%s:%d", addr, port))
|
||||
if err != nil {
|
||||
Fatalf("Can't listen on %s:%d: %v", addr, port, err)
|
||||
}
|
||||
go http.Serve(l, rpc.JSONRPC(xeth.New(eth, nil), dataDir))
|
||||
}
|
||||
|
Reference in New Issue
Block a user