aboutsummaryrefslogtreecommitdiffstats
path: root/ethereum
diff options
context:
space:
mode:
Diffstat (limited to 'ethereum')
-rw-r--r--ethereum/javascript_runtime.go19
-rw-r--r--ethereum/repl.go10
2 files changed, 28 insertions, 1 deletions
diff --git a/ethereum/javascript_runtime.go b/ethereum/javascript_runtime.go
index 93297f604..b05d39232 100644
--- a/ethereum/javascript_runtime.go
+++ b/ethereum/javascript_runtime.go
@@ -10,6 +10,7 @@ import (
"github.com/obscuren/otto"
"io/ioutil"
"os"
+ "path"
"path/filepath"
)
@@ -25,6 +26,20 @@ type JSRE struct {
objectCb map[string][]otto.Value
}
+func (jsre *JSRE) LoadExtFile(path string) {
+ result, err := ioutil.ReadFile(path)
+ if err == nil {
+ jsre.vm.Run(result)
+ } else {
+ ethutil.Config.Log.Debugln("Could not load file:", path)
+ }
+}
+
+func (jsre *JSRE) LoadIntFile(file string) {
+ assetPath := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "ethereal", "assets", "ext")
+ jsre.LoadExtFile(path.Join(assetPath, file))
+}
+
func NewJSRE(ethereum *eth.Ethereum) *JSRE {
re := &JSRE{
ethereum,
@@ -39,6 +54,10 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
// Init the JS lib
re.vm.Run(jsLib)
+ // Load extra javascript files
+ re.LoadIntFile("string.js")
+ re.LoadIntFile("big.js")
+
// We have to make sure that, whoever calls this, calls "Stop"
go re.mainLoop()
diff --git a/ethereum/repl.go b/ethereum/repl.go
index 10f51675e..0208459ad 100644
--- a/ethereum/repl.go
+++ b/ethereum/repl.go
@@ -66,6 +66,10 @@ func (self *JSEthereum) GetBlock(hash string) otto.Value {
return self.toVal(&JSBlock{self.PEthereum.GetBlock(hash), self})
}
+func (self *JSEthereum) GetPeers() otto.Value {
+ return self.toVal(self.PEthereum.GetPeers())
+}
+
func (self *JSEthereum) GetKey() otto.Value {
return self.toVal(self.PEthereum.GetKey())
}
@@ -74,6 +78,10 @@ func (self *JSEthereum) GetStateObject(addr string) otto.Value {
return self.toVal(self.PEthereum.GetStateObject(addr))
}
+func (self *JSEthereum) GetStateKeyVals(addr string) otto.Value {
+ return self.toVal(self.PEthereum.GetStateObject(addr).StateKeyVal(false))
+}
+
func (self *JSEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) otto.Value {
r, err := self.PEthereum.Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr)
if err != nil {
@@ -101,7 +109,7 @@ func (self *JSEthereum) toVal(v interface{}) otto.Value {
result, err := self.vm.ToValue(v)
if err != nil {
- fmt.Println(err)
+ fmt.Println("Value unknown:", err)
return otto.UndefinedValue()
}