Skip to content

Commit c127563

Browse files
authored
Merge pull request #533 from chaosuper12321/release_v4.7.0
add some param check
2 parents 1263ccc + 5b9eaf8 commit c127563

File tree

4 files changed

+57
-63
lines changed

4 files changed

+57
-63
lines changed

src/main/java/org/tron/common/utils/HttpSelfFormatFieldName.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ public class HttpSelfFormatFieldName {
115115
AddressFieldNameMap.put("protocol.ShieldedTransferContract.transparent_from_address", 1);
116116
AddressFieldNameMap.put("protocol.ShieldedTransferContract.transparent_to_address", 1);
117117

118+
//FreezeBalanceV2Contract
119+
AddressFieldNameMap.put("protocol.FreezeBalanceV2Contract.owner_address", 1);
120+
//UnfreezeBalanceV2Contract
121+
AddressFieldNameMap.put("protocol.UnfreezeBalanceV2Contract.owner_address", 1);
122+
//WithdrawExpireUnfreezeContract
123+
AddressFieldNameMap.put("protocol.WithdrawExpireUnfreezeContract.owner_address", 1);
124+
//DelegateResourceContract
125+
AddressFieldNameMap.put("protocol.DelegateResourceContract.owner_address", 1);
126+
AddressFieldNameMap.put("protocol.DelegateResourceContract.receiver_address", 1);
127+
//UnDelegateResourceContract
128+
AddressFieldNameMap.put("protocol.UnDelegateResourceContract.owner_address", 1);
129+
AddressFieldNameMap.put("protocol.UnDelegateResourceContract.receiver_address", 1);
130+
AddressFieldNameMap.put("protocol.CanDelegatedMaxSizeRequestMessage.owner_address", 1);
131+
AddressFieldNameMap.put("protocol.GetAvailableUnfreezeCountRequestMessage.owner_address", 1);
132+
AddressFieldNameMap.put("protocol.CanWithdrawUnfreezeAmountRequestMessage.owner_address", 1);
133+
118134
//***** Tron.proto *****
119135
//AccountId
120136
AddressFieldNameMap.put("protocol.AccountId.address", 1);

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

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public class Client {
9090
"CreateAccount",
9191
"CreateProposal",
9292
"CreateWitness",
93+
"DelegateResource",
9394
"DeleteProposal",
9495
"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)>",
9596
"ExchangeCreate",
@@ -198,6 +199,7 @@ public class Client {
198199
"TransferAsset",
199200
"TriggerConstantContract contractAddress method args isHex",
200201
"TriggerContract contractAddress method args isHex fee_limit value",
202+
"UnDelegateResource",
201203
"UnfreezeAsset",
202204
"UnfreezeBalance",
203205
"UnfreezeBalanceV2",
@@ -211,8 +213,6 @@ public class Client {
211213
"VoteWitness",
212214
"WithdrawBalance",
213215
"WithdrawExpireUnfreeze",
214-
"DelegateResource",
215-
"UnDelegateResource",
216216
};
217217

218218
// note: this is sorted by alpha
@@ -231,13 +231,15 @@ public class Client {
231231
"CreateAccount",
232232
"CreateProposal",
233233
"CreateWitness",
234+
"DelegateResource",
234235
"DeleteProposal",
235236
"DeployContract",
236237
"ExchangeCreate",
237238
"ExchangeInject",
238239
"ExchangeTransaction",
239240
"ExchangeWithdraw",
240241
"FreezeBalance",
242+
"FreezeBalanceV2",
241243
"GenerateAddress",
242244
// "GenerateShieldedAddress",
243245
"GenerateShieldedTRC20Address",
@@ -338,8 +340,10 @@ public class Client {
338340
"TransferAsset",
339341
"TriggerConstantContract",
340342
"TriggerContract",
343+
"UnDelegateResource",
341344
"UnfreezeAsset",
342345
"UnfreezeBalance",
346+
"UnfreezeBalanceV2",
343347
"UpdateAccount",
344348
"UpdateAccountPermission",
345349
"UpdateAsset",
@@ -349,6 +353,7 @@ public class Client {
349353
"UpdateWitness",
350354
"VoteWitness",
351355
"WithdrawBalance",
356+
"WithdrawExpireUnfreeze",
352357
};
353358

354359
private byte[] inputPrivateKey() throws IOException {
@@ -1427,24 +1432,19 @@ private void delegateResource(String[] parameters)
14271432
return;
14281433
}
14291434
} else if (parameters.length == 4 || parameters.length == 5) {
1430-
ownerAddress = getAddressBytes(parameters[index++]);
1435+
ownerAddress = getAddressBytes(parameters[index]);
14311436
if (ownerAddress != null) {
1432-
balance = Long.parseLong(parameters[index++]);
1433-
resourceCode = Integer.parseInt(parameters[index++]);
1434-
receiverAddress = getAddressBytes(parameters[index++]);
1435-
if (receiverAddress == null) {
1436-
System.out.println(
1437-
"delegateResource receiverAddress is invalid");
1438-
return;
1439-
}
1440-
if (parameters.length == 5) {
1441-
lock = Boolean.parseBoolean(parameters[index++]);
1442-
}
1443-
} if (ownerAddress == null) {
1437+
index ++;
1438+
}
1439+
balance = Long.parseLong(parameters[index++]);
1440+
resourceCode = Integer.parseInt(parameters[index++]);
1441+
receiverAddress = getAddressBytes(parameters[index++]);
1442+
if (receiverAddress == null) {
14441443
System.out.println(
1445-
"delegateResource ownerAddress is invalid");
1444+
"delegateResource receiverAddress is invalid");
14461445
return;
14471446
}
1447+
lock = Boolean.parseBoolean(parameters[index++]);
14481448
}
14491449

14501450

@@ -1719,15 +1719,21 @@ private void getCanWithdrawUnfreezeAmount(String[] parameters) throws CipherExce
17191719
byte[] ownerAddress = getAddressBytes(parameters[index]);
17201720
if (ownerAddress != null) {
17211721
index++;
1722+
if (parameters.length != 2) {
1723+
System.out.println("Using getCanWithdrawUnfreezeAmount command needs 2 parameters like: ");
1724+
System.out.println("getcanwithdrawunfreezeamount [ownerAddress] timestamp");
1725+
return;
1726+
}
17221727
}
1728+
17231729
timestamp = Long.parseLong(parameters[index++]);
17241730
if (timestamp < 0) {
17251731
System.out.println("Invalid param, timestamp >= 0");
17261732
return;
17271733
}
17281734

1729-
Optional<CanWithdrawUnfreezeAmountResponseMessage> result = walletApiWrapper.
1730-
getCanWithdrawUnfreezeAmount(ownerAddress, timestamp);
1735+
Optional<CanWithdrawUnfreezeAmountResponseMessage> result = WalletApi.getCanWithdrawUnfreezeAmount(
1736+
ownerAddress, timestamp);
17311737
if (result.isPresent()) {
17321738
CanWithdrawUnfreezeAmountResponseMessage canWithdrawUnfreezeAmountResponseMessage = result.get();
17331739
System.out.println(Utils.formatMessageString(canWithdrawUnfreezeAmountResponseMessage));
@@ -1747,14 +1753,21 @@ private void getCanDelegatedMaxSize(String[] parameters) throws CipherException,
17471753
byte[] ownerAddress = getAddressBytes(parameters[index]);
17481754
if (ownerAddress != null) {
17491755
index++;
1756+
if (parameters.length < 2) {
1757+
System.out.println("Using getcandelegatedmaxsize command needs 2 parameters like: ");
1758+
System.out.println("getcandelegatedmaxsize [ownerAddress] type");
1759+
return ;
1760+
}
17501761
}
1762+
17511763
type = Integer.parseInt(parameters[index++]);
1764+
17521765
if (ResourceCode.BANDWIDTH.ordinal() != type && ResourceCode.ENERGY.ordinal() != type) {
17531766
System.out.println("getcandelegatedmaxsize param type must be: 0 or 1");
17541767
return;
17551768
}
17561769

1757-
Optional<CanDelegatedMaxSizeResponseMessage> result = walletApiWrapper.getCanDelegatedMaxSize(ownerAddress, type);
1770+
Optional<CanDelegatedMaxSizeResponseMessage> result = WalletApi.getCanDelegatedMaxSize(ownerAddress, type);
17581771
if (result.isPresent()) {
17591772
CanDelegatedMaxSizeResponseMessage canDelegatedMaxSizeResponseMessage = result.get();
17601773
System.out.println(Utils.formatMessageString(canDelegatedMaxSizeResponseMessage));
@@ -1773,9 +1786,14 @@ private void getAvailableUnfreezeCount(String[] parameters) throws CipherExcepti
17731786
byte[] ownerAddress = null;
17741787
if (parameters.length == 1) {
17751788
ownerAddress = getAddressBytes(parameters[index]);
1789+
if (ownerAddress == null) {
1790+
System.out.println("Using getavailableunfreezecount command needs 1 parameters like: ");
1791+
System.out.println("getavailableunfreezecount [owner_address] ");
1792+
return ;
1793+
}
17761794
}
17771795

1778-
Optional<GetAvailableUnfreezeCountResponseMessage> result = walletApiWrapper.getAvailableUnfreezeCount(ownerAddress);
1796+
Optional<GetAvailableUnfreezeCountResponseMessage> result = WalletApi.getAvailableUnfreezeCount(ownerAddress);
17791797
if (result.isPresent()) {
17801798
GetAvailableUnfreezeCountResponseMessage getAvailableUnfreezeCountResponseMessage = result.get();
17811799
System.out.println(Utils.formatMessageString(getAvailableUnfreezeCountResponseMessage));

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

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -577,37 +577,6 @@ public boolean undelegateresource(byte[] ownerAddress, long balance
577577

578578
return wallet.unDelegateResource(ownerAddress, balance, resourceCode, receiverAddress);
579579
}
580-
581-
public Optional<GrpcAPI.CanWithdrawUnfreezeAmountResponseMessage> getCanWithdrawUnfreezeAmount(
582-
byte[] ownerAddress, long timestamp)
583-
throws CipherException, IOException, CancelException {
584-
if (wallet == null || !wallet.isLoginState()) {
585-
System.out.println("Warning: getCanWithdrawUnfreezeAmount failed, Please login first !!");
586-
return Optional.empty();
587-
}
588-
589-
return wallet.getCanWithdrawUnfreezeAmount(ownerAddress, timestamp);
590-
}
591-
592-
public Optional<GrpcAPI.CanDelegatedMaxSizeResponseMessage> getCanDelegatedMaxSize(byte[] ownerAddress, int type)
593-
throws CipherException, IOException, CancelException {
594-
if (wallet == null || !wallet.isLoginState()) {
595-
System.out.println("Warning: getCanDelegatedMaxSize failed, Please login first !!");
596-
return Optional.empty();
597-
}
598-
599-
return wallet.getCanDelegatedMaxSize(ownerAddress, type);
600-
}
601-
602-
public Optional<GrpcAPI.GetAvailableUnfreezeCountResponseMessage> getAvailableUnfreezeCount(byte[] ownerAddress)
603-
throws CipherException, IOException, CancelException {
604-
if (wallet == null || !wallet.isLoginState()) {
605-
System.out.println("Warning: getAvailableUnfreezeCount failed, Please login first !!");
606-
return Optional.empty();
607-
}
608-
609-
return wallet.getAvailableUnfreezeCount(ownerAddress);
610-
}
611580

612581
public boolean unfreezeAsset(byte[] ownerAddress)
613582
throws CipherException, IOException, CancelException {

src/main/java/org/tron/walletserver/WalletApi.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,27 +1657,18 @@ public static Optional<Protocol.DelegatedResourceAccountIndex> getDelegatedResou
16571657
return rpcCli.getDelegatedResourceAccountIndexV2(ownerAddress);
16581658
}
16591659

1660-
public Optional<GrpcAPI.CanWithdrawUnfreezeAmountResponseMessage> getCanWithdrawUnfreezeAmount(
1660+
public static Optional<GrpcAPI.CanWithdrawUnfreezeAmountResponseMessage> getCanWithdrawUnfreezeAmount(
16611661
byte[] ownerAddress, long timestamp) {
1662-
if (ownerAddress == null) {
1663-
ownerAddress = this.getAddress();
1664-
}
16651662
return rpcCli.getCanWithdrawUnfreezeAmount(ownerAddress, timestamp);
16661663
}
16671664

1668-
public Optional<GrpcAPI.CanDelegatedMaxSizeResponseMessage> getCanDelegatedMaxSize(
1665+
public static Optional<GrpcAPI.CanDelegatedMaxSizeResponseMessage> getCanDelegatedMaxSize(
16691666
byte[] ownerAddress, int type) {
1670-
if (ownerAddress == null) {
1671-
ownerAddress = this.getAddress();
1672-
}
16731667
return rpcCli.getCanDelegatedMaxSize(ownerAddress, type);
16741668
}
16751669

1676-
public Optional<GrpcAPI.GetAvailableUnfreezeCountResponseMessage> getAvailableUnfreezeCount(
1670+
public static Optional<GrpcAPI.GetAvailableUnfreezeCountResponseMessage> getAvailableUnfreezeCount(
16771671
byte[] ownerAddress) {
1678-
if (ownerAddress == null) {
1679-
ownerAddress = this.getAddress();
1680-
}
16811672
return rpcCli.getAvailableUnfreezeCount(ownerAddress);
16821673
}
16831674

0 commit comments

Comments
 (0)