diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go index 3d1010229c..a979a23c89 100644 --- a/accounts/abi/abi.go +++ b/accounts/abi/abi.go @@ -32,12 +32,14 @@ import ( // invokable methods. It will allow you to type check function calls and // packs data accordingly. type ABI struct { - Constructor Method - Methods map[string]Method - Events map[string]Event + Constructor Method `json:"constructor"` + Fallback Method `json:"fallback"` + Methods map[string]Method `json:"function"` + Events map[string]Event `json:"event"` } // JSON returns a parsed ABI interface and error if it failed. +// Note [RJ] - Can we deprecate this? func JSON(reader io.Reader) (ABI, error) { dec := json.NewDecoder(reader) @@ -372,46 +374,3 @@ func (abi ABI) Unpack(v interface{}, name string, output []byte) error { return nil } - -func (abi *ABI) UnmarshalJSON(data []byte) error { - var fields []struct { - Type string - Name string - Constant bool - Indexed bool - Anonymous bool - Inputs []Argument - Outputs []Argument - } - - if err := json.Unmarshal(data, &fields); err != nil { - return err - } - - abi.Methods = make(map[string]Method) - abi.Events = make(map[string]Event) - for _, field := range fields { - switch field.Type { - case "constructor": - abi.Constructor = Method{ - Inputs: field.Inputs, - } - // empty defaults to function according to the abi spec - case "function", "": - abi.Methods[field.Name] = Method{ - Name: field.Name, - Const: field.Constant, - Inputs: field.Inputs, - Outputs: field.Outputs, - } - case "event": - abi.Events[field.Name] = Event{ - Name: field.Name, - Anonymous: field.Anonymous, - Inputs: field.Inputs, - } - } - } - - return nil -} diff --git a/accounts/abi/argument.go b/accounts/abi/argument.go index 4691318ce7..aacc89cb1a 100644 --- a/accounts/abi/argument.go +++ b/accounts/abi/argument.go @@ -24,9 +24,9 @@ import ( // Argument holds the name of the argument and the corresponding type. // Types are used when packing and testing arguments. type Argument struct { - Name string - Type Type - Indexed bool // indexed is only used by events + Name string `json:"name"` + Type Type `json:"type"` + Indexed bool `json:"indexed"` // indexed is only used by events } func (a *Argument) UnmarshalJSON(data []byte) error { diff --git a/accounts/abi/event.go b/accounts/abi/event.go index 51ab842418..9f35e2eb45 100644 --- a/accounts/abi/event.go +++ b/accounts/abi/event.go @@ -28,9 +28,9 @@ import ( // holds type information (inputs) about the yielded output. Anonymous events // don't get the signature canonical representation as the first LOG topic. type Event struct { - Name string - Anonymous bool - Inputs []Argument + Name string `json:"name"` + Anonymous bool `json:"anonymous"` + Inputs []Argument `json:"inputs"` } // Id returns the canonical representation of the event's signature used by the diff --git a/accounts/abi/method.go b/accounts/abi/method.go index d56f3bc3dd..b8ba765d3c 100644 --- a/accounts/abi/method.go +++ b/accounts/abi/method.go @@ -33,10 +33,12 @@ import ( // be flagged `true`. // Input specifies the required input parameters for this gives method. type Method struct { - Name string - Const bool - Inputs []Argument - Outputs []Argument + Name string `json:"name"` + Const bool `json:"constant"` + Inputs []Argument `json:"inputs"` + Outputs []Argument `json:"outputs"` + //to add + // Payable bool `json:"payable"` } func (m Method) pack(method Method, args ...interface{}) ([]byte, error) {