From df47de9aea67cad60afa336171e05c4242ec4b9a Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 22 Jun 2016 12:17:51 +0300 Subject: [PATCH] jail --- build/env.sh | 12 ++++++------ src/jail.go | 35 +++++++++++++++++++++++++++++++++++ src/library.go | 17 +++++++++++++++++ 3 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 src/jail.go diff --git a/build/env.sh b/build/env.sh index a9a0fbc88..edf64680e 100755 --- a/build/env.sh +++ b/build/env.sh @@ -10,11 +10,11 @@ fi # Create fake Go workspace if it doesn't exist yet. workspace="$PWD/build/_workspace" root="$PWD" -ethdir="$workspace/src/github.com/ethereum" -if [ ! -L "$ethdir/go-ethereum" ]; then +ethdir="$workspace/src/github.com/status-im" +if [ ! -L "$ethdir/status-go" ]; then mkdir -p "$ethdir" cd "$ethdir" - ln -s ../../../../../. go-ethereum + ln -s ../../../../../. status-go cd "$root" fi @@ -25,8 +25,8 @@ GOBIN="$PWD/build/bin" export GOPATH GOBIN # Run the command inside the workspace. -cd "$ethdir/go-ethereum" -PWD="$ethdir/go-ethereum" +cd "$ethdir/status-go" +PWD="$ethdir/status-go" # Launch the arguments with the configured environment. -exec "$@" \ No newline at end of file +exec "$@" diff --git a/src/jail.go b/src/jail.go new file mode 100644 index 000000000..80b1faf29 --- /dev/null +++ b/src/jail.go @@ -0,0 +1,35 @@ +package main + +import ( + "github.com/robertkrimen/otto" +) + +var statusJs string +var vms = make(map[string]*otto.Otto) + +func Init(js string) { + statusJs = js +} + +func Parse(chatId string, js string) string { + vm := otto.New() + jjs := statusJs + js + ` + var catalog = JSON.stringify(_status_catalog); + ` + vms[chatId] = vm + vm.Run(jjs) + res, _ := vm.Get("catalog") + + return res.String() +} + +func Call(chatId string, path string, args string) string { + vm, ok := vms[chatId] + if !ok { + return "" + } + + res, _ := vm.Call("call", nil, path, args) + + return res.String() +} diff --git a/src/library.go b/src/library.go index 5e348289c..b50ee292d 100644 --- a/src/library.go +++ b/src/library.go @@ -39,3 +39,20 @@ func doStartNode(datadir *C.char) C.int { } return 0 } + +//export parse +func parse(chatId *C.char, js *C.char) *C.char { + res := Parse(C.GoString(chatId), C.GoString(js)) + return C.CString(res) +} + +//export call +func call(chatId *C.char, path *C.char, params *C.char) *C.char { + res := Call(C.GoString(chatId), C.GoString(path), C.GoString(params)) + return C.CString(res) +} + +//export initJail +func initJail(js *C.char) { + Init(C.GoString(js)) +}