Skip to content

Commit

Permalink
Merge pull request hyperledger-web3j#1673 from vchernetskyi993/fix/ar…
Browse files Browse the repository at this point in the history
…rays-in-structs

Fix array types in solidity struct constructor
  • Loading branch information
andrii-kl authored May 9, 2022
2 parents c38e2f0 + 21109ea commit 0987807
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public class SolidityFunctionWrapper extends Generator {

private static final ClassName LOG = ClassName.get(Log.class);
private static final Logger LOGGER = LoggerFactory.getLogger(SolidityFunctionWrapper.class);
private static final Pattern ARRAY_SUFFIX = Pattern.compile("\\[(\\d*)]");

private static final String CODEGEN_WARNING =
"<p>Auto generated code.\n"
Expand Down Expand Up @@ -505,8 +506,11 @@ private List<TypeSpec> buildStructTypes(final List<AbiDefinition> functionDefini
i
== component
.structIdentifier())
? ".getValue()"
: ""));
? ARRAY_SUFFIX.matcher(component.getType()).find()
? ".getValue().stream().map(v -> v.getValue()).collect($T.toList())"
: ".getValue()"
: ""),
Collectors.class);
}

builder.superclass(namedType.isDynamic() ? DynamicStruct.class : StaticStruct.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Address;
import org.web3j.abi.datatypes.Bool;
Expand Down Expand Up @@ -212,24 +213,24 @@ public Entity(DynamicBytes bytesField, Bytes32 extraData, DynamicArray<Utf8Strin
super(bytesField, extraData, stringArrayField, bytesArrayField, bytes2ArrayField, bytes32ArrayField, unitArrayField, unit256ArrayField, boolField, intArrayField, addressArrayField, stringArrayFieldStatic, bytesArrayFieldStatic, bytes2ArrayFieldStatic, bytes32ArrayFieldStatic, unitArrayFieldStatic, unit256ArrayFieldStatic, boolFieldStatic, intArrayFieldStatic, addressArrayFieldStatic);
this.bytesField = bytesField.getValue();
this.extraData = extraData.getValue();
this.stringArrayField = stringArrayField.getValue();
this.bytesArrayField = bytesArrayField.getValue();
this.bytes2ArrayField = bytes2ArrayField.getValue();
this.bytes32ArrayField = bytes32ArrayField.getValue();
this.unitArrayField = unitArrayField.getValue();
this.unit256ArrayField = unit256ArrayField.getValue();
this.boolField = boolField.getValue();
this.intArrayField = intArrayField.getValue();
this.addressArrayField = addressArrayField.getValue();
this.stringArrayFieldStatic = stringArrayFieldStatic.getValue();
this.bytesArrayFieldStatic = bytesArrayFieldStatic.getValue();
this.bytes2ArrayFieldStatic = bytes2ArrayFieldStatic.getValue();
this.bytes32ArrayFieldStatic = bytes32ArrayFieldStatic.getValue();
this.unitArrayFieldStatic = unitArrayFieldStatic.getValue();
this.unit256ArrayFieldStatic = unit256ArrayFieldStatic.getValue();
this.boolFieldStatic = boolFieldStatic.getValue();
this.intArrayFieldStatic = intArrayFieldStatic.getValue();
this.addressArrayFieldStatic = addressArrayFieldStatic.getValue();
this.stringArrayField = stringArrayField.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
this.bytesArrayField = bytesArrayField.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
this.bytes2ArrayField = bytes2ArrayField.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
this.bytes32ArrayField = bytes32ArrayField.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
this.unitArrayField = unitArrayField.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
this.unit256ArrayField = unit256ArrayField.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
this.boolField = boolField.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
this.intArrayField = intArrayField.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
this.addressArrayField = addressArrayField.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
this.stringArrayFieldStatic = stringArrayFieldStatic.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
this.bytesArrayFieldStatic = bytesArrayFieldStatic.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
this.bytes2ArrayFieldStatic = bytes2ArrayFieldStatic.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
this.bytes32ArrayFieldStatic = bytes32ArrayFieldStatic.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
this.unitArrayFieldStatic = unitArrayFieldStatic.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
this.unit256ArrayFieldStatic = unit256ArrayFieldStatic.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
this.boolFieldStatic = boolFieldStatic.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
this.intArrayFieldStatic = intArrayFieldStatic.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
this.addressArrayFieldStatic = addressArrayFieldStatic.getValue().stream().map(v -> v.getValue()).collect(Collectors.toList());
}
}
}

0 comments on commit 0987807

Please sign in to comment.