added batch support to console and attach actions

This commit is contained in:
Bas van Kervel 2015-06-19 14:04:18 +02:00 committed by Bas van Kervel
parent 3ff272b618
commit f87501b1c5
6 changed files with 62 additions and 30 deletions

View File

@ -220,6 +220,25 @@ func (self *jsre) loadAutoCompletion() {
} }
} }
func (self *jsre) batch(statement string) {
val, err := self.re.Run(statement)
if err != nil {
fmt.Printf("error: %v", err)
} else if val.IsDefined() && val.IsObject() {
obj, _ := self.re.Get("ret_result")
fmt.Printf("%v", obj)
} else if val.IsDefined() {
fmt.Printf("%v", val)
}
if self.atexit != nil {
self.atexit()
}
self.re.Stop(false)
}
// show summary of current geth instance // show summary of current geth instance
func (self *jsre) welcome() { func (self *jsre) welcome() {
self.re.Eval(`console.log('instance: ' + web3.version.client);`) self.re.Eval(`console.log('instance: ' + web3.version.client);`)

View File

@ -255,6 +255,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
utils.IPCDisabledFlag, utils.IPCDisabledFlag,
utils.IPCApiFlag, utils.IPCApiFlag,
utils.IPCPathFlag, utils.IPCPathFlag,
utils.ExecFlag,
utils.WhisperEnabledFlag, utils.WhisperEnabledFlag,
utils.VMDebugFlag, utils.VMDebugFlag,
utils.ProtocolVersionFlag, utils.ProtocolVersionFlag,
@ -337,8 +338,12 @@ func attach(ctx *cli.Context) {
true, true,
nil) nil)
if ctx.GlobalString(utils.ExecFlag.Name) != "" {
repl.batch(ctx.GlobalString(utils.ExecFlag.Name))
} else {
repl.welcome() repl.welcome()
repl.interactive() repl.interactive()
}
} }
func console(ctx *cli.Context) { func console(ctx *cli.Context) {
@ -368,8 +373,12 @@ func console(ctx *cli.Context) {
nil, nil,
) )
if ctx.GlobalString(utils.ExecFlag.Name) != "" {
repl.batch(ctx.GlobalString(utils.ExecFlag.Name))
} else {
repl.welcome() repl.welcome()
repl.interactive() repl.interactive()
}
ethereum.Stop() ethereum.Stop()
ethereum.WaitForShutdown() ethereum.WaitForShutdown()

View File

@ -227,6 +227,10 @@ var (
Usage: "Filename for IPC socket/pipe", Usage: "Filename for IPC socket/pipe",
Value: DirectoryString{common.DefaultIpcPath()}, Value: DirectoryString{common.DefaultIpcPath()},
} }
ExecFlag = cli.StringFlag{
Name: "exec",
Usage: "Execute javascript statement (only in combination with console/attach)",
}
// Network Settings // Network Settings
MaxPeersFlag = cli.IntFlag{ MaxPeersFlag = cli.IntFlag{
Name: "maxpeers", Name: "maxpeers",

View File

@ -3,12 +3,13 @@ package api
import ( import (
"testing" "testing"
"github.com/ethereum/go-ethereum/rpc/codec"
"encoding/json" "encoding/json"
"strconv" "strconv"
"github.com/ethereum/go-ethereum/common/compiler" "github.com/ethereum/go-ethereum/common/compiler"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/xeth" "github.com/ethereum/go-ethereum/xeth"
) )

View File

@ -250,7 +250,6 @@ func (self *ethApi) Sign(req *shared.Request) (interface{}, error) {
return v, nil return v, nil
} }
func (self *ethApi) PushTx(req *shared.Request) (interface{}, error) { func (self *ethApi) PushTx(req *shared.Request) (interface{}, error) {
args := new(NewDataArgs) args := new(NewDataArgs)
if err := self.codec.Decode(req.Params, &args); err != nil { if err := self.codec.Decode(req.Params, &args); err != nil {