@@ -93,6 +93,7 @@ public class Client {
9393 "DelegateResource" ,
9494 "DeleteProposal" ,
9595 "DeployContract contractName ABI byteCode constructor params isHex fee_limit consume_user_resource_percent origin_energy_limit value token_value token_id <library:address,library:address,...> <lib_compiler_version(e.g:v5)>" ,
96+ "EstimateEnergy" ,
9697 "ExchangeCreate" ,
9798 "ExchangeInject" ,
9899 "ExchangeTransaction" ,
@@ -234,6 +235,7 @@ public class Client {
234235 "DelegateResource" ,
235236 "DeleteProposal" ,
236237 "DeployContract" ,
238+ "EstimateEnergy" ,
237239 "ExchangeCreate" ,
238240 "ExchangeInject" ,
239241 "ExchangeTransaction" ,
@@ -2734,6 +2736,65 @@ private void triggerConstantContract(String[] parameters)
27342736 ownerAddress , contractAddress , callValue , input , 0 , tokenValue , tokenId , true );
27352737 }
27362738
2739+ private void estimateEnergy (String [] parameters )
2740+ throws IOException , CipherException , CancelException {
2741+
2742+ if (parameters == null || (parameters .length != 5 && parameters .length != 8 )) {
2743+ System .out .println ("EstimateEnergy needs 5 or 8 parameters like: " );
2744+ System .out .println ("EstimateEnergy ownerAddress(use # if you own)"
2745+ + " contractAddress method args isHex "
2746+ + "[value token_value token_id(e.g: TRXTOKEN, use # if don't provided)]" );
2747+ return ;
2748+ }
2749+
2750+ int idx = 0 ;
2751+
2752+ String ownerAddressStr = parameters [idx ++];
2753+ byte [] ownerAddress = null ;
2754+ if (!"#" .equals (ownerAddressStr )) {
2755+ ownerAddress = WalletApi .decodeFromBase58Check (ownerAddressStr );
2756+ if (ownerAddress == null ) {
2757+ System .out .println ("Invalid Owner Address." );
2758+ return ;
2759+ }
2760+ }
2761+
2762+ String contractAddressStr = parameters [idx ++];
2763+ byte [] contractAddress = WalletApi .decodeFromBase58Check (contractAddressStr );
2764+ if (contractAddress == null ) {
2765+ System .out .println ("Invalid Contract Address." );
2766+ return ;
2767+ }
2768+
2769+ String methodStr = parameters [idx ++];
2770+ String argsStr = parameters [idx ++];
2771+ boolean isHex = Boolean .parseBoolean (parameters [idx ++]);
2772+ long callValue = 0 ;
2773+ long tokenValue = 0 ;
2774+ String tokenId = "" ;
2775+ if (parameters .length == 8 ) {
2776+ callValue = Long .parseLong (parameters [idx ++]);
2777+ tokenValue = Long .parseLong (parameters [idx ++]);
2778+ tokenId = parameters [idx ];
2779+ }
2780+
2781+ if (argsStr .equalsIgnoreCase ("#" )) {
2782+ argsStr = "" ;
2783+ }
2784+
2785+ if (tokenId .equalsIgnoreCase ("#" )) {
2786+ tokenId = "" ;
2787+ }
2788+
2789+ byte [] input = new byte [0 ];
2790+ if (!methodStr .equalsIgnoreCase ("#" )) {
2791+ input = Hex .decode (AbiUtil .parseMethod (methodStr , argsStr , isHex ));
2792+ }
2793+
2794+ walletApiWrapper .estimateEnergy (
2795+ ownerAddress , contractAddress , callValue , input , tokenValue , tokenId );
2796+ }
2797+
27372798 private void getContract (String [] parameters ) {
27382799 if (parameters == null ||
27392800 parameters .length != 1 ) {
@@ -4658,6 +4719,10 @@ private void run() {
46584719 triggerConstantContract (parameters );
46594720 break ;
46604721 }
4722+ case "estimateenergy" : {
4723+ estimateEnergy (parameters );
4724+ break ;
4725+ }
46614726 case "getcontract" : {
46624727 getContract (parameters );
46634728 break ;
0 commit comments