mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
add IPC commandline options
This commit is contained in:
parent
0eca879627
commit
8c736d1319
7 changed files with 93 additions and 24 deletions
|
|
@ -67,14 +67,14 @@ type jsre struct {
|
||||||
prompter
|
prompter
|
||||||
}
|
}
|
||||||
|
|
||||||
func newJSRE(datadir, libPath string) *jsre {
|
func newJSRE(datadir, libPath, ipcpath string) *jsre {
|
||||||
js := &jsre{ps1: "> "}
|
js := &jsre{ps1: "> "}
|
||||||
js.wait = make(chan *big.Int)
|
js.wait = make(chan *big.Int)
|
||||||
|
|
||||||
// update state in separare forever blocks
|
// update state in separare forever blocks
|
||||||
js.re = re.New(libPath)
|
js.re = re.New(libPath)
|
||||||
js.apiBindings()
|
js.apiBindings(ipcpath)
|
||||||
// js.adminBindings()
|
// TODO js.adminBindings()
|
||||||
|
|
||||||
if !liner.TerminalSupported() {
|
if !liner.TerminalSupported() {
|
||||||
js.prompter = dumbterm{bufio.NewReader(os.Stdin)}
|
js.prompter = dumbterm{bufio.NewReader(os.Stdin)}
|
||||||
|
|
@ -92,9 +92,9 @@ func newJSRE(datadir, libPath string) *jsre {
|
||||||
return js
|
return js
|
||||||
}
|
}
|
||||||
|
|
||||||
func (js *jsre) apiBindings() {
|
func (js *jsre) apiBindings(ipcpath string) {
|
||||||
ethApi := rpc.NewEthereumApi(nil)
|
ethApi := rpc.NewEthereumApi(nil)
|
||||||
jeth := rpc.NewJeth(ethApi, js.re)
|
jeth := rpc.NewJeth(ethApi, js.re, ipcpath)
|
||||||
|
|
||||||
js.re.Set("jeth", struct{}{})
|
js.re.Set("jeth", struct{}{})
|
||||||
t, _ := js.re.Get("jeth")
|
t, _ := js.re.Get("jeth")
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/mattn/go-colorable"
|
"github.com/mattn/go-colorable"
|
||||||
"github.com/mattn/go-isatty"
|
"github.com/mattn/go-isatty"
|
||||||
|
"github.com/codegangsta/cli"
|
||||||
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -33,6 +37,34 @@ const (
|
||||||
Version = "0.9.26"
|
Version = "0.9.26"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
gitCommit string // set via linker flag
|
||||||
|
nodeNameVersion string
|
||||||
|
app = utils.NewApp(Version, "the ether console")
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if gitCommit == "" {
|
||||||
|
nodeNameVersion = Version
|
||||||
|
} else {
|
||||||
|
nodeNameVersion = Version + "-" + gitCommit[:8]
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Action = run
|
||||||
|
app.Flags = []cli.Flag{
|
||||||
|
utils.DataDirFlag,
|
||||||
|
utils.IPCDisabledFlag,
|
||||||
|
utils.IPCPathFlag,
|
||||||
|
utils.VerbosityFlag,
|
||||||
|
utils.JSpathFlag,
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Before = func(ctx *cli.Context) error {
|
||||||
|
utils.SetupLogger(ctx)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Wrap the standard output with a colorified stream (windows)
|
// Wrap the standard output with a colorified stream (windows)
|
||||||
if isatty.IsTerminal(os.Stdout.Fd()) {
|
if isatty.IsTerminal(os.Stdout.Fd()) {
|
||||||
|
|
@ -42,7 +74,32 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO, datadir + jspath
|
var interrupted = false
|
||||||
repl := newJSRE("/home/bas/.ethereum", ".")
|
utils.RegisterInterrupt(func(os.Signal) {
|
||||||
|
interrupted = true
|
||||||
|
})
|
||||||
|
utils.HandleInterrupt()
|
||||||
|
|
||||||
|
if err := app.Run(os.Args); err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, "Error: ", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// we need to run the interrupt callbacks in case gui is closed
|
||||||
|
// this skips if we got here by actual interrupt stopping the GUI
|
||||||
|
if !interrupted {
|
||||||
|
utils.RunInterruptCallbacks(os.Interrupt)
|
||||||
|
}
|
||||||
|
logger.Flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
func run(ctx *cli.Context) {
|
||||||
|
//start := time.Now()
|
||||||
|
|
||||||
|
datadir := ctx.GlobalString(utils.DataDirFlag.Name)
|
||||||
|
jspath := ctx.GlobalString(utils.JSpathFlag.Name)
|
||||||
|
ipcpath := ctx.GlobalString(utils.IPCPathFlag.Name)
|
||||||
|
|
||||||
|
repl := newJSRE(datadir, jspath, ipcpath)
|
||||||
|
|
||||||
repl.interactive()
|
repl.interactive()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ type jsre struct {
|
||||||
prompter
|
prompter
|
||||||
}
|
}
|
||||||
|
|
||||||
func newJSRE(ethereum *eth.Ethereum, libPath, corsDomain string, interactive bool, f xeth.Frontend) *jsre {
|
func newJSRE(ethereum *eth.Ethereum, libPath, ipcpath, corsDomain string, interactive bool, f xeth.Frontend) *jsre {
|
||||||
js := &jsre{ethereum: ethereum, ps1: "> "}
|
js := &jsre{ethereum: ethereum, ps1: "> "}
|
||||||
// set default cors domain used by startRpc from CLI flag
|
// set default cors domain used by startRpc from CLI flag
|
||||||
js.corsDomain = corsDomain
|
js.corsDomain = corsDomain
|
||||||
|
|
@ -84,7 +84,7 @@ func newJSRE(ethereum *eth.Ethereum, libPath, corsDomain string, interactive boo
|
||||||
js.wait = js.xeth.UpdateState()
|
js.wait = js.xeth.UpdateState()
|
||||||
// update state in separare forever blocks
|
// update state in separare forever blocks
|
||||||
js.re = re.New(libPath)
|
js.re = re.New(libPath)
|
||||||
js.apiBindings(f)
|
js.apiBindings(f, ipcpath)
|
||||||
js.adminBindings()
|
js.adminBindings()
|
||||||
|
|
||||||
if !liner.TerminalSupported() || !interactive {
|
if !liner.TerminalSupported() || !interactive {
|
||||||
|
|
@ -103,10 +103,10 @@ func newJSRE(ethereum *eth.Ethereum, libPath, corsDomain string, interactive boo
|
||||||
return js
|
return js
|
||||||
}
|
}
|
||||||
|
|
||||||
func (js *jsre) apiBindings(f xeth.Frontend) {
|
func (js *jsre) apiBindings(f xeth.Frontend, ipcpath string) {
|
||||||
xe := xeth.New(js.ethereum, f)
|
xe := xeth.New(js.ethereum, f)
|
||||||
ethApi := rpc.NewEthereumApi(xe)
|
ethApi := rpc.NewEthereumApi(xe)
|
||||||
jeth := rpc.NewJeth(ethApi, js.re)
|
jeth := rpc.NewJeth(ethApi, js.re, ipcpath)
|
||||||
|
|
||||||
js.re.Set("jeth", struct{}{})
|
js.re.Set("jeth", struct{}{})
|
||||||
t, _ := js.re.Get("jeth")
|
t, _ := js.re.Get("jeth")
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,8 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
|
||||||
utils.RPCEnabledFlag,
|
utils.RPCEnabledFlag,
|
||||||
utils.RPCListenAddrFlag,
|
utils.RPCListenAddrFlag,
|
||||||
utils.RPCPortFlag,
|
utils.RPCPortFlag,
|
||||||
utils.IPCEnabledFlag,
|
utils.IPCDisabledFlag,
|
||||||
|
utils.IPCPathFlag,
|
||||||
utils.WhisperEnabledFlag,
|
utils.WhisperEnabledFlag,
|
||||||
utils.VMDebugFlag,
|
utils.VMDebugFlag,
|
||||||
utils.ProtocolVersionFlag,
|
utils.ProtocolVersionFlag,
|
||||||
|
|
@ -304,6 +305,7 @@ func console(ctx *cli.Context) {
|
||||||
repl := newJSRE(
|
repl := newJSRE(
|
||||||
ethereum,
|
ethereum,
|
||||||
ctx.String(utils.JSpathFlag.Name),
|
ctx.String(utils.JSpathFlag.Name),
|
||||||
|
ctx.String(utils.IPCPathFlag.Name),
|
||||||
ctx.GlobalString(utils.RPCCORSDomainFlag.Name),
|
ctx.GlobalString(utils.RPCCORSDomainFlag.Name),
|
||||||
true,
|
true,
|
||||||
nil,
|
nil,
|
||||||
|
|
@ -325,6 +327,7 @@ func execJSFiles(ctx *cli.Context) {
|
||||||
repl := newJSRE(
|
repl := newJSRE(
|
||||||
ethereum,
|
ethereum,
|
||||||
ctx.String(utils.JSpathFlag.Name),
|
ctx.String(utils.JSpathFlag.Name),
|
||||||
|
ctx.String(utils.IPCPathFlag.Name),
|
||||||
ctx.GlobalString(utils.RPCCORSDomainFlag.Name),
|
ctx.GlobalString(utils.RPCCORSDomainFlag.Name),
|
||||||
false,
|
false,
|
||||||
nil,
|
nil,
|
||||||
|
|
@ -387,7 +390,7 @@ func startEth(ctx *cli.Context, eth *eth.Ethereum) {
|
||||||
utils.Fatalf("Error starting RPC: %v", err)
|
utils.Fatalf("Error starting RPC: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ctx.GlobalBool(utils.IPCEnabledFlag.Name) {
|
if !ctx.GlobalBool(utils.IPCDisabledFlag.Name) {
|
||||||
if err := utils.StartIPC(eth, ctx); err != nil {
|
if err := utils.StartIPC(eth, ctx); err != nil {
|
||||||
utils.Fatalf("Error starting IPC: %v", err)
|
utils.Fatalf("Error starting IPC: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -204,9 +204,14 @@ var (
|
||||||
Usage: "Domain on which to send Access-Control-Allow-Origin header",
|
Usage: "Domain on which to send Access-Control-Allow-Origin header",
|
||||||
Value: "",
|
Value: "",
|
||||||
}
|
}
|
||||||
IPCEnabledFlag = cli.BoolFlag{
|
IPCDisabledFlag = cli.BoolFlag{
|
||||||
Name: "ipc",
|
Name: "ipcdisable",
|
||||||
Usage: "Enable the IPC-RPC server",
|
Usage: "Disable the IPC-RPC server",
|
||||||
|
}
|
||||||
|
IPCPathFlag = cli.StringFlag{
|
||||||
|
Name: "ipcpath",
|
||||||
|
Usage: "Filename for IPC socket/pipe",
|
||||||
|
Value: common.DefaultIpcPath(),
|
||||||
}
|
}
|
||||||
// Network Settings
|
// Network Settings
|
||||||
MaxPeersFlag = cli.IntFlag{
|
MaxPeersFlag = cli.IntFlag{
|
||||||
|
|
@ -378,7 +383,7 @@ func StartRPC(eth *eth.Ethereum, ctx *cli.Context) error {
|
||||||
|
|
||||||
func StartIPC(eth *eth.Ethereum, ctx *cli.Context) error {
|
func StartIPC(eth *eth.Ethereum, ctx *cli.Context) error {
|
||||||
config := comms.IpcConfig{
|
config := comms.IpcConfig{
|
||||||
Endpoint: ctx.GlobalString(DataDirFlag.Name) + "/geth.sock",
|
Endpoint: ctx.GlobalString(IPCPathFlag.Name),
|
||||||
}
|
}
|
||||||
|
|
||||||
xeth := xeth.New(eth, nil)
|
xeth := xeth.New(eth, nil)
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,10 @@ func DefaultDataDir() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DefaultIpcPath() string {
|
||||||
|
return filepath.Join(DefaultDataDir(), "geth.ipc")
|
||||||
|
}
|
||||||
|
|
||||||
func IsWindows() bool {
|
func IsWindows() bool {
|
||||||
return runtime.GOOS == "windows"
|
return runtime.GOOS == "windows"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
rpc/jeth.go
12
rpc/jeth.go
|
|
@ -13,12 +13,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Jeth struct {
|
type Jeth struct {
|
||||||
ethApi *EthereumApi
|
ethApi *EthereumApi
|
||||||
re *jsre.JSRE
|
re *jsre.JSRE
|
||||||
|
ipcpath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewJeth(ethApi *EthereumApi, re *jsre.JSRE) *Jeth {
|
func NewJeth(ethApi *EthereumApi, re *jsre.JSRE, ipcpath string) *Jeth {
|
||||||
return &Jeth{ethApi, re}
|
return &Jeth{ethApi, re, ipcpath}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Jeth) err(call otto.FunctionCall, code int, msg string, id interface{}) (response otto.Value) {
|
func (self *Jeth) err(call otto.FunctionCall, code int, msg string, id interface{}) (response otto.Value) {
|
||||||
|
|
@ -40,8 +41,7 @@ func (self *Jeth) Send(call otto.FunctionCall) (response otto.Value) {
|
||||||
return self.err(call, -32700, err.Error(), nil)
|
return self.err(call, -32700, err.Error(), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
client, err := comms.NewIpcClient(comms.IpcConfig{self.ipcpath}, codec.JSON)
|
||||||
client, err := comms.NewIpcClient(comms.IpcConfig{"/home/bas/.ethereum/geth.sock"}, codec.JSON)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error response:", err)
|
fmt.Println("Error response:", err)
|
||||||
return self.err(call, -32603, err.Error(), -1)
|
return self.err(call, -32603, err.Error(), -1)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue