mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
accounts/abi: begin tagging fields in structs
Signed-off-by: RJ Catalano <rj@monax.io>
This commit is contained in:
parent
344f25fb3e
commit
d65c84b1c9
4 changed files with 17 additions and 56 deletions
|
|
@ -32,12 +32,14 @@ import (
|
||||||
// invokable methods. It will allow you to type check function calls and
|
// invokable methods. It will allow you to type check function calls and
|
||||||
// packs data accordingly.
|
// packs data accordingly.
|
||||||
type ABI struct {
|
type ABI struct {
|
||||||
Constructor Method
|
Constructor Method `json:"constructor"`
|
||||||
Methods map[string]Method
|
Fallback Method `json:"fallback"`
|
||||||
Events map[string]Event
|
Methods map[string]Method `json:"function"`
|
||||||
|
Events map[string]Event `json:"event"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSON returns a parsed ABI interface and error if it failed.
|
// JSON returns a parsed ABI interface and error if it failed.
|
||||||
|
// Note [RJ] - Can we deprecate this?
|
||||||
func JSON(reader io.Reader) (ABI, error) {
|
func JSON(reader io.Reader) (ABI, error) {
|
||||||
dec := json.NewDecoder(reader)
|
dec := json.NewDecoder(reader)
|
||||||
|
|
||||||
|
|
@ -372,46 +374,3 @@ func (abi ABI) Unpack(v interface{}, name string, output []byte) error {
|
||||||
|
|
||||||
return nil
|
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@ import (
|
||||||
// Argument holds the name of the argument and the corresponding type.
|
// Argument holds the name of the argument and the corresponding type.
|
||||||
// Types are used when packing and testing arguments.
|
// Types are used when packing and testing arguments.
|
||||||
type Argument struct {
|
type Argument struct {
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
Type Type
|
Type Type `json:"type"`
|
||||||
Indexed bool // indexed is only used by events
|
Indexed bool `json:"indexed"` // indexed is only used by events
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Argument) UnmarshalJSON(data []byte) error {
|
func (a *Argument) UnmarshalJSON(data []byte) error {
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,9 @@ import (
|
||||||
// holds type information (inputs) about the yielded output. Anonymous events
|
// holds type information (inputs) about the yielded output. Anonymous events
|
||||||
// don't get the signature canonical representation as the first LOG topic.
|
// don't get the signature canonical representation as the first LOG topic.
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
Anonymous bool
|
Anonymous bool `json:"anonymous"`
|
||||||
Inputs []Argument
|
Inputs []Argument `json:"inputs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Id returns the canonical representation of the event's signature used by the
|
// Id returns the canonical representation of the event's signature used by the
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,12 @@ import (
|
||||||
// be flagged `true`.
|
// be flagged `true`.
|
||||||
// Input specifies the required input parameters for this gives method.
|
// Input specifies the required input parameters for this gives method.
|
||||||
type Method struct {
|
type Method struct {
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
Const bool
|
Const bool `json:"constant"`
|
||||||
Inputs []Argument
|
Inputs []Argument `json:"inputs"`
|
||||||
Outputs []Argument
|
Outputs []Argument `json:"outputs"`
|
||||||
|
//to add
|
||||||
|
// Payable bool `json:"payable"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Method) pack(method Method, args ...interface{}) ([]byte, error) {
|
func (m Method) pack(method Method, args ...interface{}) ([]byte, error) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue