Skip to content

Commit

Permalink
Post-review cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kberezin-p6 committed Oct 25, 2022
1 parent 142752f commit 3569111
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 19 deletions.
7 changes: 1 addition & 6 deletions abi/src/main/java/org/web3j/abi/TypeDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -565,12 +565,7 @@ private static <T extends Type> T decodeDynamicParameterFromStruct(
decodeDynamicArray(
dynamicElementData,
0,
new TypeReference<DynamicArray>() {
@Override
TypeReference getSubTypeReference() {
return TypeReference.create(parameter);
}
});
Utils.getDynamicArrayTypeReference(parameter));
} else {
value = decode(dynamicElementData, declaredField);
}
Expand Down
30 changes: 21 additions & 9 deletions abi/src/main/java/org/web3j/abi/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.web3j.abi.datatypes.*;
import org.web3j.abi.datatypes.DynamicArray;
import org.web3j.abi.datatypes.DynamicBytes;
import org.web3j.abi.datatypes.Fixed;
import org.web3j.abi.datatypes.Int;
import org.web3j.abi.datatypes.StaticArray;
import org.web3j.abi.datatypes.StaticStruct;
import org.web3j.abi.datatypes.StructType;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.Ufixed;
import org.web3j.abi.datatypes.Uint;
import org.web3j.abi.datatypes.Utf8String;
import org.web3j.abi.datatypes.reflection.Parameterized;

/** Utility functions. */
Expand Down Expand Up @@ -66,14 +76,7 @@ public static String getStructType(Class type) {
Class parameterAnnotation =
extractParameterFromAnnotation(constructor.getParameterAnnotations()[i]);
if (parameterAnnotation != null) {
sb.append(
getTypeName(
new TypeReference<DynamicArray>() {
@Override
TypeReference getSubTypeReference() {
return TypeReference.create(parameterAnnotation);
}
}));
sb.append(getTypeName(getDynamicArrayTypeReference(parameterAnnotation)));
} else {
sb.append(getTypeName(TypeReference.create(cls)));
}
Expand All @@ -86,6 +89,15 @@ TypeReference getSubTypeReference() {
return sb.toString();
}

public static TypeReference<DynamicArray> getDynamicArrayTypeReference(Class parameter) {
return new TypeReference<DynamicArray>() {
@Override
TypeReference getSubTypeReference() {
return TypeReference.create(parameter);
}
};
}

public static <T extends Type> Class<T> extractParameterFromAnnotation(
Annotation[] parameterAnnotation) {
for (Annotation a : parameterAnnotation) {
Expand Down
15 changes: 13 additions & 2 deletions abi/src/test/java/org/web3j/abi/AbiV2TestFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,19 @@
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.abi.datatypes.generated.Uint32;

import org.web3j.abi.datatypes.*;
import org.web3j.abi.datatypes.generated.*;
import org.web3j.abi.datatypes.DynamicArray;
import org.web3j.abi.datatypes.DynamicBytes;
import org.web3j.abi.datatypes.DynamicStruct;
import org.web3j.abi.datatypes.Event;
import org.web3j.abi.datatypes.Function;
import org.web3j.abi.datatypes.StaticStruct;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.Utf8String;
import org.web3j.abi.datatypes.generated.StaticArray1;
import org.web3j.abi.datatypes.generated.StaticArray2;
import org.web3j.abi.datatypes.generated.StaticArray3;
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.abi.datatypes.generated.Uint32;
import org.web3j.abi.datatypes.reflection.Parameterized;

public class AbiV2TestFixture {
Expand Down
15 changes: 13 additions & 2 deletions abi/src/test/java/org/web3j/abi/FunctionReturnDecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@

import org.junit.jupiter.api.Test;

import org.web3j.abi.datatypes.*;
import org.web3j.abi.datatypes.generated.*;
import org.web3j.abi.datatypes.DynamicArray;
import org.web3j.abi.datatypes.DynamicBytes;
import org.web3j.abi.datatypes.Function;
import org.web3j.abi.datatypes.StaticArray;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.Uint;
import org.web3j.abi.datatypes.Utf8String;
import org.web3j.abi.datatypes.generated.Bytes16;
import org.web3j.abi.datatypes.generated.Bytes32;
import org.web3j.abi.datatypes.generated.StaticArray2;
import org.web3j.abi.datatypes.generated.StaticArray3;
import org.web3j.abi.datatypes.generated.StaticArray4;
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.crypto.Hash;
import org.web3j.utils.Numeric;

Expand Down

0 comments on commit 3569111

Please sign in to comment.