Skip to content

Commit

Permalink
ABIJSON refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
esaulpaugh committed Oct 10, 2024
1 parent f99829a commit cfad274
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/main/java/com/esaulpaugh/headlong/abi/ABIJSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ static String toJson(ABIObject o, boolean pretty) {
}
}
}
stateMutability(out, f.getStateMutability());
String stateMutability = f.getStateMutability();
if (stateMutability != null) {
out.name(STATE_MUTABILITY).value(stateMutability);
}
} else if (o.isEvent()) {
final Event<?> e = o.asEvent();
type(out, EVENT);
Expand Down Expand Up @@ -198,25 +201,16 @@ private static void name(JsonWriter out, String name) throws IOException {
}
}

private static void internalType(JsonWriter out, String internalType) throws IOException {
if (internalType != null) {
out.name(INTERNAL_TYPE).value(internalType);
}
}

private static void stateMutability(JsonWriter out, String stateMutability) throws IOException {
if (stateMutability != null) {
out.name(STATE_MUTABILITY).value(stateMutability);
}
}

private static void tupleType(JsonWriter out, String name, TupleType<?> tupleType, boolean[] indexedManifest) throws IOException {
out.name(name).beginArray();
int i = 0;
for (final ABIType<?> e : tupleType) {
for (int i = 0; i < tupleType.elementTypes.length; i++) {
final ABIType<?> e = tupleType.elementTypes[i];
out.beginObject();
if (tupleType.elementInternalTypes != null) {
internalType(out, tupleType.elementInternalTypes[i]);
String internalType = tupleType.elementInternalTypes[i];
if (internalType != null) {
out.name(INTERNAL_TYPE).value(internalType);
}
}
if (tupleType.elementNames != null) {
name(out, tupleType.elementNames[i]);
Expand All @@ -232,7 +226,6 @@ private static void tupleType(JsonWriter out, String name, TupleType<?> tupleTyp
out.name(INDEXED).value(indexedManifest[i]);
}
out.endObject();
i++;
}
out.endArray();
}
Expand Down

0 comments on commit cfad274

Please sign in to comment.