Skip to content

Commit ad0aca6

Browse files
authored
Merge pull request #637 from tronprotocol/feature/deprecated_api_v4.7.1.1
feat(api): generateAddress use local method
2 parents d41443f + bd7c856 commit ad0aca6

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ For more information on a specific command, just type the command on terminal wh
7070
| [BroadcastTransaction](#Some-others) | [ChangePassword](#Wallet-related-commands)| [CreateProposal](#How-to-initiate-a-proposal)
7171
| [DeleteProposal](#Cancel-the-created-proposal) | [DeployContract](#How-to-use-smart-contract) | [ExchangeCreate](#How-to-trade-on-the-exchange) |
7272
| [ExchangeInject](#How-to-trade-on-the-exchange) | [ExchangeTransaction](#How-to-trade-on-the-exchange) | [ExchangeWithdraw](#How-to-trade-on-the-exchange) |
73-
| [FreezeBalance](#How-to-delegate-resourcee) |[GetCanWithdrawUnfreezeAmount](#How-to-freezev2)| [GenerateShieldedTRC20Address](#How-to-transfer-shielded-TRC20-token)|
73+
| [FreezeBalance](#How-to-delegate-resourcee) | [GenerateAddress](#Account-related-commands) | [GenerateShieldedTRC20Address](#How-to-transfer-shielded-TRC20-token)|
7474
| [GetAccount](#Account-related-commands) |[GetAccountNet](#Account-related-commands) | [GetAccountResource](#Account-related-commands) |
7575
| [GetAddress](#Account-related-commands) | [GetAkFromAsk](#How-to-transfer-shielded-TRC20-token) |[GetAssetIssueByAccount](#How-to-issue-TRC10-tokens) |
7676
| [GetAssetIssueById](#How-to-issue-TRC10-tokens) | [GetAssetIssueByName](#How-to-issue-TRC10-tokens) |[GetAssetIssueListByName](#How-to-issue-TRC10-tokens) |
7777
| [GetBalance](#Account-related-commands) | [GetBlock](#How-to-get-block-information) |[GetBlockById](#How-to-get-block-information) |
7878
| [GetBlockByLatestNum](#How-to-get-block-information) | [GetBlockByLimitNext](#How-to-get-block-information) | [GetBrokerage](#Brokerage) |
7979
| [GetContract](#How-to-use-smart-contracts) | [GetDelegatedResource](#How-to-delegate-resource) |[GetDelegatedResourceAccountIndex](#How-to-delegate-resource) |
80-
| [GetDiversifier](#How-to-transfer-shielded-TRC20-token)| [GetExpandedSpendingKey](#How-to-transfer-shielded-TRC20-token)| [GetIncomingViewingKey](#How-to-transfer-shielded-TRC20-token) |
81-
| [GetMarketOrderByAccount](#How-to-use-tron-dex-to-sell-asset)| [GetMarketOrderById](#How-to-use-tron-dex-to-sell-asset)| [GetMarketOrderListByPair](#How-to-use-tron-dex-to-sell-asset) |
80+
| [GetDiversifier](#How-to-transfer-shielded-TRC20-token)| [GetExpandedSpendingKey](#How-to-transfer-shielded-TRC20-token)| [GetIncomingViewingKey](#How-to-transfer-shielded-TRC20-token) |
81+
| [GetMarketOrderByAccount](#How-to-use-tron-dex-to-sell-asset)| [GetMarketOrderById](#How-to-use-tron-dex-to-sell-asset)| [GetMarketOrderListByPair](#How-to-use-tron-dex-to-sell-asset) |
8282
| [GetMarketPairList](#How-to-use-tron-dex-to-sell-asset)| [GetMarketPriceByPair](#How-to-use-tron-dex-to-sell-asset)| [GetNextMaintenanceTime](#Some-others) |
8383
| [GetNkFromNsk](#How-to-transfer-shielded-TRC20-token) | [GetProposal](#Get-proposal-information) | [GetShieldedPaymentAddress](#How-to-transfer-shielded-TRC20-token)|
8484
| [GetSpendingKey](#How-to-transfer-shielded-TRC20-token) | [GetReward](#Brokerage) | [GetTransactionApprovedList](#How-to-use-the-multi-signature-feature-of-wallet-cli) |
@@ -98,7 +98,7 @@ For more information on a specific command, just type the command on terminal wh
9898
| [UpdateAccountPermission](#How-to-use-the-multi-signature-feature-of-wallet-cli) | [VoteWitness](#How-to-vote) | [FreezeBalanceV2](#How-to-freezev2) |
9999
| [UnfreezeBalanceV2](#How-to-freezev2) | [DelegateResource](#How-to-freezev2) | [UnDelegateResource](#How-to-freezev2) |
100100
| [WithdrawExpireUnfreeze](#How-to-freezev2) | [GetDelegatedResourceV2](#How-to-freezev2) | [GetDelegatedResourceAccountIndexV2](#How-to-freezev2) |
101-
| [GetCanDelegatedMaxSize](#How-to-freezev2) | [GetAvailableUnfreezeCount](#How-to-freezev2) | |
101+
| [GetCanDelegatedMaxSize](#How-to-freezev2) | [GetAvailableUnfreezeCount](#How-to-freezev2) | [GetCanWithdrawUnfreezeAmount](#How-to-freezev2) |
102102

103103
Type any one of the listed commands, to display how-to tips.
104104

@@ -1458,6 +1458,9 @@ as: 721d63b074f18d41c147e04c952ec93467777a30b6f16745bc47a8eae5076545
14581458
14591459
## Account related commands
14601460

1461+
**GenerateAddress**
1462+
> Generate an address and print out the public and private keys
1463+
14611464
**GetAccount**
14621465
> Get account information based on address
14631466

src/main/java/org/tron/walletcli/Client.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
import org.jline.terminal.TerminalBuilder;
2727
import org.tron.api.GrpcAPI.*;
2828
import org.tron.common.crypto.Hash;
29+
import org.tron.common.crypto.SignInterface;
30+
import org.tron.common.crypto.SignUtils;
2931
import org.tron.common.utils.AbiUtil;
32+
import org.tron.common.utils.Base58;
3033
import org.tron.common.utils.ByteArray;
3134
import org.tron.common.utils.ByteUtil;
3235
import org.tron.common.utils.Utils;
@@ -100,6 +103,7 @@ public class Client {
100103
"ExchangeWithdraw",
101104
"FreezeBalance",
102105
"FreezeBalanceV2",
106+
"GenerateAddress",
103107
// "GenerateShieldedAddress",
104108
"GenerateShieldedTRC20Address",
105109
"GetAccount",
@@ -241,6 +245,7 @@ public class Client {
241245
"ExchangeWithdraw",
242246
"FreezeBalance",
243247
"FreezeBalanceV2",
248+
"GenerateAddress",
244249
// "GenerateShieldedAddress",
245250
"GenerateShieldedTRC20Address",
246251
"GetAccount",
@@ -2837,6 +2842,24 @@ private void getContractInfo(String[] parameters) {
28372842
}
28382843
}
28392844

2845+
private void generateAddress(String[] parameters) {
2846+
try {
2847+
boolean isECKey = parameters == null || parameters.length == 0
2848+
|| Boolean.parseBoolean(parameters[0]);
2849+
SignInterface cryptoEngine = SignUtils.getGeneratedRandomSign(Utils.getRandom(), isECKey);
2850+
byte[] priKey = cryptoEngine.getPrivateKey();
2851+
byte[] address = cryptoEngine.getAddress();
2852+
String addressStr = Base58.encode(address);
2853+
String priKeyStr = ByteArray.toHexString(priKey);
2854+
AddressPrKeyPairMessage.Builder builder = AddressPrKeyPairMessage.newBuilder();
2855+
builder.setAddress(addressStr);
2856+
builder.setPrivateKey(priKeyStr);
2857+
System.out.println(Utils.formatMessageString(builder.build()));
2858+
} catch (Exception e) {
2859+
System.out.println("GenerateAddress failed !!!");
2860+
}
2861+
}
2862+
28402863
private void updateAccountPermission(String[] parameters)
28412864
throws CipherException, IOException, CancelException {
28422865
if (parameters == null || parameters.length != 2) {
@@ -4721,6 +4744,10 @@ private void run() {
47214744
getContractInfo(parameters);
47224745
break;
47234746
}
4747+
case "generateaddress": {
4748+
generateAddress(parameters);
4749+
break;
4750+
}
47244751
case "updateaccountpermission": {
47254752
updateAccountPermission(parameters);
47264753
break;

src/main/protos/api/api.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,11 @@ message PaginatedMessage {
11911191
int64 offset = 1;
11921192
int64 limit = 2;
11931193
}
1194+
// for only wallet-cli, do not delete
1195+
message AddressPrKeyPairMessage {
1196+
string address = 1;
1197+
string privateKey = 2;
1198+
}
11941199

11951200
message TransactionExtention {
11961201
Transaction transaction = 1;

0 commit comments

Comments
 (0)