From b408d1b3caad0b63f40c3ac201d6b5e4a16b74c3 Mon Sep 17 00:00:00 2001 From: Anton Tokalov Date: Wed, 6 Sep 2023 04:56:49 +0300 Subject: [PATCH] fix unable to parse abi with error types --- .../evm/abi/definition/AbiDefinition.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/osslabz/evm/abi/definition/AbiDefinition.java b/src/main/java/net/osslabz/evm/abi/definition/AbiDefinition.java index 6739224..8a7a40f 100644 --- a/src/main/java/net/osslabz/evm/abi/definition/AbiDefinition.java +++ b/src/main/java/net/osslabz/evm/abi/definition/AbiDefinition.java @@ -94,6 +94,10 @@ public Event findEvent(Predicate searchPredicate) { return find(Event.class, Entry.Type.event, searchPredicate); } + public Error findError(Predicate searchError) { + return find(Error.class, Entry.Type.error, searchError); + } + public Constructor findConstructor() { return find(Constructor.class, Entry.Type.constructor, object -> true); } @@ -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; @@ -181,7 +188,8 @@ public enum Type { function, event, fallback, - receive + receive, + error } @Data @@ -358,4 +366,19 @@ public String toString() { return format("event %s(%s);", name, join(inputs, ", ")); } } -} \ No newline at end of file + + public static class Error extends Entry { + public Error(String name, List 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, ", ")); + } + } +}