Skip to content

Commit ac26768

Browse files
authored
Merge pull request #534 from chaosuper12321/release_v4.7.0
fix some parameter verification problems
2 parents c127563 + 8dd116f commit ac26768

File tree

2 files changed

+112
-40
lines changed

2 files changed

+112
-40
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ wallet> getDelegatedResourceAccountIndexV2 TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh
13851385
}
13861386
```
13871387

1388-
> getcandelegatedmaxsize [ownerAddress] type
1388+
> getcandelegatedmaxsize ownerAddress type
13891389
> get the max size that the ownerAddress can delegate use delegateResource
13901390
13911391
ownerAddress
@@ -1396,27 +1396,27 @@ type
13961396
13971397
Example:
13981398
```console
1399-
wallet> getCanDelegatedMaxSize 0
1399+
wallet> getCanDelegatedMaxSize TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh 0
14001400
{
14011401
"max_size": 999999978708334
14021402
}
14031403
```
14041404

1405-
> getavailableunfreezecount [ownerAddress]
1405+
> getavailableunfreezecount ownerAddress
14061406
> get the available unfreeze count that the ownerAddress can call unfreezeBalanceV2
14071407
14081408
ownerAddress
14091409
> The address of the account that initiated the transaction, optional, default is the address of the login account.
14101410
14111411
Example:
14121412
```console
1413-
wallet> getAvailableUnfreezeCount
1413+
wallet> getAvailableUnfreezeCount TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh
14141414
{
14151415
"count": 31
14161416
}
14171417
```
14181418

1419-
> getcanwithdrawunfreezeamount [ownerAddress] timestamp
1419+
> getcanwithdrawunfreezeamount ownerAddress timestamp
14201420
> get the withdraw unfreeze amount that the ownerAddress can get by withdrawexpireunfreeze
14211421
14221422
ownerAddress
@@ -1428,7 +1428,7 @@ timestamp
14281428

14291429
Example:
14301430
```console
1431-
wallet> getCanWithdrawUnfreezeAmount 1671100335000
1431+
wallet> getCanWithdrawUnfreezeAmount TJAVcszse667FmSNCwU2fm6DmfM5D4AyDh 1671100335000
14321432
{
14331433
"amount": 9000000
14341434
}

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

Lines changed: 106 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,9 +1444,12 @@ private void delegateResource(String[] parameters)
14441444
"delegateResource receiverAddress is invalid");
14451445
return;
14461446
}
1447-
lock = Boolean.parseBoolean(parameters[index++]);
1448-
}
14491447

1448+
if (parameters.length == 5 ||
1449+
(ownerAddress == null && parameters.length == 4)) {
1450+
lock = Boolean.parseBoolean(parameters[index++]);
1451+
}
1452+
}
14501453

14511454
boolean result = walletApiWrapper.delegateresource(
14521455
ownerAddress, balance, resourceCode, receiverAddress, lock);
@@ -1708,28 +1711,54 @@ private void getDelegatedResourceAccountIndexV2(String[] parameters) {
17081711
}
17091712
}
17101713

1714+
private void outputGetCanWithdrawUnfreezeAmountTip() {
1715+
System.out.println("Using getCanWithdrawUnfreezeAmount command needs 2 parameters like: ");
1716+
System.out.println("getcanwithdrawunfreezeamount ownerAddress timestamp");
1717+
}
1718+
17111719
private void getCanWithdrawUnfreezeAmount(String[] parameters) throws CipherException, IOException, CancelException {
17121720
if (parameters == null || !(parameters.length == 1 || parameters.length == 2)) {
1713-
System.out.println("Using getCanWithdrawUnfreezeAmount command needs 2 parameters like: ");
1714-
System.out.println("getcanwithdrawunfreezeamount [ownerAddress] timestamp");
1721+
this.outputGetCanWithdrawUnfreezeAmountTip();
17151722
return;
17161723
}
17171724
int index = 0;
17181725
long timestamp = 0;
1719-
byte[] ownerAddress = getAddressBytes(parameters[index]);
1720-
if (ownerAddress != null) {
1721-
index++;
1722-
if (parameters.length != 2) {
1723-
System.out.println("Using getCanWithdrawUnfreezeAmount command needs 2 parameters like: ");
1724-
System.out.println("getcanwithdrawunfreezeamount [ownerAddress] timestamp");
1726+
byte[] ownerAddress = null;
1727+
1728+
if (parameters.length == 1) {
1729+
try {
1730+
timestamp = Long.parseLong(parameters[index]);
1731+
if (timestamp < 0) {
1732+
System.out.println("Invalid param, timestamp >= 0");
1733+
return;
1734+
}
1735+
} catch (NumberFormatException nfe) {
1736+
this.outputGetCanWithdrawUnfreezeAmountTip();
17251737
return;
17261738
}
1727-
}
17281739

1729-
timestamp = Long.parseLong(parameters[index++]);
1730-
if (timestamp < 0) {
1731-
System.out.println("Invalid param, timestamp >= 0");
1732-
return;
1740+
ownerAddress = this.getLoginAddreess();
1741+
if (ownerAddress == null) {
1742+
System.out.println("getcanwithdrawunfreezeamount ownerAddress is invalid");
1743+
return ;
1744+
}
1745+
} else if (parameters.length == 2) {
1746+
ownerAddress = getAddressBytes(parameters[index++]);
1747+
if (ownerAddress == null) {
1748+
this.outputGetCanWithdrawUnfreezeAmountTip();
1749+
return;
1750+
}
1751+
1752+
try {
1753+
timestamp = Long.parseLong(parameters[index]);
1754+
if (timestamp < 0) {
1755+
System.out.println("Invalid param, timestamp >= 0");
1756+
return;
1757+
}
1758+
} catch (NumberFormatException nfe) {
1759+
this.outputGetCanWithdrawUnfreezeAmountTip();
1760+
return;
1761+
}
17331762
}
17341763

17351764
Optional<CanWithdrawUnfreezeAmountResponseMessage> result = WalletApi.getCanWithdrawUnfreezeAmount(
@@ -1742,29 +1771,55 @@ private void getCanWithdrawUnfreezeAmount(String[] parameters) throws CipherExce
17421771
}
17431772
}
17441773

1774+
1775+
private void outputGetCanDelegatedMaxSizeTip() {
1776+
System.out.println("Using getcandelegatedmaxsize command needs 2 parameters like: ");
1777+
System.out.println("getcandelegatedmaxsize ownerAddress type");
1778+
}
1779+
17451780
private void getCanDelegatedMaxSize(String[] parameters) throws CipherException, IOException, CancelException {
17461781
if (parameters == null || !(parameters.length == 1 || parameters.length == 2)) {
1747-
System.out.println("Using getcandelegatedmaxsize command needs 2 parameters like: ");
1748-
System.out.println("getcandelegatedmaxsize [ownerAddress] type");
1782+
this.outputGetCanDelegatedMaxSizeTip();
17491783
return;
17501784
}
17511785
int index = 0;
17521786
int type = 0;
1753-
byte[] ownerAddress = getAddressBytes(parameters[index]);
1754-
if (ownerAddress != null) {
1755-
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 ;
1787+
byte[] ownerAddress = null;
1788+
1789+
if (parameters.length == 1) {
1790+
try {
1791+
type = Integer.parseInt(parameters[index]);
1792+
if (ResourceCode.BANDWIDTH.ordinal() != type && ResourceCode.ENERGY.ordinal() != type) {
1793+
System.out.println("getcandelegatedmaxsize type must be: 0 or 1");
1794+
return;
1795+
}
1796+
} catch (NumberFormatException nfe) {
1797+
this.outputGetCanDelegatedMaxSizeTip();
1798+
return;
17601799
}
1761-
}
17621800

1763-
type = Integer.parseInt(parameters[index++]);
1801+
ownerAddress = this.getLoginAddreess();
1802+
if (ownerAddress == null) {
1803+
System.out.println("getcandelegatedmaxsize ownerAddress is invalid");
1804+
return ;
1805+
}
1806+
} else if (parameters.length == 2) {
1807+
ownerAddress = getAddressBytes(parameters[index++]);
1808+
if (ownerAddress == null) {
1809+
this.outputGetCanDelegatedMaxSizeTip();
1810+
return ;
1811+
}
17641812

1765-
if (ResourceCode.BANDWIDTH.ordinal() != type && ResourceCode.ENERGY.ordinal() != type) {
1766-
System.out.println("getcandelegatedmaxsize param type must be: 0 or 1");
1767-
return;
1813+
try {
1814+
type = Integer.parseInt(parameters[index]);
1815+
if (ResourceCode.BANDWIDTH.ordinal() != type && ResourceCode.ENERGY.ordinal() != type) {
1816+
System.out.println("getcandelegatedmaxsize type must be: 0 or 1");
1817+
return;
1818+
}
1819+
} catch (NumberFormatException nfe) {
1820+
this.outputGetCanDelegatedMaxSizeTip();
1821+
return;
1822+
}
17681823
}
17691824

17701825
Optional<CanDelegatedMaxSizeResponseMessage> result = WalletApi.getCanDelegatedMaxSize(ownerAddress, type);
@@ -1776,21 +1831,30 @@ private void getCanDelegatedMaxSize(String[] parameters) throws CipherException,
17761831
}
17771832
}
17781833

1834+
private void outputGetAvailableUnfreezeCountTip() {
1835+
System.out.println("Using getavailableunfreezecount command needs 1 parameters like: ");
1836+
System.out.println("getavailableunfreezecount owner_address ");
1837+
}
1838+
17791839
private void getAvailableUnfreezeCount(String[] parameters) throws CipherException, IOException, CancelException {
17801840
if (parameters == null || !(parameters.length == 0 || parameters.length == 1)) {
1781-
System.out.println("Using getavailableunfreezecount command needs 1 parameters like: ");
1782-
System.out.println("getavailableunfreezecount [owner_address] ");
1841+
this.outputGetAvailableUnfreezeCountTip();
17831842
return;
17841843
}
17851844
int index = 0;
17861845
byte[] ownerAddress = null;
17871846
if (parameters.length == 1) {
17881847
ownerAddress = getAddressBytes(parameters[index]);
17891848
if (ownerAddress == null) {
1790-
System.out.println("Using getavailableunfreezecount command needs 1 parameters like: ");
1791-
System.out.println("getavailableunfreezecount [owner_address] ");
1792-
return ;
1849+
this.outputGetAvailableUnfreezeCountTip();
1850+
return;
17931851
}
1852+
} else {
1853+
ownerAddress = this.getLoginAddreess();
1854+
if (ownerAddress == null) {
1855+
this.outputGetAvailableUnfreezeCountTip();
1856+
return;
1857+
}
17941858
}
17951859

17961860
Optional<GetAvailableUnfreezeCountResponseMessage> result = WalletApi.getAvailableUnfreezeCount(ownerAddress);
@@ -4818,6 +4882,14 @@ private void getChainParameters() {
48184882
}
48194883
}
48204884

4885+
private byte[] getLoginAddreess() {
4886+
if (walletApiWrapper.isLoginState()) {
4887+
String ownerAddressStr = walletApiWrapper.getAddress();
4888+
return WalletApi.decodeFromBase58Check(ownerAddressStr);
4889+
}
4890+
return null;
4891+
}
4892+
48214893
private void getBlockByIdOrNum(String[] parameters) {
48224894
String idOrNum = null;
48234895
boolean detail = false;

0 commit comments

Comments
 (0)