Skip to content

Commit

Permalink
accounts/abi: events can't be overloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed Jul 6, 2021
1 parent 015af49 commit 0883718
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
3 changes: 1 addition & 2 deletions accounts/abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
name := overloadedName(field.Name, func(s string) bool { _, ok := abi.Events[s]; return ok })
abi.Events[name] = NewEvent(name, field.Name, field.Anonymous, field.Inputs)
case "error":
name := overloadedName(field.Name, func(s string) bool { _, ok := abi.Errors[s]; return ok })
abi.Errors[name] = NewError(name, field.Name, field.Inputs)
abi.Errors[field.Name] = NewError(field.Name, field.Inputs)
default:
return fmt.Errorf("abi: could not recognize type %v of field %v", field.Type, field.Name)
}
Expand Down
25 changes: 11 additions & 14 deletions accounts/abi/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ import (
)

type Error struct {
Name string
// RawName might be overloaded
RawName string
Inputs Arguments
str string
Name string
Inputs Arguments
str string
// Sig contains the string signature according to the ABI spec.
// e.g. event foo(uint32 a, int b) = "foo(uint32,int256)"
// Please note that "int" is substitute for its canonical representation "int256"
Expand All @@ -39,7 +37,7 @@ type Error struct {
ID common.Hash
}

func NewError(name, rawName string, inputs Arguments) Error {
func NewError(name string, inputs Arguments) Error {
// sanitize inputs to remove inputs without names
// and precompute string and sig representation.
names := make([]string, len(inputs))
Expand All @@ -63,17 +61,16 @@ func NewError(name, rawName string, inputs Arguments) Error {
types[i] = input.Type.String()
}

str := fmt.Sprintf("event %v(%v)", rawName, strings.Join(names, ", "))
sig := fmt.Sprintf("%v(%v)", rawName, strings.Join(types, ","))
str := fmt.Sprintf("event %v(%v)", name, strings.Join(names, ", "))
sig := fmt.Sprintf("%v(%v)", name, strings.Join(types, ","))
id := common.BytesToHash(crypto.Keccak256([]byte(sig)))

return Error{
Name: name,
RawName: rawName,
Inputs: inputs,
str: str,
Sig: sig,
ID: id,
Name: name,
Inputs: inputs,
str: str,
Sig: sig,
ID: id,
}
}

Expand Down

0 comments on commit 0883718

Please sign in to comment.