aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/utils
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-10 18:04:11 +0800
committerobscuren <geffobscura@gmail.com>2015-03-10 18:04:11 +0800
commit05c9351659e0482aeb29f80903286aefc671f0c5 (patch)
tree56132f55a3f826ce852c5d053c7e8984932e7878 /cmd/utils
parent0db4a0e898d09ffa7b6b1289e9a334edc0001cfa (diff)
parent80985f97da8174576ee227909035a364af2fd6c9 (diff)
downloadgo-tangerine-05c9351659e0482aeb29f80903286aefc671f0c5.tar
go-tangerine-05c9351659e0482aeb29f80903286aefc671f0c5.tar.gz
go-tangerine-05c9351659e0482aeb29f80903286aefc671f0c5.tar.bz2
go-tangerine-05c9351659e0482aeb29f80903286aefc671f0c5.tar.lz
go-tangerine-05c9351659e0482aeb29f80903286aefc671f0c5.tar.xz
go-tangerine-05c9351659e0482aeb29f80903286aefc671f0c5.tar.zst
go-tangerine-05c9351659e0482aeb29f80903286aefc671f0c5.zip
Merge branch 'accounts-integration' of https://github.com/fjl/go-ethereum into fjl-accounts-integration
Diffstat (limited to 'cmd/utils')
-rw-r--r--cmd/utils/cmd.go52
-rw-r--r--cmd/utils/flags.go78
2 files changed, 51 insertions, 79 deletions
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index a77c6ad4d..a802a08da 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -29,14 +29,11 @@ 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/state"
- "github.com/ethereum/go-ethereum/xeth"
)
var clilogger = logger.NewLogger("CLI")
@@ -98,14 +95,6 @@ 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 {
@@ -134,47 +123,6 @@ func StartEthereum(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)
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 88ff3558d..cde5fa024 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -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,21 @@ 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"
)
+// 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.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.
@@ -36,16 +54,6 @@ var (
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",
@@ -151,23 +159,21 @@ func GetNodeKey(ctx *cli.Context) (key *ecdsa.PrivateKey) {
func GetEthereum(clientID, version string, ctx *cli.Context) *eth.Ethereum {
ethereum, err := eth.New(&eth.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),
+ 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)
@@ -188,3 +194,21 @@ func GetChain(ctx *cli.Context) (*core.ChainManager, ethutil.Database, ethutil.D
}
return core.NewChainManager(blockDb, stateDb, new(event.TypeMux)), blockDb, stateDb
}
+
+func GetAccountManager(ctx *cli.Context) *accounts.Manager {
+ dataDir := ctx.GlobalString(DataDirFlag.Name)
+ ks := crypto.NewKeyStorePassphrase(path.Join(dataDir, "keys"))
+ return accounts.NewManager(ks)
+}
+
+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))
+}