Skip to content

Commit 1ed7098

Browse files
committed
Add a check on the duplicated event names hyperledger-web3j#1781
1 parent a21a379 commit 1ed7098

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

codegen/src/main/java/org/web3j/codegen/SolidityFunctionWrapper.java

+21
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ private List<MethodSpec> buildFunctionDefinitions(
423423
throws ClassNotFoundException {
424424

425425
Set<String> duplicateFunctionNames = getDuplicateFunctionNames(functionDefinitions);
426+
changeEventsName(functionDefinitions);
426427
List<MethodSpec> methodSpecs = new ArrayList<>();
427428
for (AbiDefinition functionDefinition : functionDefinitions) {
428429
if (functionDefinition.getType().equals(TYPE_FUNCTION)) {
@@ -436,6 +437,25 @@ private List<MethodSpec> buildFunctionDefinitions(
436437
return methodSpecs;
437438
}
438439

440+
private void changeEventsName(List<AbiDefinition> functionDefinitions) {
441+
442+
Map<String, Integer> countMap = new HashMap<>();
443+
444+
for (AbiDefinition functionDefinition : functionDefinitions) {
445+
if (TYPE_EVENT.equals(functionDefinition.getType())
446+
&& functionDefinition.getName() != null) {
447+
String s = functionDefinition.getName();
448+
if (countMap.containsKey(s)) {
449+
int count = countMap.get(s);
450+
functionDefinition.setName(s + count);
451+
countMap.put(s, count + 1);
452+
} else {
453+
countMap.put(s, 1);
454+
}
455+
}
456+
}
457+
}
458+
439459
private List<TypeSpec> buildStructTypes(final List<AbiDefinition> functionDefinitions)
440460
throws ClassNotFoundException {
441461
final List<AbiDefinition.NamedType> orderedKeys = extractStructs(functionDefinitions);
@@ -723,6 +743,7 @@ Iterable<FieldSpec> buildFuncNameConstants(List<AbiDefinition> functionDefinitio
723743
Set<String> fieldNames = new HashSet<>();
724744
fieldNames.add(Contract.FUNC_DEPLOY);
725745
Set<String> duplicateFunctionNames = getDuplicateFunctionNames(functionDefinitions);
746+
changeEventsName(functionDefinitions);
726747
if (!duplicateFunctionNames.isEmpty()) {
727748
System.out.println(
728749
"\nWarning: Duplicate field(s) found: "

0 commit comments

Comments
 (0)