blob: 33c072d4f126451b72d5d9971eb107434e30c889 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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()
}
|