aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/natspec/natspec.go
diff options
context:
space:
mode:
authorFefe <zsfelfoldi@gmail.com>2015-03-06 10:43:34 +0800
committerFefe <zsfelfoldi@gmail.com>2015-03-06 10:43:34 +0800
commitb67ded9f276172d8031ac3251d8d9c4fd7c8d3aa (patch)
treed113d257c55b26b379e0b860a70ca9b92b874643 /ethutil/natspec/natspec.go
parente64f727529287b7414af6d1f482ea5f318cbd2eb (diff)
downloaddexon-b67ded9f276172d8031ac3251d8d9c4fd7c8d3aa.tar
dexon-b67ded9f276172d8031ac3251d8d9c4fd7c8d3aa.tar.gz
dexon-b67ded9f276172d8031ac3251d8d9c4fd7c8d3aa.tar.bz2
dexon-b67ded9f276172d8031ac3251d8d9c4fd7c8d3aa.tar.lz
dexon-b67ded9f276172d8031ac3251d8d9c4fd7c8d3aa.tar.xz
dexon-b67ded9f276172d8031ac3251d8d9c4fd7c8d3aa.tar.zst
dexon-b67ded9f276172d8031ac3251d8d9c4fd7c8d3aa.zip
Natspec + test
Diffstat (limited to 'ethutil/natspec/natspec.go')
-rw-r--r--ethutil/natspec/natspec.go69
1 files changed, 69 insertions, 0 deletions
diff --git a/ethutil/natspec/natspec.go b/ethutil/natspec/natspec.go
new file mode 100644
index 000000000..33c072d4f
--- /dev/null
+++ b/ethutil/natspec/natspec.go
@@ -0,0 +1,69 @@
+package natspec
+
+import (
+ // "encoding/json"
+ // "fmt"
+ "github.com/ethereum/go-ethereum/eth"
+ "github.com/ethereum/go-ethereum/javascript"
+ "io/ioutil"
+)
+
+type NatSpec struct {
+ jsre *javascript.JSRE
+}
+
+func NewNATSpec(ethereum *eth.Ethereum, 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")
+ code, err := ioutil.ReadFile("natspec.js")
+ if err != nil {
+ return
+ }
+
+ _, err = self.jsre.Run(string(code))
+ if err != nil {
+ return
+ }
+ _, err = self.jsre.Run("var natspec = require('natspec');")
+ if err != nil {
+ return
+ }
+
+ self.jsre.Run("var transaction = " + transaction + ";")
+
+ return
+}
+
+func (self *NatSpec) SetDescription(desc string) (err error) {
+
+ _, err = self.jsre.Run("var expression = \"" + desc + "\";")
+ return
+
+}
+
+func (self *NatSpec) SetABI(abi string) (err error) {
+
+ _, err = self.jsre.Run("var abi = " + abi + ";")
+ return
+
+}
+
+func (self *NatSpec) SetMethod(method string) (err error) {
+
+ _, err = self.jsre.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);")
+ if err != nil {
+ return err.Error()
+ }
+ return value.String()
+
+}