aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/natspec/natspec.go
diff options
context:
space:
mode:
authorFefe <zsfelfoldi@gmail.com>2015-03-07 01:54:26 +0800
committerFefe <zsfelfoldi@gmail.com>2015-03-07 01:54:26 +0800
commite1571472538e276ad9d9da3f2169dbd50a3bedfe (patch)
tree33d3a306597cff9ad18251923c2e96ecede26c5f /ethutil/natspec/natspec.go
parentb67ded9f276172d8031ac3251d8d9c4fd7c8d3aa (diff)
downloaddexon-e1571472538e276ad9d9da3f2169dbd50a3bedfe.tar
dexon-e1571472538e276ad9d9da3f2169dbd50a3bedfe.tar.gz
dexon-e1571472538e276ad9d9da3f2169dbd50a3bedfe.tar.bz2
dexon-e1571472538e276ad9d9da3f2169dbd50a3bedfe.tar.lz
dexon-e1571472538e276ad9d9da3f2169dbd50a3bedfe.tar.xz
dexon-e1571472538e276ad9d9da3f2169dbd50a3bedfe.tar.zst
dexon-e1571472538e276ad9d9da3f2169dbd50a3bedfe.zip
Now using github.com/obscuren/otto, no need for an Ethereum object
(got rid of some messy code in test)
Diffstat (limited to 'ethutil/natspec/natspec.go')
-rw-r--r--ethutil/natspec/natspec.go28
1 files changed, 12 insertions, 16 deletions
diff --git a/ethutil/natspec/natspec.go b/ethutil/natspec/natspec.go
index 33c072d4f..00e6f8720 100644
--- a/ethutil/natspec/natspec.go
+++ b/ethutil/natspec/natspec.go
@@ -1,66 +1,62 @@
package natspec
import (
- // "encoding/json"
- // "fmt"
- "github.com/ethereum/go-ethereum/eth"
- "github.com/ethereum/go-ethereum/javascript"
+ "github.com/obscuren/otto"
"io/ioutil"
)
type NatSpec struct {
- jsre *javascript.JSRE
+ jsvm *otto.Otto
}
-func NewNATSpec(ethereum *eth.Ethereum, transaction string) (self *NatSpec, err error) {
+func NewNATSpec(transaction string) (self *NatSpec, err error) {
self = new(NatSpec)
- self.jsre = javascript.NewJSRE(ethereum)
- //self.jsre.LoadExtFile("/home/fefe/go-ethereum/ethutil/natspec/natspec.js")
+ self.jsvm = otto.New()
code, err := ioutil.ReadFile("natspec.js")
if err != nil {
return
}
- _, err = self.jsre.Run(string(code))
+ _, err = self.jsvm.Run(string(code))
if err != nil {
return
}
- _, err = self.jsre.Run("var natspec = require('natspec');")
+ _, err = self.jsvm.Run("var natspec = require('natspec');")
if err != nil {
return
}
- self.jsre.Run("var transaction = " + transaction + ";")
+ self.jsvm.Run("var transaction = " + transaction + ";")
return
}
func (self *NatSpec) SetDescription(desc string) (err error) {
- _, err = self.jsre.Run("var expression = \"" + desc + "\";")
+ _, err = self.jsvm.Run("var expression = \"" + desc + "\";")
return
}
func (self *NatSpec) SetABI(abi string) (err error) {
- _, err = self.jsre.Run("var abi = " + abi + ";")
+ _, err = self.jsvm.Run("var abi = " + abi + ";")
return
}
func (self *NatSpec) SetMethod(method string) (err error) {
- _, err = self.jsre.Run("var method = '" + method + "';")
+ _, err = self.jsvm.Run("var method = '" + method + "';")
return
}
func (self *NatSpec) Parse() string {
- self.jsre.Run("var call = {method: method,abi: abi,transaction: transaction};")
- value, err := self.jsre.Run("natspec.evaluateExpression(expression, call);")
+ self.jsvm.Run("var call = {method: method,abi: abi,transaction: transaction};")
+ value, err := self.jsvm.Run("natspec.evaluateExpression(expression, call);")
if err != nil {
return err.Error()
}