aboutsummaryrefslogtreecommitdiffstats
path: root/ethereum
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-07-16 02:34:25 +0800
committerobscuren <geffobscura@gmail.com>2014-07-16 02:34:25 +0800
commit28948d061cfc14d7a5da307a12ebd504b78d2dbb (patch)
tree168772cef16e9fb7eea6727d4ae254097d277ce1 /ethereum
parent288f1c5387c1a0a8863499389e8a7ca7e3068208 (diff)
downloadgo-tangerine-28948d061cfc14d7a5da307a12ebd504b78d2dbb.tar
go-tangerine-28948d061cfc14d7a5da307a12ebd504b78d2dbb.tar.gz
go-tangerine-28948d061cfc14d7a5da307a12ebd504b78d2dbb.tar.bz2
go-tangerine-28948d061cfc14d7a5da307a12ebd504b78d2dbb.tar.lz
go-tangerine-28948d061cfc14d7a5da307a12ebd504b78d2dbb.tar.xz
go-tangerine-28948d061cfc14d7a5da307a12ebd504b78d2dbb.tar.zst
go-tangerine-28948d061cfc14d7a5da307a12ebd504b78d2dbb.zip
Moved the repl to a new package
Diffstat (limited to 'ethereum')
-rw-r--r--ethereum/cmd.go5
-rw-r--r--ethereum/flags.go2
-rw-r--r--ethereum/main.go1
-rw-r--r--ethereum/repl/javascript_runtime.go (renamed from ethereum/javascript_runtime.go)2
-rw-r--r--ethereum/repl/js_lib.go (renamed from ethereum/js_lib.go)2
-rw-r--r--ethereum/repl/repl.go83
-rw-r--r--ethereum/repl/repl_darwin.go (renamed from ethereum/repl_darwin.go)2
l---------ethereum/repl/repl_linux.go (renamed from ethereum/repl_linux.go)0
-rw-r--r--ethereum/repl/repl_windows.go (renamed from ethereum/repl_windows.go)2
-rw-r--r--ethereum/repl/types.go (renamed from ethereum/repl.go)82
10 files changed, 105 insertions, 76 deletions
diff --git a/ethereum/cmd.go b/ethereum/cmd.go
index 08147824d..ff2b8409c 100644
--- a/ethereum/cmd.go
+++ b/ethereum/cmd.go
@@ -2,13 +2,14 @@ package main
import (
"github.com/ethereum/eth-go"
+ "github.com/ethereum/go-ethereum/ethereum/repl"
"github.com/ethereum/go-ethereum/utils"
"io/ioutil"
"os"
)
func InitJsConsole(ethereum *eth.Ethereum) {
- repl := NewJSRepl(ethereum)
+ repl := ethrepl.NewJSRepl(ethereum)
go repl.Start()
utils.RegisterInterrupt(func(os.Signal) {
repl.Stop()
@@ -24,7 +25,7 @@ func ExecJsFile(ethereum *eth.Ethereum, InputFile string) {
if err != nil {
logger.Fatalln(err)
}
- re := NewJSRE(ethereum)
+ re := ethrepl.NewJSRE(ethereum)
utils.RegisterInterrupt(func(os.Signal) {
re.Stop()
})
diff --git a/ethereum/flags.go b/ethereum/flags.go
index af0fd9a69..4f59ddf06 100644
--- a/ethereum/flags.go
+++ b/ethereum/flags.go
@@ -12,6 +12,7 @@ import (
var Identifier string
var KeyRing string
var DiffTool bool
+var DiffType string
var KeyStore string
var StartRpc bool
var RpcPort int
@@ -68,6 +69,7 @@ func Init() {
flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
flag.IntVar(&LogLevel, "loglevel", int(ethlog.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)")
flag.BoolVar(&DiffTool, "difftool", false, "creates output for diff'ing. Sets LogLevel=0")
+ flag.StringVar(&DiffType, "diff", "all", "sets the level of diff output [vm, all]. Has no effect if difftool=false")
flag.BoolVar(&StartMining, "mine", false, "start dagger mining")
flag.BoolVar(&StartJsConsole, "js", false, "launches javascript console")
diff --git a/ethereum/main.go b/ethereum/main.go
index 39226c1d2..fd4a89aa9 100644
--- a/ethereum/main.go
+++ b/ethereum/main.go
@@ -29,6 +29,7 @@ func main() {
utils.InitConfig(ConfigFile, Datadir, "ETH")
ethutil.Config.Diff = DiffTool
+ ethutil.Config.DiffType = DiffType
utils.InitDataDir(Datadir)
diff --git a/ethereum/javascript_runtime.go b/ethereum/repl/javascript_runtime.go
index 852a50487..cd87f9868 100644
--- a/ethereum/javascript_runtime.go
+++ b/ethereum/repl/javascript_runtime.go
@@ -1,4 +1,4 @@
-package main
+package ethrepl
import (
"fmt"
diff --git a/ethereum/js_lib.go b/ethereum/repl/js_lib.go
index 189dcc3a0..c781c43d0 100644
--- a/ethereum/js_lib.go
+++ b/ethereum/repl/js_lib.go
@@ -1,4 +1,4 @@
-package main
+package ethrepl
const jsLib = `
function pp(object) {
diff --git a/ethereum/repl/repl.go b/ethereum/repl/repl.go
new file mode 100644
index 000000000..92d4ad86a
--- /dev/null
+++ b/ethereum/repl/repl.go
@@ -0,0 +1,83 @@
+package ethrepl
+
+import (
+ "bufio"
+ "fmt"
+ "github.com/ethereum/eth-go"
+ "github.com/ethereum/eth-go/ethlog"
+ "github.com/ethereum/eth-go/ethutil"
+ "io"
+ "os"
+ "path"
+)
+
+var logger = ethlog.NewLogger("REPL")
+
+type Repl interface {
+ Start()
+ Stop()
+}
+
+type JSRepl struct {
+ re *JSRE
+
+ prompt string
+
+ history *os.File
+
+ running bool
+}
+
+func NewJSRepl(ethereum *eth.Ethereum) *JSRepl {
+ 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() {
+ if !self.running {
+ self.running = true
+ 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() {
+ if self.running {
+ self.running = false
+ self.re.Stop()
+ logger.Infoln("exit JS Console")
+ self.history.Close()
+ }
+}
+
+func (self *JSRepl) parseInput(code string) {
+ defer func() {
+ if r := recover(); r != nil {
+ fmt.Println("[native] error", r)
+ }
+ }()
+
+ value, err := self.re.Run(code)
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+
+ self.PrintValue(value)
+}
diff --git a/ethereum/repl_darwin.go b/ethereum/repl/repl_darwin.go
index 62b40059a..3a91b0d44 100644
--- a/ethereum/repl_darwin.go
+++ b/ethereum/repl/repl_darwin.go
@@ -1,4 +1,4 @@
-package main
+package ethrepl
// #cgo darwin CFLAGS: -I/usr/local/opt/readline/include
// #cgo darwin LDFLAGS: -L/usr/local/opt/readline/lib
diff --git a/ethereum/repl_linux.go b/ethereum/repl/repl_linux.go
index 276f135d7..276f135d7 120000
--- a/ethereum/repl_linux.go
+++ b/ethereum/repl/repl_linux.go
diff --git a/ethereum/repl_windows.go b/ethereum/repl/repl_windows.go
index 9d4787772..4106c89bc 100644
--- a/ethereum/repl_windows.go
+++ b/ethereum/repl/repl_windows.go
@@ -1,4 +1,4 @@
-package main
+package ethrepl
import (
"bufio"
diff --git a/ethereum/repl.go b/ethereum/repl/types.go
index 34380a06f..16a18e6e5 100644
--- a/ethereum/repl.go
+++ b/ethereum/repl/types.go
@@ -1,84 +1,26 @@
-package main
+package ethrepl
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 {
- Start()
- Stop()
-}
-
-type JSRepl struct {
- re *JSRE
-
- prompt string
-
- history *os.File
-
- running bool
-}
-
-func NewJSRepl(ethereum *eth.Ethereum) *JSRepl {
- 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() {
- if !self.running {
- self.running = true
- 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() {
- if self.running {
- self.running = false
- self.re.Stop()
- logger.Infoln("exit JS Console")
- self.history.Close()
- }
+type JSStateObject struct {
+ *ethpub.PStateObject
+ eth *JSEthereum
}
-func (self *JSRepl) parseInput(code string) {
- defer func() {
- if r := recover(); r != nil {
- fmt.Println("[native] error", r)
- }
- }()
+func (self *JSStateObject) EachStorage(call otto.FunctionCall) otto.Value {
+ cb := call.Argument(0)
+ self.PStateObject.EachStorage(func(key string, value *ethutil.Value) {
+ value.Decode()
- value, err := self.re.Run(code)
- if err != nil {
- fmt.Println(err)
- return
- }
+ cb.Call(self.eth.toVal(self), self.eth.toVal(key), self.eth.toVal(ethutil.Bytes2Hex(value.Bytes())))
+ })
- self.PrintValue(value)
+ return otto.UndefinedValue()
}
// The JSEthereum object attempts to wrap the PEthereum object and returns
@@ -110,7 +52,7 @@ func (self *JSEthereum) GetKey() otto.Value {
}
func (self *JSEthereum) GetStateObject(addr string) otto.Value {
- return self.toVal(self.PEthereum.GetStateObject(addr))
+ return self.toVal(&JSStateObject{self.PEthereum.GetStateObject(addr), self})
}
func (self *JSEthereum) GetStateKeyVals(addr string) otto.Value {