Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unable to parse abi with error types #62

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, ", "));
}
}
}