|
25 | 25 | import org.jline.terminal.TerminalBuilder; |
26 | 26 | import org.tron.api.GrpcAPI.*; |
27 | 27 | import org.tron.common.crypto.Hash; |
| 28 | +import org.tron.common.crypto.SignInterface; |
| 29 | +import org.tron.common.crypto.SignUtils; |
28 | 30 | import org.tron.common.utils.AbiUtil; |
| 31 | +import org.tron.common.utils.Base58; |
29 | 32 | import org.tron.common.utils.ByteArray; |
30 | 33 | import org.tron.common.utils.ByteUtil; |
31 | 34 | import org.tron.common.utils.Utils; |
@@ -99,6 +102,7 @@ public class Client { |
99 | 102 | "ExchangeWithdraw", |
100 | 103 | "FreezeBalance", |
101 | 104 | "FreezeBalanceV2", |
| 105 | + "GenerateAddress", |
102 | 106 | // "GenerateShieldedAddress", |
103 | 107 | "GenerateShieldedTRC20Address", |
104 | 108 | "GetAccount", |
@@ -241,6 +245,7 @@ public class Client { |
241 | 245 | "ExchangeWithdraw", |
242 | 246 | "FreezeBalance", |
243 | 247 | "FreezeBalanceV2", |
| 248 | + "GenerateAddress", |
244 | 249 | // "GenerateShieldedAddress", |
245 | 250 | "GenerateShieldedTRC20Address", |
246 | 251 | "GetAccount", |
@@ -2857,6 +2862,24 @@ private void getContractInfo(String[] parameters) { |
2857 | 2862 | } |
2858 | 2863 | } |
2859 | 2864 |
|
| 2865 | + private void generateAddress(String[] parameters) { |
| 2866 | + try { |
| 2867 | + boolean isECKey = parameters == null || parameters.length == 0 |
| 2868 | + || Boolean.parseBoolean(parameters[0]); |
| 2869 | + SignInterface cryptoEngine = SignUtils.getGeneratedRandomSign(Utils.getRandom(), isECKey); |
| 2870 | + byte[] priKey = cryptoEngine.getPrivateKey(); |
| 2871 | + byte[] address = cryptoEngine.getAddress(); |
| 2872 | + String addressStr = WalletApi.encode58Check(address); |
| 2873 | + String priKeyStr = ByteArray.toHexString(priKey); |
| 2874 | + AddressPrKeyPairMessage.Builder builder = AddressPrKeyPairMessage.newBuilder(); |
| 2875 | + builder.setAddress(addressStr); |
| 2876 | + builder.setPrivateKey(priKeyStr); |
| 2877 | + System.out.println(Utils.formatMessageString(builder.build())); |
| 2878 | + } catch (Exception e) { |
| 2879 | + System.out.println("GenerateAddress failed !!!"); |
| 2880 | + } |
| 2881 | + } |
| 2882 | + |
2860 | 2883 | private void updateAccountPermission(String[] parameters) |
2861 | 2884 | throws CipherException, IOException, CancelException { |
2862 | 2885 | if (parameters == null || parameters.length != 2) { |
@@ -4745,6 +4768,10 @@ private void run() { |
4745 | 4768 | getContractInfo(parameters); |
4746 | 4769 | break; |
4747 | 4770 | } |
| 4771 | + case "generateaddress": { |
| 4772 | + generateAddress(parameters); |
| 4773 | + break; |
| 4774 | + } |
4748 | 4775 | case "updateaccountpermission": { |
4749 | 4776 | updateAccountPermission(parameters); |
4750 | 4777 | break; |
|
0 commit comments