Added js interpret mode
This commit is contained in:
parent
017bbbb582
commit
92eaa98e83
@ -21,6 +21,7 @@ var LogFile string
|
|||||||
var DataDir string
|
var DataDir string
|
||||||
var NonInteractive bool
|
var NonInteractive bool
|
||||||
var StartJsConsole bool
|
var StartJsConsole bool
|
||||||
|
var InputFile string
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
flag.BoolVar(&StartConsole, "c", false, "debug and testing console")
|
flag.BoolVar(&StartConsole, "c", false, "debug and testing console")
|
||||||
@ -40,6 +41,7 @@ func Init() {
|
|||||||
flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)")
|
flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)")
|
||||||
flag.IntVar(&MaxPeer, "x", 5, "maximum desired peers")
|
flag.IntVar(&MaxPeer, "x", 5, "maximum desired peers")
|
||||||
flag.BoolVar(&StartJsConsole, "js", false, "exp")
|
flag.BoolVar(&StartJsConsole, "js", false, "exp")
|
||||||
|
flag.StringVar(&InputFile, "e", "", "Run javascript file")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/ethereum/eth-go/ethchain"
|
"github.com/ethereum/eth-go/ethchain"
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/utils"
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@ -51,7 +52,7 @@ func main() {
|
|||||||
var logSys *log.Logger
|
var logSys *log.Logger
|
||||||
flags := log.LstdFlags
|
flags := log.LstdFlags
|
||||||
|
|
||||||
if StartJsConsole {
|
if StartJsConsole || len(InputFile) > 0 {
|
||||||
ethutil.ReadConfig(DataDir, ethutil.LogFile)
|
ethutil.ReadConfig(DataDir, ethutil.LogFile)
|
||||||
} else {
|
} else {
|
||||||
ethutil.ReadConfig(DataDir, ethutil.LogFile|ethutil.LogStd)
|
ethutil.ReadConfig(DataDir, ethutil.LogFile|ethutil.LogStd)
|
||||||
@ -157,6 +158,22 @@ save these words so you can restore your account later: %s
|
|||||||
RegisterInterrupt(func(os.Signal) {
|
RegisterInterrupt(func(os.Signal) {
|
||||||
repl.Stop()
|
repl.Stop()
|
||||||
})
|
})
|
||||||
|
} else if len(InputFile) > 0 {
|
||||||
|
file, err := os.Open(InputFile)
|
||||||
|
if err != nil {
|
||||||
|
ethutil.Config.Log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err := ioutil.ReadAll(file)
|
||||||
|
if err != nil {
|
||||||
|
ethutil.Config.Log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
re := NewJSRE(ethereum)
|
||||||
|
RegisterInterrupt(func(os.Signal) {
|
||||||
|
re.Stop()
|
||||||
|
})
|
||||||
|
re.Run(string(content))
|
||||||
}
|
}
|
||||||
|
|
||||||
if StartRpc {
|
if StartRpc {
|
||||||
|
@ -31,6 +31,8 @@ function pp(object) {
|
|||||||
str += "\033[1m\033[30m" + object;
|
str += "\033[1m\033[30m" + object;
|
||||||
} else if(typeof(object) === "number") {
|
} else if(typeof(object) === "number") {
|
||||||
str += "\033[31m" + object;
|
str += "\033[31m" + object;
|
||||||
|
} else if(typeof(object) === "function") {
|
||||||
|
str += "\033[35m[Function]";
|
||||||
} else {
|
} else {
|
||||||
str += object;
|
str += object;
|
||||||
}
|
}
|
||||||
@ -40,7 +42,12 @@ function pp(object) {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
function prettyPrint(object) {
|
function prettyPrint(/* */) {
|
||||||
console.log(pp(object))
|
var args = arguments;
|
||||||
|
for(var i = 0, l = args.length; i < l; i++) {
|
||||||
|
console.log(pp(args[i]))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var print = prettyPrint;
|
||||||
`
|
`
|
||||||
|
Loading…
Reference in New Issue
Block a user