@@ -2141,28 +2141,70 @@ private void deployContract(String[] parameter)
21412141 }
21422142 }
21432143
2144- private void triggerContract (String [] parameters , boolean isConstant )
2145- throws IOException , CipherException , CancelException , EncodingException {
2146- String cmdMethodStr = isConstant ? "TriggerConstantContract" : "TriggerContract" ;
2147-
2148- if (isConstant ) {
2149- if (parameters == null || (parameters .length != 4 && parameters .length != 5 )) {
2150- System .out .println (cmdMethodStr + " needs 4 or 5 parameters like: " );
2151- System .out .println (cmdMethodStr + " [OwnerAddress] contractAddress method args isHex" );
2144+ private void deployConstantContract (String [] parameters )
2145+ throws IOException , CipherException , CancelException {
2146+
2147+ if (parameters == null || (parameters .length != 5 && parameters .length != 8 )) {
2148+ System .out .println ("DeployConstantContract needs at least 4 parameters like: " );
2149+ System .out .println ("DeployConstantContract ownerAddress(use # if you own)"
2150+ + " byteCode constructor params isHex [value token_value token_id]" );
2151+ return ;
2152+ }
2153+
2154+ int idx = 0 ;
2155+
2156+ String ownerAddressStr = parameters [idx ++];
2157+ byte [] ownerAddress = null ;
2158+ if (!"#" .equals (ownerAddressStr )) {
2159+ ownerAddress = WalletApi .decodeFromBase58Check (ownerAddressStr );
2160+ if (ownerAddress == null ) {
2161+ System .out .println ("Invalid Owner Address." );
21522162 return ;
21532163 }
2154- } else {
2155- if (parameters == null || (parameters .length != 8 && parameters .length != 9 )) {
2156- System .out .println (cmdMethodStr + " needs 8 or 9 parameters like: " );
2157- System .out .println (cmdMethodStr + " [OwnerAddress] contractAddress method args isHex"
2158- + " fee_limit value token_value token_id(e.g: TRXTOKEN, use # if don't provided)" );
2159- return ;
2164+ }
2165+
2166+ String codeStr = parameters [idx ++];
2167+ String constructorStr = parameters [idx ++];
2168+ String argsStr = parameters [idx ++];
2169+ boolean isHex = Boolean .parseBoolean (parameters [idx ++]);
2170+ long callValue = 0 ;
2171+ long tokenValue = 0 ;
2172+ String tokenId = "" ;
2173+ if (parameters .length == 8 ) {
2174+ callValue = Long .parseLong (parameters [idx ++]);
2175+ tokenValue = Long .parseLong (parameters [idx ++]);
2176+ tokenId = parameters [idx ];
2177+ }
2178+
2179+ if (!(constructorStr .equals ("#" ) || argsStr .equals ("#" ))) {
2180+ if (isHex ) {
2181+ codeStr += argsStr ;
2182+ } else {
2183+ codeStr += Hex .toHexString (AbiUtil .encodeInput (constructorStr , argsStr ));
21602184 }
21612185 }
21622186
2187+ if (tokenId .equalsIgnoreCase ("#" )) {
2188+ tokenId = "" ;
2189+ }
2190+
2191+ walletApiWrapper .callContract (
2192+ ownerAddress , null , callValue , Hex .decode (codeStr ), 0 , tokenValue , tokenId , true );
2193+ }
2194+
2195+ private void triggerContract (String [] parameters )
2196+ throws IOException , CipherException , CancelException {
2197+
2198+ if (parameters == null || (parameters .length != 8 && parameters .length != 9 )) {
2199+ System .out .println ("TriggerContract needs 8 or 9 parameters like: " );
2200+ System .out .println ("TriggerContract [OwnerAddress] contractAddress method args isHex"
2201+ + " fee_limit value token_value token_id(e.g: TRXTOKEN, use # if don't provided)" );
2202+ return ;
2203+ }
2204+
21632205 int index = 0 ;
21642206 byte [] ownerAddress = null ;
2165- if (parameters .length == 5 || parameters . length == 9 ) {
2207+ if (parameters .length == 9 ) {
21662208 ownerAddress = WalletApi .decodeFromBase58Check (parameters [index ++]);
21672209 if (ownerAddress == null ) {
21682210 System .out .println ("Invalid OwnerAddress." );
@@ -2173,42 +2215,92 @@ private void triggerContract(String[] parameters, boolean isConstant)
21732215 String contractAddrStr = parameters [index ++];
21742216 String methodStr = parameters [index ++];
21752217 String argsStr = parameters [index ++];
2176- boolean isHex = Boolean .valueOf (parameters [index ++]);
2177- long feeLimit = 0 ;
2178- long callValue = 0 ;
2179- long tokenCallValue = 0 ;
2180- String tokenId = "" ;
2218+ boolean isHex = Boolean .parseBoolean (parameters [index ++]);
2219+ long feeLimit = Long . parseLong ( parameters [ index ++]) ;
2220+ long callValue = Long . parseLong ( parameters [ index ++]) ;
2221+ long tokenValue = Long . parseLong ( parameters [ index ++]) ;
2222+ String tokenId = parameters [ index ] ;
21812223
2182- if (!isConstant ) {
2183- feeLimit = Long .valueOf (parameters [index ++]);
2184- callValue = Long .valueOf (parameters [index ++]);
2185- tokenCallValue = Long .valueOf (parameters [index ++]);
2186- tokenId = parameters [index ++];
2187- }
21882224 if (argsStr .equalsIgnoreCase ("#" )) {
21892225 argsStr = "" ;
21902226 }
2227+
21912228 if (tokenId .equalsIgnoreCase ("#" )) {
21922229 tokenId = "" ;
21932230 }
2231+
21942232 byte [] input = new byte [0 ];
21952233 if (!methodStr .equalsIgnoreCase ("#" )) {
21962234 input = Hex .decode (AbiUtil .parseMethod (methodStr , argsStr , isHex ));
21972235 }
21982236 byte [] contractAddress = WalletApi .decodeFromBase58Check (contractAddrStr );
21992237
2200- boolean result = walletApiWrapper
2201- .callContract (ownerAddress , contractAddress , callValue , input , feeLimit , tokenCallValue ,
2202- tokenId ,
2203- isConstant );
2204- if (!isConstant ) {
2205- if (result ) {
2206- System .out .println ("Broadcast the " + cmdMethodStr + " successful.\n "
2207- + "Please check the given transaction id to get the result on blockchain using getTransactionInfoById command" );
2208- } else {
2209- System .out .println ("Broadcast the " + cmdMethodStr + " failed" );
2238+ boolean result = walletApiWrapper .callContract (
2239+ ownerAddress , contractAddress , callValue , input , feeLimit , tokenValue , tokenId , false );
2240+ if (result ) {
2241+ System .out .println ("Broadcast the TriggerContract successful.\n "
2242+ + "Please check the given transaction id to get the result on blockchain using getTransactionInfoById command" );
2243+ } else {
2244+ System .out .println ("Broadcast the TriggerContract failed" );
2245+ }
2246+ }
2247+
2248+ private void triggerConstantContract (String [] parameters )
2249+ throws IOException , CipherException , CancelException {
2250+
2251+ if (parameters == null || (parameters .length != 5 && parameters .length != 8 )) {
2252+ System .out .println ("TriggerConstantContract needs 5 or 8 parameters like: " );
2253+ System .out .println ("TriggerConstantContract ownerAddress(use # if you own)"
2254+ + " contractAddress method args isHex [value token_value token_id(e.g: TRXTOKEN, use # if don't provided)]" );
2255+ return ;
2256+ }
2257+
2258+ int idx = 0 ;
2259+
2260+ String ownerAddressStr = parameters [idx ++];
2261+ byte [] ownerAddress = null ;
2262+ if (!"#" .equals (ownerAddressStr )) {
2263+ ownerAddress = WalletApi .decodeFromBase58Check (ownerAddressStr );
2264+ if (ownerAddress == null ) {
2265+ System .out .println ("Invalid Owner Address." );
2266+ return ;
22102267 }
22112268 }
2269+
2270+ String contractAddressStr = parameters [idx ++];
2271+ byte [] contractAddress = WalletApi .decodeFromBase58Check (contractAddressStr );
2272+ if (contractAddress == null ) {
2273+ System .out .println ("Invalid Contract Address." );
2274+ return ;
2275+ }
2276+
2277+ String methodStr = parameters [idx ++];
2278+ String argsStr = parameters [idx ++];
2279+ boolean isHex = Boolean .parseBoolean (parameters [idx ++]);
2280+ long callValue = 0 ;
2281+ long tokenValue = 0 ;
2282+ String tokenId = "" ;
2283+ if (parameters .length == 8 ) {
2284+ callValue = Long .parseLong (parameters [idx ++]);
2285+ tokenValue = Long .parseLong (parameters [idx ++]);
2286+ tokenId = parameters [idx ];
2287+ }
2288+
2289+ if (argsStr .equalsIgnoreCase ("#" )) {
2290+ argsStr = "" ;
2291+ }
2292+
2293+ if (tokenId .equalsIgnoreCase ("#" )) {
2294+ tokenId = "" ;
2295+ }
2296+
2297+ byte [] input = new byte [0 ];
2298+ if (!methodStr .equalsIgnoreCase ("#" )) {
2299+ input = Hex .decode (AbiUtil .parseMethod (methodStr , argsStr , isHex ));
2300+ }
2301+
2302+ walletApiWrapper .callContract (
2303+ ownerAddress , contractAddress , callValue , input , 0 , tokenValue , tokenId , true );
22122304 }
22132305
22142306 private void getContract (String [] parameters ) {
@@ -3692,6 +3784,7 @@ private void help() {
36923784
36933785 public static String [] getCmd (String cmdLine ) {
36943786 if (cmdLine .indexOf ("\" " ) < 0 || cmdLine .toLowerCase ().startsWith ("deploycontract" )
3787+ || cmdLine .toLowerCase ().startsWith ("deployconstantcontract" )
36953788 || cmdLine .toLowerCase ().startsWith ("triggercontract" )
36963789 || cmdLine .toLowerCase ().startsWith ("triggerconstantcontract" )
36973790 || cmdLine .toLowerCase ().startsWith ("updateaccountpermission" )) {
@@ -4078,12 +4171,16 @@ private void run() {
40784171 deployContract (parameters );
40794172 break ;
40804173 }
4174+ case "deployconstantcontract" : {
4175+ deployConstantContract (parameters );
4176+ break ;
4177+ }
40814178 case "triggercontract" : {
4082- triggerContract (parameters , false );
4179+ triggerContract (parameters );
40834180 break ;
40844181 }
40854182 case "triggerconstantcontract" : {
4086- triggerContract (parameters , true );
4183+ triggerConstantContract (parameters );
40874184 break ;
40884185 }
40894186 case "getcontract" : {
0 commit comments