diff options
author | Felix Lange <fjl@twurst.com> | 2015-03-11 00:14:31 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-03-11 00:14:31 +0800 |
commit | 269cfbb8ace76ddc1f50dbd5b218c499308c8a5c (patch) | |
tree | c2e9e274c64f431f03b9a6b8b3de22585c016027 /ethutil/natspec/natspec.go | |
parent | 972e2c1e31067a9bab77228c19348b66964ce643 (diff) | |
parent | 0542df941f57a75fa7b699089db1d9ae40e4ff71 (diff) | |
download | go-tangerine-269cfbb8ace76ddc1f50dbd5b218c499308c8a5c.tar.gz go-tangerine-269cfbb8ace76ddc1f50dbd5b218c499308c8a5c.tar.zst go-tangerine-269cfbb8ace76ddc1f50dbd5b218c499308c8a5c.zip |
Merge branch origin/develop into accounts-integration
Conflicts:
cmd/blocktest/main.go
cmd/mist/debugger.go
cmd/utils/cmd.go
Diffstat (limited to 'ethutil/natspec/natspec.go')
-rw-r--r-- | ethutil/natspec/natspec.go | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/ethutil/natspec/natspec.go b/ethutil/natspec/natspec.go index 00e6f8720..793bf59ae 100644 --- a/ethutil/natspec/natspec.go +++ b/ethutil/natspec/natspec.go @@ -1,24 +1,21 @@ package natspec import ( + "fmt" "github.com/obscuren/otto" - "io/ioutil" ) type NatSpec struct { jsvm *otto.Otto } -func NewNATSpec(transaction string) (self *NatSpec, err error) { +// TODO: should initialise with abi and userdoc jsons +func New() (self *NatSpec, err error) { self = new(NatSpec) self.jsvm = otto.New() - code, err := ioutil.ReadFile("natspec.js") - if err != nil { - return - } - _, err = self.jsvm.Run(string(code)) + _, err = self.jsvm.Run(natspecJS) if err != nil { return } @@ -27,39 +24,40 @@ func NewNATSpec(transaction string) (self *NatSpec, err error) { return } - self.jsvm.Run("var transaction = " + transaction + ";") - - return -} - -func (self *NatSpec) SetDescription(desc string) (err error) { - - _, err = self.jsvm.Run("var expression = \"" + desc + "\";") return - } -func (self *NatSpec) SetABI(abi string) (err error) { - - _, err = self.jsvm.Run("var abi = " + abi + ";") - return - -} - -func (self *NatSpec) SetMethod(method string) (err error) { +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) + } - _, err = self.jsvm.Run("var method = '" + method + "';") - return + 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) + } -func (self *NatSpec) Parse() string { + 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 err.Error() + 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) } - return value.String() + if len(value.String()) == 0 { + return "", fmt.Errorf("natspec.js error evaluating expression") + } + + return value.String(), nil } |