5757public class SolidityFunctionWrapper extends Generator {
5858
5959 private static final String BINARY = "BINARY" ;
60- private static final String WEB3J = "nervosj" ;
60+ private static final String NERVOSJ = "nervosj" ;
6161 private static final String CREDENTIALS = "credentials" ;
6262 private static final String TRANSACTION_MANAGER = "transactionManager" ;
6363 private static final String INITIAL_VALUE = "initialWeiValue" ;
@@ -256,23 +256,23 @@ private static MethodSpec buildConstructor(Class authType, String authName) {
256256 return MethodSpec .constructorBuilder ()
257257 .addModifiers (Modifier .PROTECTED )
258258 .addParameter (String .class , CONTRACT_ADDRESS )
259- .addParameter (Nervosj .class , WEB3J )
259+ .addParameter (Nervosj .class , NERVOSJ )
260260 .addParameter (authType , authName )
261261 .addParameter (BigInteger .class , GAS_PRICE )
262262 .addParameter (BigInteger .class , GAS_LIMIT )
263263 .addStatement ("super($N, $N, $N, $N, $N, $N)" ,
264- BINARY , CONTRACT_ADDRESS , WEB3J , authName , GAS_PRICE , GAS_LIMIT )
264+ BINARY , CONTRACT_ADDRESS , NERVOSJ , authName , GAS_PRICE , GAS_LIMIT )
265265 .build ();
266266 }
267267
268268 private static MethodSpec buildConstructorAdaptToCita (Class authType , String authName ) {
269269 return MethodSpec .constructorBuilder ()
270270 .addModifiers (Modifier .PROTECTED )
271271 .addParameter (String .class , CONTRACT_ADDRESS )
272- .addParameter (Nervosj .class , WEB3J )
272+ .addParameter (Nervosj .class , NERVOSJ )
273273 .addParameter (authType , authName )
274274 .addStatement ("super($N, $N, $N, $N)" ,
275- BINARY , CONTRACT_ADDRESS , WEB3J , authName )
275+ BINARY , CONTRACT_ADDRESS , NERVOSJ , authName )
276276 .build ();
277277 }
278278
@@ -319,11 +319,11 @@ private static MethodSpec buildDeployWithParams(
319319 if (isPayable ) {
320320 methodBuilder .addStatement (
321321 "return deployRemoteCall($L.class, $L, $L, $L, $L, $L, encodedConstructor, $L)" ,
322- className , WEB3J , authName , GAS_PRICE , GAS_LIMIT , BINARY , INITIAL_VALUE );
322+ className , NERVOSJ , authName , GAS_PRICE , GAS_LIMIT , BINARY , INITIAL_VALUE );
323323 } else {
324324 methodBuilder .addStatement (
325325 "return deployRemoteCall($L.class, $L, $L, $L, $L, $L, encodedConstructor)" ,
326- className , WEB3J , authName , GAS_PRICE , GAS_LIMIT , BINARY );
326+ className , NERVOSJ , authName , GAS_PRICE , GAS_LIMIT , BINARY );
327327 }
328328
329329 return methodBuilder .build ();
@@ -340,7 +340,7 @@ private static MethodSpec buildDeployWithParams(
340340 methodBuilder .addStatement (
341341 "return deployRemoteCall"
342342 + "($L.class, $L, $L, $L, $L, $L, $L, $L, $L, $L, encodedConstructor)" ,
343- className , WEB3J , authName , QUOTA , NONCE , VALID_UNTIL_BLOCK ,
343+ className , NERVOSJ , authName , QUOTA , NONCE , VALID_UNTIL_BLOCK ,
344344 VERSION , CHAIN_ID , VALUE , BINARY );
345345 return methodBuilder .build ();
346346 }
@@ -351,11 +351,11 @@ private static MethodSpec buildDeployNoParams(
351351 if (isPayable ) {
352352 methodBuilder .addStatement (
353353 "return deployRemoteCall($L.class, $L, $L, $L, $L, $L, \" \" , $L)" ,
354- className , WEB3J , authName , GAS_PRICE , GAS_LIMIT , BINARY , INITIAL_VALUE );
354+ className , NERVOSJ , authName , GAS_PRICE , GAS_LIMIT , BINARY , INITIAL_VALUE );
355355 } else {
356356 methodBuilder .addStatement (
357357 "return deployRemoteCall($L.class, $L, $L, $L, $L, $L, \" \" )" ,
358- className , WEB3J , authName , GAS_PRICE , GAS_LIMIT , BINARY );
358+ className , NERVOSJ , authName , GAS_PRICE , GAS_LIMIT , BINARY );
359359 }
360360
361361 return methodBuilder .build ();
@@ -367,7 +367,7 @@ private static MethodSpec buildDeployNoParams(
367367 methodBuilder .addStatement (
368368 "return deployRemoteCall"
369369 + "($L.class, $L, $L, $L, $L, $L, $L, $L, $L, $L, \" \" )" ,
370- className , WEB3J , authName , QUOTA , NONCE ,
370+ className , NERVOSJ , authName , QUOTA , NONCE ,
371371 VALID_UNTIL_BLOCK , VERSION , CHAIN_ID , VALUE , BINARY );
372372 return methodBuilder .build ();
373373 }
@@ -378,7 +378,7 @@ private static MethodSpec.Builder getDeployMethodSpec(
378378 .addModifiers (Modifier .PUBLIC , Modifier .STATIC )
379379 .returns (
380380 buildRemoteCall (TypeVariableName .get (className , Type .class )))
381- .addParameter (Nervosj .class , WEB3J )
381+ .addParameter (Nervosj .class , NERVOSJ )
382382 .addParameter (authType , authName )
383383 .addParameter (BigInteger .class , GAS_PRICE )
384384 .addParameter (BigInteger .class , GAS_LIMIT );
@@ -396,7 +396,7 @@ private static MethodSpec.Builder getDeployMethodSpec(
396396 .addModifiers (Modifier .PUBLIC , Modifier .STATIC )
397397 .returns (
398398 buildRemoteCall (TypeVariableName .get (className , Type .class )))
399- .addParameter (Nervosj .class , WEB3J )
399+ .addParameter (Nervosj .class , NERVOSJ )
400400 .addParameter (authType , authName )
401401 .addParameter (Long .class , QUOTA )
402402 .addParameter (BigInteger .class , NONCE )
@@ -413,12 +413,12 @@ private static MethodSpec buildLoad(
413413 .addModifiers (Modifier .PUBLIC , Modifier .STATIC )
414414 .returns (TypeVariableName .get (className , Type .class ))
415415 .addParameter (String .class , CONTRACT_ADDRESS )
416- .addParameter (Nervosj .class , WEB3J )
416+ .addParameter (Nervosj .class , NERVOSJ )
417417 .addParameter (authType , authName )
418418 .addParameter (BigInteger .class , GAS_PRICE )
419419 .addParameter (BigInteger .class , GAS_LIMIT )
420420 .addStatement ("return new $L($L, $L, $L, $L, $L)" , className ,
421- CONTRACT_ADDRESS , WEB3J , authName , GAS_PRICE , GAS_LIMIT )
421+ CONTRACT_ADDRESS , NERVOSJ , authName , GAS_PRICE , GAS_LIMIT )
422422 .build ();
423423 }
424424
@@ -428,10 +428,10 @@ private static MethodSpec buildLoadAdaptToCita(
428428 .addModifiers (Modifier .PUBLIC , Modifier .STATIC )
429429 .returns (TypeVariableName .get (className , Type .class ))
430430 .addParameter (String .class , CONTRACT_ADDRESS )
431- .addParameter (Nervosj .class , WEB3J )
431+ .addParameter (Nervosj .class , NERVOSJ )
432432 .addParameter (authType , authName )
433433 .addStatement ("return new $L($L, $L, $L)" , className ,
434- CONTRACT_ADDRESS , WEB3J , authName )
434+ CONTRACT_ADDRESS , NERVOSJ , authName )
435435 .build ();
436436 }
437437
@@ -671,7 +671,7 @@ private void buildConstantFunction(
671671 buildVariableLengthReturnFunctionConstructor (
672672 methodBuilder , functionName , inputParams , outputParameterTypes );
673673
674- buildTupleResultContainer (methodBuilder , parameterizedTupleType );
674+ buildTupleResultContainer (methodBuilder , parameterizedTupleType , outputParameterTypes );
675675 }
676676 }
677677
@@ -964,30 +964,54 @@ private static void buildVariableLengthReturnFunctionConstructor(
964964 }
965965
966966 private void buildTupleResultContainer (
967- MethodSpec .Builder methodBuilder , ParameterizedTypeName tupleType )
967+ MethodSpec .Builder methodBuilder , ParameterizedTypeName tupleType ,
968+ List <TypeName > outputParameterTypes )
968969 throws ClassNotFoundException {
969970
970971 List <TypeName > typeArguments = tupleType .typeArguments ;
971972
972973 CodeBlock .Builder tupleConstructor = CodeBlock .builder ();
973974 tupleConstructor .addStatement (
974- "$T results = executeCallMultipleValueReturn(function);" ,
975- ParameterizedTypeName .get (List .class , Type .class ))
975+ "$T results = executeCallMultipleValueReturn(function);" ,
976+ ParameterizedTypeName .get (List .class , Type .class ))
976977 .add ("return new $T(" , tupleType )
977978 .add ("$>$>" );
978979
979- String resultString = "\n ($T) results.get($L)" ;
980+ String resultStringSimple = "\n ($T) results.get($L)" ;
980981 if (useNativeJavaTypes ) {
981- resultString += ".getValue()" ;
982+ resultStringSimple += ".getValue()" ;
982983 }
983984
985+ String resultStringNativeList =
986+ "\n convertToNative(($T) results.get($L).getValue())" ;
987+
984988 int size = typeArguments .size ();
985- for (int i = 0 ; i < size - 1 ; i ++) {
989+ ClassName classList = ClassName .get (List .class );
990+
991+ for (int i = 0 ; i < size ; i ++) {
992+ TypeName param = outputParameterTypes .get (i );
993+ TypeName convertTo = typeArguments .get (i );
994+
995+ String resultString = resultStringSimple ;
996+
997+ // If we use native java types we need to convert
998+ // elements of arrays to native java types too
999+ if (useNativeJavaTypes && param instanceof ParameterizedTypeName ) {
1000+ ParameterizedTypeName oldContainer = (ParameterizedTypeName )param ;
1001+ ParameterizedTypeName newContainer = (ParameterizedTypeName )convertTo ;
1002+ if (newContainer .rawType .compareTo (classList ) == 0
1003+ && newContainer .typeArguments .size () == 1 ) {
1004+ convertTo = ParameterizedTypeName .get (classList ,
1005+ oldContainer .typeArguments .get (0 ));
1006+ resultString = resultStringNativeList ;
1007+ }
1008+ }
1009+
9861010 tupleConstructor
987- .add (resultString + ", " , typeArguments .get (i ), i );
1011+ .add (resultString , convertTo , i );
1012+ tupleConstructor .add (i < size - 1 ? ", " : ");\n " );
9881013 }
989- tupleConstructor
990- .add (resultString + ");\n " , typeArguments .get (size - 1 ), size - 1 );
1014+
9911015 tupleConstructor .add ("$<$<" );
9921016
9931017 TypeSpec callableType = TypeSpec .anonymousClassBuilder ("" )
0 commit comments