5555import org .web3j .protocol .core .methods .response .TransactionReceipt ;
5656import org .web3j .tx .Contract ;
5757import org .web3j .tx .TransactionManager ;
58+ import org .web3j .tx .gas .ContractGasProvider ;
5859import org .web3j .utils .Collection ;
5960import org .web3j .utils .Strings ;
6061import org .web3j .utils .Version ;
@@ -67,6 +68,7 @@ public class SolidityFunctionWrapper extends Generator {
6768 private static final String BINARY = "BINARY" ;
6869 private static final String WEB3J = "web3j" ;
6970 private static final String CREDENTIALS = "credentials" ;
71+ private static final String CONTRACT_GAS_PROVIDER = "contractGasProvider" ;
7072 private static final String TRANSACTION_MANAGER = "transactionManager" ;
7173 private static final String INITIAL_VALUE = "initialWeiValue" ;
7274 private static final String CONTRACT_ADDRESS = "contractAddress" ;
@@ -122,15 +124,21 @@ void generateJavaFiles(
122124
123125 TypeSpec .Builder classBuilder = createClassBuilder (className , bin );
124126
125- classBuilder .addMethod (buildConstructor (Credentials .class , CREDENTIALS ));
127+ classBuilder .addMethod (buildConstructor (Credentials .class , CREDENTIALS , false ));
128+ classBuilder .addMethod (buildConstructor (Credentials .class , CREDENTIALS , true ));
126129 classBuilder .addMethod (buildConstructor (TransactionManager .class ,
127- TRANSACTION_MANAGER ));
130+ TRANSACTION_MANAGER , false ));
131+ classBuilder .addMethod (buildConstructor (TransactionManager .class ,
132+ TRANSACTION_MANAGER , true ));
128133 classBuilder .addFields (buildFuncNameConstants (abi ));
129134 classBuilder .addMethods (
130135 buildFunctionDefinitions (className , classBuilder , abi ));
131- classBuilder .addMethod (buildLoad (className , Credentials .class , CREDENTIALS ));
136+ classBuilder .addMethod (buildLoad (className , Credentials .class , CREDENTIALS , false ));
137+ classBuilder .addMethod (buildLoad (className , TransactionManager .class ,
138+ TRANSACTION_MANAGER , false ));
139+ classBuilder .addMethod (buildLoad (className , Credentials .class , CREDENTIALS , true ));
132140 classBuilder .addMethod (buildLoad (className , TransactionManager .class ,
133- TRANSACTION_MANAGER ));
141+ TRANSACTION_MANAGER , true ));
134142
135143 addAddressesSupport (classBuilder , addresses );
136144
@@ -257,25 +265,49 @@ private List<MethodSpec> buildFunctionDefinitions(
257265 } else if (functionDefinition .getType ().equals ("constructor" )) {
258266 constructor = true ;
259267 methodSpecs .add (buildDeploy (
260- className , functionDefinition , Credentials .class , CREDENTIALS ));
268+ className , functionDefinition , Credentials .class , CREDENTIALS , true ));
269+ methodSpecs .add (buildDeploy (
270+ className , functionDefinition , TransactionManager .class ,
271+ TRANSACTION_MANAGER , true ));
272+ methodSpecs .add (buildDeploy (
273+ className , functionDefinition , Credentials .class , CREDENTIALS , false ));
261274 methodSpecs .add (buildDeploy (
262275 className , functionDefinition , TransactionManager .class ,
263- TRANSACTION_MANAGER ));
276+ TRANSACTION_MANAGER , false ));
264277 }
265278 }
266279
267280 // constructor will not be specified in ABI file if its empty
268281 if (!constructor ) {
269282 MethodSpec .Builder credentialsMethodBuilder =
270- getDeployMethodSpec (className , Credentials .class , CREDENTIALS , false );
283+ getDeployMethodSpec (className , Credentials .class , CREDENTIALS ,
284+ false , true );
285+ methodSpecs .add (buildDeployNoParams (
286+ credentialsMethodBuilder , className , CREDENTIALS ,
287+ false , true ));
288+
289+ MethodSpec .Builder credentialsMethodBuilderNoGasProvider =
290+ getDeployMethodSpec (className , Credentials .class , CREDENTIALS ,
291+ false , false );
271292 methodSpecs .add (buildDeployNoParams (
272- credentialsMethodBuilder , className , CREDENTIALS , false ));
293+ credentialsMethodBuilderNoGasProvider , className , CREDENTIALS ,
294+ false , false ));
273295
274296 MethodSpec .Builder transactionManagerMethodBuilder =
275297 getDeployMethodSpec (
276- className , TransactionManager .class , TRANSACTION_MANAGER , false );
298+ className , TransactionManager .class , TRANSACTION_MANAGER ,
299+ false , true );
277300 methodSpecs .add (buildDeployNoParams (
278- transactionManagerMethodBuilder , className , TRANSACTION_MANAGER , false ));
301+ transactionManagerMethodBuilder , className , TRANSACTION_MANAGER ,
302+ false , true ));
303+
304+ MethodSpec .Builder transactionManagerMethodBuilderNoGasProvider =
305+ getDeployMethodSpec (
306+ className , TransactionManager .class , TRANSACTION_MANAGER ,
307+ false , false );
308+ methodSpecs .add (buildDeployNoParams (
309+ transactionManagerMethodBuilderNoGasProvider , className , TRANSACTION_MANAGER ,
310+ false , false ));
279311 }
280312
281313 return methodSpecs ;
@@ -304,105 +336,154 @@ Iterable<FieldSpec> buildFuncNameConstants(List<AbiDefinition> functionDefinitio
304336 return fields ;
305337 }
306338
307- private static MethodSpec buildConstructor (Class authType , String authName ) {
308- return MethodSpec .constructorBuilder ()
339+ private static MethodSpec buildConstructor (Class authType , String authName ,
340+ boolean withGasProvider ) {
341+ MethodSpec .Builder toReturn = MethodSpec .constructorBuilder ()
309342 .addModifiers (Modifier .PROTECTED )
310343 .addParameter (String .class , CONTRACT_ADDRESS )
311344 .addParameter (Web3j .class , WEB3J )
312- .addParameter (authType , authName )
313- .addParameter (BigInteger .class , GAS_PRICE )
314- .addParameter (BigInteger .class , GAS_LIMIT )
315- .addStatement ("super($N, $N, $N, $N, $N, $N)" ,
316- BINARY , CONTRACT_ADDRESS , WEB3J , authName , GAS_PRICE , GAS_LIMIT )
317- .build ();
345+ .addParameter (authType , authName );
346+
347+ if (withGasProvider ) {
348+ toReturn .addParameter (ContractGasProvider .class , CONTRACT_GAS_PROVIDER )
349+ .addStatement ("super($N, $N, $N, $N, $N)" ,
350+ BINARY , CONTRACT_ADDRESS , WEB3J , authName , CONTRACT_GAS_PROVIDER );
351+ } else {
352+ toReturn .addParameter (BigInteger .class , GAS_PRICE )
353+ .addParameter (BigInteger .class , GAS_LIMIT )
354+ .addStatement ("super($N, $N, $N, $N, $N, $N)" ,
355+ BINARY , CONTRACT_ADDRESS , WEB3J , authName , GAS_PRICE , GAS_LIMIT )
356+ .addAnnotation (Deprecated .class );
357+ }
358+
359+ return toReturn .build ();
318360 }
319361
320362 private MethodSpec buildDeploy (
321363 String className , AbiDefinition functionDefinition ,
322- Class authType , String authName ) {
364+ Class authType , String authName , boolean withGasProvider ) {
323365
324366 boolean isPayable = functionDefinition .isPayable ();
325367
326368 MethodSpec .Builder methodBuilder = getDeployMethodSpec (
327- className , authType , authName , isPayable );
369+ className , authType , authName , isPayable , withGasProvider );
328370 String inputParams = addParameters (methodBuilder , functionDefinition .getInputs ());
329371
330372 if (!inputParams .isEmpty ()) {
331373 return buildDeployWithParams (
332- methodBuilder , className , inputParams , authName , isPayable );
374+ methodBuilder , className , inputParams , authName ,
375+ isPayable , withGasProvider );
333376 } else {
334- return buildDeployNoParams (methodBuilder , className , authName , isPayable );
377+ return buildDeployNoParams (methodBuilder , className , authName ,
378+ isPayable , withGasProvider );
335379 }
336380 }
337381
338382 private static MethodSpec buildDeployWithParams (
339383 MethodSpec .Builder methodBuilder , String className , String inputParams ,
340- String authName , boolean isPayable ) {
384+ String authName , boolean isPayable , boolean withGasProvider ) {
341385
342386 methodBuilder .addStatement ("$T encodedConstructor = $T.encodeConstructor("
343387 + "$T.<$T>asList($L)"
344388 + ")" ,
345389 String .class , FunctionEncoder .class , Arrays .class , Type .class , inputParams );
346- if (isPayable ) {
390+ if (isPayable && ! withGasProvider ) {
347391 methodBuilder .addStatement (
348392 "return deployRemoteCall("
349393 + "$L.class, $L, $L, $L, $L, $L, encodedConstructor, $L)" ,
350394 className , WEB3J , authName , GAS_PRICE , GAS_LIMIT , BINARY , INITIAL_VALUE );
351- } else {
395+ methodBuilder .addAnnotation (Deprecated .class );
396+ } else if (isPayable && withGasProvider ) {
397+ methodBuilder .addStatement (
398+ "return deployRemoteCall("
399+ + "$L.class, $L, $L, $L, $L, encodedConstructor, $L)" ,
400+ className , WEB3J , authName , CONTRACT_GAS_PROVIDER , BINARY , INITIAL_VALUE );
401+ } else if (!isPayable && !withGasProvider ) {
352402 methodBuilder .addStatement (
353403 "return deployRemoteCall($L.class, $L, $L, $L, $L, $L, encodedConstructor)" ,
354404 className , WEB3J , authName , GAS_PRICE , GAS_LIMIT , BINARY );
405+ methodBuilder .addAnnotation (Deprecated .class );
406+ } else {
407+ methodBuilder .addStatement (
408+ "return deployRemoteCall($L.class, $L, $L, $L, $L, encodedConstructor)" ,
409+ className , WEB3J , authName , CONTRACT_GAS_PROVIDER , BINARY );
355410 }
356411
357412 return methodBuilder .build ();
358413 }
359414
360415 private static MethodSpec buildDeployNoParams (
361416 MethodSpec .Builder methodBuilder , String className ,
362- String authName , boolean isPayable ) {
363- if (isPayable ) {
417+ String authName , boolean isPayable , boolean withGasPRovider ) {
418+ if (isPayable && ! withGasPRovider ) {
364419 methodBuilder .addStatement (
365420 "return deployRemoteCall($L.class, $L, $L, $L, $L, $L, \" \" , $L)" ,
366421 className , WEB3J , authName , GAS_PRICE , GAS_LIMIT , BINARY , INITIAL_VALUE );
367- } else {
422+ methodBuilder .addAnnotation (Deprecated .class );
423+ } else if (isPayable && withGasPRovider ) {
424+ methodBuilder .addStatement (
425+ "return deployRemoteCall($L.class, $L, $L, $L, $L, \" \" , $L)" ,
426+ className , WEB3J , authName , CONTRACT_GAS_PROVIDER , BINARY , INITIAL_VALUE );
427+ } else if (!isPayable && !withGasPRovider ) {
368428 methodBuilder .addStatement (
369429 "return deployRemoteCall($L.class, $L, $L, $L, $L, $L, \" \" )" ,
370430 className , WEB3J , authName , GAS_PRICE , GAS_LIMIT , BINARY );
431+ methodBuilder .addAnnotation (Deprecated .class );
432+ } else {
433+ methodBuilder .addStatement (
434+ "return deployRemoteCall($L.class, $L, $L, $L, $L, \" \" )" ,
435+ className , WEB3J , authName , CONTRACT_GAS_PROVIDER , BINARY );
371436 }
372437
373438 return methodBuilder .build ();
374439 }
375440
376441 private static MethodSpec .Builder getDeployMethodSpec (
377- String className , Class authType , String authName , boolean isPayable ) {
442+ String className , Class authType , String authName ,
443+ boolean isPayable , boolean withGasProvider ) {
378444 MethodSpec .Builder builder = MethodSpec .methodBuilder ("deploy" )
379445 .addModifiers (Modifier .PUBLIC , Modifier .STATIC )
380446 .returns (
381447 buildRemoteCall (TypeVariableName .get (className , Type .class )))
382448 .addParameter (Web3j .class , WEB3J )
383- .addParameter (authType , authName )
384- .addParameter (BigInteger .class , GAS_PRICE )
385- .addParameter (BigInteger .class , GAS_LIMIT );
386- if (isPayable ) {
387- return builder .addParameter (BigInteger .class , INITIAL_VALUE );
449+ .addParameter (authType , authName );
450+ if (isPayable && !withGasProvider ) {
451+ return builder .addParameter (BigInteger .class , GAS_PRICE )
452+ .addParameter (BigInteger .class , GAS_LIMIT )
453+ .addParameter (BigInteger .class , INITIAL_VALUE );
454+ } else if (isPayable && withGasProvider ) {
455+ return builder .addParameter (ContractGasProvider .class , CONTRACT_GAS_PROVIDER )
456+ .addParameter (BigInteger .class , INITIAL_VALUE );
457+ } else if (!isPayable && withGasProvider ) {
458+ return builder .addParameter (ContractGasProvider .class , CONTRACT_GAS_PROVIDER );
388459 } else {
389- return builder ;
460+ return builder .addParameter (BigInteger .class , GAS_PRICE )
461+ .addParameter (BigInteger .class , GAS_LIMIT );
390462 }
391463 }
392464
393465 private static MethodSpec buildLoad (
394- String className , Class authType , String authName ) {
395- return MethodSpec .methodBuilder ("load" )
466+ String className , Class authType , String authName , boolean withGasProvider ) {
467+ MethodSpec . Builder toReturn = MethodSpec .methodBuilder ("load" )
396468 .addModifiers (Modifier .PUBLIC , Modifier .STATIC )
397469 .returns (TypeVariableName .get (className , Type .class ))
398470 .addParameter (String .class , CONTRACT_ADDRESS )
399471 .addParameter (Web3j .class , WEB3J )
400- .addParameter (authType , authName )
401- .addParameter (BigInteger .class , GAS_PRICE )
402- .addParameter (BigInteger .class , GAS_LIMIT )
403- .addStatement ("return new $L($L, $L, $L, $L, $L)" , className ,
404- CONTRACT_ADDRESS , WEB3J , authName , GAS_PRICE , GAS_LIMIT )
405- .build ();
472+ .addParameter (authType , authName );
473+
474+ if (withGasProvider ) {
475+ toReturn .addParameter (ContractGasProvider .class , CONTRACT_GAS_PROVIDER )
476+ .addStatement ("return new $L($L, $L, $L, $L)" , className ,
477+ CONTRACT_ADDRESS , WEB3J , authName , CONTRACT_GAS_PROVIDER );
478+ } else {
479+ toReturn .addParameter (BigInteger .class , GAS_PRICE )
480+ .addParameter (BigInteger .class , GAS_LIMIT )
481+ .addStatement ("return new $L($L, $L, $L, $L, $L)" , className ,
482+ CONTRACT_ADDRESS , WEB3J , authName , GAS_PRICE , GAS_LIMIT )
483+ .addAnnotation (Deprecated .class );
484+ }
485+
486+ return toReturn .build ();
406487 }
407488
408489 String addParameters (
0 commit comments