diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-16 18:27:38 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-16 18:27:38 +0800 |
commit | b5234413611ce5984292f85a01de1f56c045b490 (patch) | |
tree | e6e0c6f7fe8358a2dc63cdea11ac66b4f59397f5 /ethutil/natspec/natspec.go | |
parent | 0b8f66ed9ef177dc72442dd7ba337c6733e30344 (diff) | |
download | dexon-b5234413611ce5984292f85a01de1f56c045b490.tar dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.gz dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.bz2 dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.lz dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.xz dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.zst dexon-b5234413611ce5984292f85a01de1f56c045b490.zip |
Moved ethutil => common
Diffstat (limited to 'ethutil/natspec/natspec.go')
-rw-r--r-- | ethutil/natspec/natspec.go | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/ethutil/natspec/natspec.go b/ethutil/natspec/natspec.go deleted file mode 100644 index 793bf59ae..000000000 --- a/ethutil/natspec/natspec.go +++ /dev/null @@ -1,63 +0,0 @@ -package natspec - -import ( - "fmt" - "github.com/obscuren/otto" -) - -type NatSpec struct { - jsvm *otto.Otto -} - -// TODO: should initialise with abi and userdoc jsons -func New() (self *NatSpec, err error) { - - self = new(NatSpec) - self.jsvm = otto.New() - - _, err = self.jsvm.Run(natspecJS) - if err != nil { - return - } - _, err = self.jsvm.Run("var natspec = require('natspec');") - if err != nil { - return - } - - return -} - -func (self *NatSpec) Notice(transaction, abi, method, expression string) (string, error) { - var err error - if _, err = self.jsvm.Run("var transaction = " + transaction + ";"); err != nil { - return "", fmt.Errorf("natspec.js error setting transaction: %v", err) - } - - if _, err = self.jsvm.Run("var abi = " + abi + ";"); err != nil { - return "", fmt.Errorf("natspec.js error setting abi: %v", err) - } - - if _, err = self.jsvm.Run("var method = '" + method + "';"); err != nil { - return "", fmt.Errorf("natspec.js error setting method: %v", err) - } - - if _, err = self.jsvm.Run("var expression = \"" + expression + "\";"); err != nil { - return "", fmt.Errorf("natspec.js error setting expression: %v", err) - } - - self.jsvm.Run("var call = {method: method,abi: abi,transaction: transaction};") - value, err := self.jsvm.Run("natspec.evaluateExpression(expression, call);") - if err != nil { - return "", fmt.Errorf("natspec.js error evaluating expression: %v", err) - } - evalError := "Natspec evaluation failed, wrong input params" - if value.String() == evalError { - return "", fmt.Errorf("natspec.js error evaluating expression: wrong input params in expression '%s'", expression) - } - if len(value.String()) == 0 { - return "", fmt.Errorf("natspec.js error evaluating expression") - } - - return value.String(), nil - -} |