Skip to content

Commit 0cd7ebb

Browse files
committed
event and error data types
1 parent b8e1f4f commit 0cd7ebb

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed

abi-parser/src/main/java/com/openelements/hiero/smartcontract/abi/model/AbiEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.util.List;
44

5-
public interface AbiEntry {
5+
public sealed interface AbiEntry permits AbiEvent, AbiError, AbiFunction {
66

77
AbiEntryType type();
88

abi-parser/src/main/java/com/openelements/hiero/smartcontract/abi/model/AbiEntryType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
public enum AbiEntryType {
66
FUNCTION,
7+
ERROR,
78
EVENT,
89
CONSTRUCTOR,
910
RECEIVE,
@@ -13,6 +14,7 @@ public static AbiEntryType of(String name) {
1314
return switch (name) {
1415
case "function" -> FUNCTION;
1516
case "event" -> EVENT;
17+
case "error" -> ERROR;
1618
case "constructor" -> CONSTRUCTOR;
1719
case "receive" -> RECEIVE;
1820
case "fallback" -> FALLBACK;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.openelements.hiero.smartcontract.abi.model;
2+
3+
import java.util.List;
4+
import java.util.Objects;
5+
import org.jspecify.annotations.NonNull;
6+
7+
public record AbiError(@NonNull String name, @NonNull List<AbiParameter> inputs) implements AbiEntry {
8+
9+
public AbiError {
10+
Objects.requireNonNull(name, "name");
11+
Objects.requireNonNull(inputs, "inputs");
12+
}
13+
14+
@Override
15+
public AbiEntryType type() {
16+
return AbiEntryType.ERROR;
17+
}
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.openelements.hiero.smartcontract.abi.model;
2+
3+
import java.util.List;
4+
import java.util.Objects;
5+
import org.jspecify.annotations.NonNull;
6+
import org.jspecify.annotations.Nullable;
7+
8+
public record AbiEvent(@NonNull String name, @NonNull List<AbiParameter> inputs, boolean anonymous) implements AbiEntry{
9+
10+
public AbiEvent {
11+
Objects.requireNonNull(name, "name");
12+
Objects.requireNonNull(inputs, "inputs");
13+
}
14+
15+
@Override
16+
public AbiEntryType type() {
17+
return AbiEntryType.EVENT;
18+
}
19+
}

abi-parser/src/main/java/com/openelements/hiero/smartcontract/abi/model/AbiModel.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,23 @@ public record AbiModel(@NonNull List<AbiEntry> entries) {
99
public AbiModel {
1010
Objects.requireNonNull(entries, "entries");
1111
}
12+
13+
public List<AbiFunction> getFunctions() {
14+
return getEntriesOfType(AbiFunction.class);
15+
}
16+
17+
public List<AbiEvent> getEvents() {
18+
return getEntriesOfType(AbiEvent.class);
19+
}
20+
21+
public List<AbiError> getErrors() {
22+
return getEntriesOfType(AbiError.class);
23+
}
24+
25+
private <T extends AbiEntry> List<T> getEntriesOfType(Class<T> type) {
26+
return entries.stream()
27+
.filter(type::isInstance)
28+
.map(type::cast)
29+
.toList();
30+
}
1231
}

0 commit comments

Comments
 (0)