aboutsummaryrefslogtreecommitdiffstats
path: root/ethereum
diff options
context:
space:
mode:
Diffstat (limited to 'ethereum')
-rw-r--r--ethereum/javascript_runtime.go15
-rw-r--r--ethereum/repl_darwin.go28
2 files changed, 41 insertions, 2 deletions
diff --git a/ethereum/javascript_runtime.go b/ethereum/javascript_runtime.go
index fa01c7005..93297f604 100644
--- a/ethereum/javascript_runtime.go
+++ b/ethereum/javascript_runtime.go
@@ -6,6 +6,7 @@ import (
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethutil"
+ "github.com/ethereum/go-ethereum/utils"
"github.com/obscuren/otto"
"io/ioutil"
"os"
@@ -116,14 +117,26 @@ func (self *JSRE) initStdFuncs() {
eth.Set("watch", self.watch)
eth.Set("addPeer", self.addPeer)
eth.Set("require", self.require)
+ eth.Set("stopMining", self.stopMining)
+ eth.Set("startMining", self.startMining)
}
/*
* The following methods are natively implemented javascript functions
*/
+func (self *JSRE) stopMining(call otto.FunctionCall) otto.Value {
+ v, _ := self.vm.ToValue(utils.StopMining(self.ethereum))
+ return v
+}
+
+func (self *JSRE) startMining(call otto.FunctionCall) otto.Value {
+ v, _ := self.vm.ToValue(utils.StartMining(self.ethereum))
+ return v
+}
+
// eth.watch
-func (self JSRE) watch(call otto.FunctionCall) otto.Value {
+func (self *JSRE) watch(call otto.FunctionCall) otto.Value {
addr, _ := call.Argument(0).ToString()
var storageAddr string
var cb otto.Value
diff --git a/ethereum/repl_darwin.go b/ethereum/repl_darwin.go
index 1b98c2150..fa36b0d52 100644
--- a/ethereum/repl_darwin.go
+++ b/ethereum/repl_darwin.go
@@ -1,17 +1,42 @@
package main
+// #cgo darwin CFLAGS: -I/usr/local/opt/readline/include
+// #cgo darwin LDFLAGS: -L/usr/local/opt/readline/lib
// #cgo LDFLAGS: -lreadline
// #include <stdio.h>
// #include <stdlib.h>
// #include <readline/readline.h>
// #include <readline/history.h>
import "C"
-
import (
+ "os"
+ "os/signal"
"strings"
+ "syscall"
"unsafe"
)
+func initReadLine() {
+ C.rl_catch_sigwinch = 0
+ C.rl_catch_signals = 0
+ c := make(chan os.Signal, 1)
+ signal.Notify(c, syscall.SIGWINCH)
+ signal.Notify(c, os.Interrupt)
+ go func() {
+ for sig := range c {
+ switch sig {
+ case syscall.SIGWINCH:
+ C.rl_resize_terminal()
+
+ case os.Interrupt:
+ C.rl_cleanup_after_signal()
+ default:
+
+ }
+ }
+ }()
+}
+
func readLine(prompt *string) *string {
var p *C.char
@@ -59,6 +84,7 @@ func (self *JSRepl) setIndent() {
}
func (self *JSRepl) read() {
+ initReadLine()
L:
for {
switch result := readLine(&self.prompt); true {