Skip to content

Commit

Permalink
Merge pull request #62 from Anton-To/feature/error-type-support
Browse files Browse the repository at this point in the history
fix unable to parse abi with error types
  • Loading branch information
rvullriede authored Feb 13, 2024
2 parents d54ef1d + b408d1b commit b4a0236
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/main/java/net/osslabz/evm/abi/definition/AbiDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public Event findEvent(Predicate<Event> searchPredicate) {
return find(Event.class, Entry.Type.event, searchPredicate);
}

public Error findError(Predicate<Error> searchError) {
return find(Error.class, Entry.Type.error, searchError);
}

public Constructor findConstructor() {
return find(Constructor.class, Entry.Type.constructor, object -> true);
}
Expand Down Expand Up @@ -148,6 +152,9 @@ public static Entry create(@JsonProperty("anonymous") boolean anonymous,
case event:
result = new Event(anonymous, name, inputs, outputs);
break;
case error:
result = new Error(name, inputs);
break;
}

return result;
Expand Down Expand Up @@ -181,7 +188,8 @@ public enum Type {
function,
event,
fallback,
receive
receive,
error
}

@Data
Expand Down Expand Up @@ -358,4 +366,19 @@ public String toString() {
return format("event %s(%s);", name, join(inputs, ", "));
}
}
}

public static class Error extends Entry {
public Error(String name, List<Param> inputs) {
super(null, null, name, inputs, null, Type.error, false);
}

public List<?> decode(byte[] encoded) {
return Param.decodeList(inputs, encoded);
}

@Override
public String toString() {
return format("error %s(%s);", name, join(inputs, ", "));
}
}
}

0 comments on commit b4a0236

Please sign in to comment.