aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/abi/abi.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <geffobscura@gmail.com>2016-01-27 15:38:53 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2016-02-02 22:28:59 +0800
commitbddf8f76c862fc4d096e8f51cc09b16640e3f13a (patch)
tree887c3661bd48c767f8fba563c549b8efb6dabc45 /accounts/abi/abi.go
parentd951ff300e7c390d91b3fa34bec4424522ecf8a0 (diff)
downloadgo-tangerine-bddf8f76c862fc4d096e8f51cc09b16640e3f13a.tar.gz
go-tangerine-bddf8f76c862fc4d096e8f51cc09b16640e3f13a.tar.zst
go-tangerine-bddf8f76c862fc4d096e8f51cc09b16640e3f13a.zip
account/abi: implements event parsing
Implementation of basic event parsing and its input types. This separates methods and events and fixes an issue with go type parsing and validation.
Diffstat (limited to 'accounts/abi/abi.go')
-rw-r--r--accounts/abi/abi.go32
1 files changed, 28 insertions, 4 deletions
diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go
index 635dc43fe..b84fd463a 100644
--- a/accounts/abi/abi.go
+++ b/accounts/abi/abi.go
@@ -37,6 +37,7 @@ type Executer func(datain []byte) []byte
// packs data accordingly.
type ABI struct {
Methods map[string]Method
+ Events map[string]Event
}
// JSON returns a parsed ABI interface and error if it failed.
@@ -149,14 +150,37 @@ func (abi ABI) Call(executer Executer, name string, args ...interface{}) interfa
}
func (abi *ABI) UnmarshalJSON(data []byte) error {
- var methods []Method
- if err := json.Unmarshal(data, &methods); err != nil {
+ var fields []struct {
+ Type string
+ Name string
+ Const bool
+ Indexed bool
+ Inputs []Argument
+ Outputs []Argument
+ }
+
+ if err := json.Unmarshal(data, &fields); err != nil {
return err
}
abi.Methods = make(map[string]Method)
- for _, method := range methods {
- abi.Methods[method.Name] = method
+ abi.Events = make(map[string]Event)
+ for _, field := range fields {
+ switch field.Type {
+ // empty defaults to function according to the abi spec
+ case "function", "":
+ abi.Methods[field.Name] = Method{
+ Name: field.Name,
+ Const: field.Const,
+ Inputs: field.Inputs,
+ Outputs: field.Outputs,
+ }
+ case "event":
+ abi.Events[field.Name] = Event{
+ Name: field.Name,
+ Inputs: field.Inputs,
+ }
+ }
}
return nil