merge upstream
This commit is contained in:
@@ -144,7 +144,7 @@ func (self *JSRE) initStdFuncs() {
|
||||
eth.Set("require", self.require)
|
||||
eth.Set("stopMining", self.stopMining)
|
||||
eth.Set("startMining", self.startMining)
|
||||
eth.Set("blockDo", self.execBlock)
|
||||
eth.Set("execBlock", self.execBlock)
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -221,7 +221,7 @@ func (self *JSRE) execBlock(call otto.FunctionCall) otto.Value {
|
||||
return otto.UndefinedValue()
|
||||
}
|
||||
|
||||
err = self.ethereum.BlockDo(ethutil.FromHex(hash))
|
||||
err = utils.BlockDo(self.ethereum, ethutil.FromHex(hash))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return otto.FalseValue()
|
||||
|
@@ -1,10 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/ethereum/eth-go"
|
||||
"github.com/ethereum/eth-go/ethpub"
|
||||
"github.com/ethereum/eth-go/ethutil"
|
||||
"github.com/obscuren/otto"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
type Repl interface {
|
||||
@@ -16,20 +21,40 @@ type JSRepl struct {
|
||||
re *JSRE
|
||||
|
||||
prompt string
|
||||
|
||||
history *os.File
|
||||
}
|
||||
|
||||
func NewJSRepl(ethereum *eth.Ethereum) *JSRepl {
|
||||
return &JSRepl{re: NewJSRE(ethereum), prompt: "> "}
|
||||
hist, err := os.OpenFile(path.Join(ethutil.Config.ExecPath, "history"), os.O_RDWR|os.O_CREATE, os.ModePerm)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &JSRepl{re: NewJSRE(ethereum), prompt: "> ", history: hist}
|
||||
}
|
||||
|
||||
func (self *JSRepl) Start() {
|
||||
logger.Infoln("init JS Console")
|
||||
reader := bufio.NewReader(self.history)
|
||||
for {
|
||||
line, err := reader.ReadString('\n')
|
||||
if err != nil && err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
fmt.Println("error reading history", err)
|
||||
break
|
||||
}
|
||||
|
||||
addHistory(line[:len(line)-1])
|
||||
}
|
||||
self.read()
|
||||
}
|
||||
|
||||
func (self *JSRepl) Stop() {
|
||||
self.re.Stop()
|
||||
logger.Infoln("exit JS Console")
|
||||
self.history.Close()
|
||||
}
|
||||
|
||||
func (self *JSRepl) parseInput(code string) {
|
||||
|
@@ -102,7 +102,9 @@ L:
|
||||
break L
|
||||
}
|
||||
|
||||
addHistory(str[:len(str)-1]) //allow user to recall this line
|
||||
hist := str[:len(str)-1]
|
||||
addHistory(hist) //allow user to recall this line
|
||||
self.history.WriteString(str)
|
||||
|
||||
self.parseInput(str)
|
||||
|
||||
|
Reference in New Issue
Block a user