diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-06-23 22:44:03 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-06-23 22:44:03 +0800 |
commit | 6b5532ab0d0e88f27af539840c58cbd6de13de90 (patch) | |
tree | 84f1856e1b3fb2fd927e6ef9c59983e4fb347a8c /cmd/geth/main.go | |
parent | 139439dcdc14e448bfdbd509bb135faa92337a28 (diff) | |
parent | 2b3957f3737b56622e38425a52caea2a836f8b63 (diff) | |
download | go-tangerine-6b5532ab0d0e88f27af539840c58cbd6de13de90.tar go-tangerine-6b5532ab0d0e88f27af539840c58cbd6de13de90.tar.gz go-tangerine-6b5532ab0d0e88f27af539840c58cbd6de13de90.tar.bz2 go-tangerine-6b5532ab0d0e88f27af539840c58cbd6de13de90.tar.lz go-tangerine-6b5532ab0d0e88f27af539840c58cbd6de13de90.tar.xz go-tangerine-6b5532ab0d0e88f27af539840c58cbd6de13de90.tar.zst go-tangerine-6b5532ab0d0e88f27af539840c58cbd6de13de90.zip |
Merge pull request #1279 from bas-vk/rpc-http
Integrate console and remove old rpc package structure
Diffstat (limited to 'cmd/geth/main.go')
-rw-r--r-- | cmd/geth/main.go | 71 |
1 files changed, 66 insertions, 5 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 89aae43e5..02ec63300 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -38,6 +38,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/rpc/codec" + "github.com/ethereum/go-ethereum/rpc/comms" "github.com/mattn/go-colorable" "github.com/mattn/go-isatty" ) @@ -202,6 +204,16 @@ nodes. The Geth console is an interactive shell for the JavaScript runtime environment which exposes a node admin interface as well as the Ðapp JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console +`}, + { + Action: attach, + Name: "attach", + Usage: `Geth Console: interactive JavaScript environment (connect to node)`, + Description: ` +The Geth console is an interactive shell for the JavaScript runtime environment +which exposes a node admin interface as well as the Ðapp JavaScript API. +See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console. +This command allows to open a console on a running geth node. `, }, { @@ -239,9 +251,11 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso utils.RPCEnabledFlag, utils.RPCListenAddrFlag, utils.RPCPortFlag, + utils.RpcApiFlag, utils.IPCDisabledFlag, utils.IPCApiFlag, utils.IPCPathFlag, + utils.ExecFlag, utils.WhisperEnabledFlag, utils.VMDebugFlag, utils.ProtocolVersionFlag, @@ -294,6 +308,44 @@ func run(ctx *cli.Context) { ethereum.WaitForShutdown() } +func attach(ctx *cli.Context) { + // Wrap the standard output with a colorified stream (windows) + if isatty.IsTerminal(os.Stdout.Fd()) { + if pr, pw, err := os.Pipe(); err == nil { + go io.Copy(colorable.NewColorableStdout(), pr) + os.Stdout = pw + } + } + + var client comms.EthereumClient + var err error + if ctx.Args().Present() { + client, err = comms.ClientFromEndpoint(ctx.Args().First(), codec.JSON) + } else { + cfg := comms.IpcConfig{ + Endpoint: ctx.GlobalString(utils.IPCPathFlag.Name), + } + client, err = comms.NewIpcClient(cfg, codec.JSON) + } + + if err != nil { + utils.Fatalf("Unable to attach to geth node - %v", err) + } + + repl := newLightweightJSRE( + ctx.GlobalString(utils.JSpathFlag.Name), + client, + true, + nil) + + if ctx.GlobalString(utils.ExecFlag.Name) != "" { + repl.batch(ctx.GlobalString(utils.ExecFlag.Name)) + } else { + repl.welcome() + repl.interactive() + } +} + func console(ctx *cli.Context) { // Wrap the standard output with a colorified stream (windows) if isatty.IsTerminal(os.Stdout.Fd()) { @@ -309,16 +361,24 @@ func console(ctx *cli.Context) { utils.Fatalf("%v", err) } + client := comms.NewInProcClient(codec.JSON) + startEth(ctx, ethereum) repl := newJSRE( ethereum, - ctx.String(utils.JSpathFlag.Name), + ctx.GlobalString(utils.JSpathFlag.Name), ctx.GlobalString(utils.RPCCORSDomainFlag.Name), - utils.IpcSocketPath(ctx), + client, true, nil, ) - repl.interactive() + + if ctx.GlobalString(utils.ExecFlag.Name) != "" { + repl.batch(ctx.GlobalString(utils.ExecFlag.Name)) + } else { + repl.welcome() + repl.interactive() + } ethereum.Stop() ethereum.WaitForShutdown() @@ -331,12 +391,13 @@ func execJSFiles(ctx *cli.Context) { utils.Fatalf("%v", err) } + client := comms.NewInProcClient(codec.JSON) startEth(ctx, ethereum) repl := newJSRE( ethereum, - ctx.String(utils.JSpathFlag.Name), + ctx.GlobalString(utils.JSpathFlag.Name), ctx.GlobalString(utils.RPCCORSDomainFlag.Name), - utils.IpcSocketPath(ctx), + client, false, nil, ) |