Skip to content

Commit d83d495

Browse files
committed
fix bug for exception
1 parent 3a1187d commit d83d495

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.tron.core.exception;
2+
3+
public class InvalidAddress extends StoreException {
4+
5+
public InvalidAddress() {
6+
super();
7+
}
8+
9+
public InvalidAddress(String message) {
10+
super(message);
11+
}
12+
}

framework/src/main/java/org/tron/core/services/http/GetNowSRAnnualizedRateOfReturnServlet.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33

44
import static org.tron.core.config.Parameter.ChainConstant.MAX_ACTIVE_WITNESS_NUM;
55

6+
import com.alibaba.fastjson.JSONObject;
67
import javax.servlet.http.HttpServletRequest;
78
import javax.servlet.http.HttpServletResponse;
89
import lombok.extern.slf4j.Slf4j;
910
import org.springframework.beans.factory.annotation.Autowired;
1011
import org.springframework.stereotype.Component;
12+
import org.tron.common.utils.Commons;
13+
import org.tron.common.utils.DecodeUtil;
1114
import org.tron.core.Wallet;
1215
import org.tron.core.exception.AddressNotFound;
16+
import org.tron.core.exception.InvalidAddress;
1317
import org.tron.protos.Protocol.Account;
1418

1519
@Component
@@ -24,10 +28,14 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) {
2428
try {
2529
double annualizedRateOfReturn = 0;
2630
byte[] address = Util.getAddress(request);
31+
if (!DecodeUtil.addressValid(address)) {
32+
throw new InvalidAddress("Invalid address!");
33+
}
2734
long rewardOfVoteEachBlock = wallet.getRewardOfVoteEachBlock() / 1000000;
28-
long rewardOfBlockEachBlock = wallet.getRewardOfBlockEachBlock() / 1000000;
35+
long rewardOfBlockEachBlock = wallet.checkAddress(address)
36+
? wallet.getRewardOfBlockEachBlock() / 1000000 : 0;
2937
double srNumber = MAX_ACTIVE_WITNESS_NUM;
30-
double blockNumberEachDay = wallet.checkAddress(address) ? wallet.getBlockNumberEachDay() : 0;
38+
double blockNumberEachDay = wallet.getBlockNumberEachDay();
3139
double totalVote;
3240
double srVote;
3341
double ratio;
@@ -49,14 +57,19 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) {
4957
protected void doPost(HttpServletRequest request, HttpServletResponse response) {
5058
try {
5159
PostParams params = PostParams.getPostParams(request);
60+
String addressStr = JSONObject.parseObject(params.getParams()).getString("address");
61+
if (!DecodeUtil.addressValid(Commons.decodeFromBase58Check(addressStr))) {
62+
throw new InvalidAddress("Invalid address!");
63+
}
5264
Account.Builder build = Account.newBuilder();
5365
JsonFormat.merge(params.getParams(), build, params.isVisible());
5466
double annualizedRateOfReturn = 0;
5567
byte[] address = build.getAddress().toByteArray();
5668
long rewardOfVoteEachBlock = wallet.getRewardOfVoteEachBlock() / 1000000;
57-
long rewardOfBlockEachBlock = wallet.getRewardOfBlockEachBlock() / 1000000;
69+
long rewardOfBlockEachBlock = wallet.checkAddress(address)
70+
? wallet.getRewardOfBlockEachBlock() / 1000000 : 0;
5871
double srNumber = MAX_ACTIVE_WITNESS_NUM;
59-
double blockNumberEachDay = wallet.checkAddress(address) ? wallet.getBlockNumberEachDay() : 0;
72+
double blockNumberEachDay = wallet.getBlockNumberEachDay();
6073
double totalVote;
6174
double srVote;
6275
double ratio;

0 commit comments

Comments
 (0)