diff options
author | Felix Lange <fjl@twurst.com> | 2015-03-10 06:25:46 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-03-10 06:25:46 +0800 |
commit | 9bf513e99305af733110cf23a0b47c8e73359010 (patch) | |
tree | f9d36e1ae1f2f7c3eb803c7499a4e85a5cdcd5bd /ethutil/natspec/natspec.go | |
parent | cd51860bf024d949a09b3863c88a278a386227a7 (diff) | |
parent | 676a0de58d3d7c508b0eeeff192d2095a46f7382 (diff) | |
download | dexon-9bf513e99305af733110cf23a0b47c8e73359010.tar dexon-9bf513e99305af733110cf23a0b47c8e73359010.tar.gz dexon-9bf513e99305af733110cf23a0b47c8e73359010.tar.bz2 dexon-9bf513e99305af733110cf23a0b47c8e73359010.tar.lz dexon-9bf513e99305af733110cf23a0b47c8e73359010.tar.xz dexon-9bf513e99305af733110cf23a0b47c8e73359010.tar.zst dexon-9bf513e99305af733110cf23a0b47c8e73359010.zip |
Merge ethereum/poc-9 into accounts-integration
Conflicts:
cmd/utils/cmd.go
cmd/utils/flags.go
core/manager.go
eth/backend.go
rpc/http/server.go
xeth/xeth.go
Diffstat (limited to 'ethutil/natspec/natspec.go')
-rw-r--r-- | ethutil/natspec/natspec.go | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/ethutil/natspec/natspec.go b/ethutil/natspec/natspec.go new file mode 100644 index 000000000..00e6f8720 --- /dev/null +++ b/ethutil/natspec/natspec.go @@ -0,0 +1,65 @@ +package natspec + +import ( + "github.com/obscuren/otto" + "io/ioutil" +) + +type NatSpec struct { + jsvm *otto.Otto +} + +func NewNATSpec(transaction string) (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)) + if err != nil { + return + } + _, err = self.jsvm.Run("var natspec = require('natspec');") + if err != nil { + 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) { + + _, err = self.jsvm.Run("var method = '" + method + "';") + return + +} + +func (self *NatSpec) Parse() string { + + 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 value.String() + +} |