Merge pull request #13 from status-im/rpc-flags
rpc flags added to the start up context
This commit is contained in:
commit
00ce499215
12
build/env.sh
12
build/env.sh
|
@ -10,11 +10,11 @@ fi
|
||||||
# Create fake Go workspace if it doesn't exist yet.
|
# Create fake Go workspace if it doesn't exist yet.
|
||||||
workspace="$PWD/build/_workspace"
|
workspace="$PWD/build/_workspace"
|
||||||
root="$PWD"
|
root="$PWD"
|
||||||
ethdir="$workspace/src/github.com/ethereum"
|
ethdir="$workspace/src/github.com/status-im"
|
||||||
if [ ! -L "$ethdir/go-ethereum" ]; then
|
if [ ! -L "$ethdir/status-go" ]; then
|
||||||
mkdir -p "$ethdir"
|
mkdir -p "$ethdir"
|
||||||
cd "$ethdir"
|
cd "$ethdir"
|
||||||
ln -s ../../../../../. go-ethereum
|
ln -s ../../../../../. status-go
|
||||||
cd "$root"
|
cd "$root"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -25,8 +25,8 @@ GOBIN="$PWD/build/bin"
|
||||||
export GOPATH GOBIN
|
export GOPATH GOBIN
|
||||||
|
|
||||||
# Run the command inside the workspace.
|
# Run the command inside the workspace.
|
||||||
cd "$ethdir/go-ethereum"
|
cd "$ethdir/status-go"
|
||||||
PWD="$ethdir/go-ethereum"
|
PWD="$ethdir/status-go"
|
||||||
|
|
||||||
# Launch the arguments with the configured environment.
|
# Launch the arguments with the configured environment.
|
||||||
exec "$@"
|
exec "$@"
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/robertkrimen/otto"
|
||||||
|
"fmt"
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
var statusJs string
|
||||||
|
var vms = make(map[string]*otto.Otto)
|
||||||
|
|
||||||
|
func Init(js string) {
|
||||||
|
statusJs = js
|
||||||
|
}
|
||||||
|
|
||||||
|
func printError(error string) string {
|
||||||
|
str := JSONError{
|
||||||
|
Error: error,
|
||||||
|
}
|
||||||
|
outBytes, _ := json.Marshal(&str)
|
||||||
|
return string(outBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func printResult(res string, err error) string {
|
||||||
|
var out string
|
||||||
|
if err != nil {
|
||||||
|
out = printError(err.Error())
|
||||||
|
} else {
|
||||||
|
if "undefined" == res {
|
||||||
|
res = "null";
|
||||||
|
}
|
||||||
|
out = fmt.Sprintf(`{"result": %s}`, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func Parse(chatId string, js string) string {
|
||||||
|
vm := otto.New()
|
||||||
|
jjs := statusJs + js + `
|
||||||
|
var catalog = JSON.stringify(_status_catalog);
|
||||||
|
`
|
||||||
|
vms[chatId] = vm
|
||||||
|
_, err := vm.Run(jjs)
|
||||||
|
res, _ := vm.Get("catalog")
|
||||||
|
|
||||||
|
return printResult(res.String(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Call(chatId string, path string, args string) string {
|
||||||
|
vm, ok := vms[chatId]
|
||||||
|
if !ok {
|
||||||
|
return printError(fmt.Sprintf("Vm[%s] doesn't exist.", chatId))
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := vm.Call("call", nil, path, args)
|
||||||
|
|
||||||
|
return printResult(res.String(), err);
|
||||||
|
}
|
|
@ -81,3 +81,20 @@ func StartNode(datadir *C.char) *C.char {
|
||||||
|
|
||||||
return C.CString(string(outBytes))
|
return C.CString(string(outBytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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))
|
||||||
|
}
|
||||||
|
|
|
@ -39,14 +39,21 @@ func main() {
|
||||||
// Placeholder for anything we want to run by default
|
// Placeholder for anything we want to run by default
|
||||||
fmt.Println("You are running statusgo!")
|
fmt.Println("You are running statusgo!")
|
||||||
|
|
||||||
|
createAndStartNode(".ethereum")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeNode create a geth node entity
|
// MakeNode create a geth node entity
|
||||||
func MakeNode(datadir string) *node.Node {
|
func MakeNode(datadir string) *node.Node {
|
||||||
|
|
||||||
|
// TODO remove admin rpcapi flag
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
set.Bool("shh", true, "whisper")
|
set.Bool("shh", true, "whisper")
|
||||||
set.Bool("noeth", true, "disable eth")
|
set.Bool("noeth", true, "disable eth")
|
||||||
|
set.Bool("rpc", true, "enable rpc")
|
||||||
|
set.String("rpcaddr", "localhost", "host for RPC")
|
||||||
|
set.String("rpcport", "8545", "rpc port")
|
||||||
|
set.String("rpcapi", "db,eth,net,web3,shh,admin", "rpc api(s)")
|
||||||
set.String("datadir", datadir, "data directory for geth")
|
set.String("datadir", datadir, "data directory for geth")
|
||||||
set.String("logdir", datadir, "log dir for glog")
|
set.String("logdir", datadir, "log dir for glog")
|
||||||
c = cli.NewContext(nil, set, nil)
|
c = cli.NewContext(nil, set, nil)
|
||||||
|
|
Loading…
Reference in New Issue