Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check if null before getInstance #3165

Merged
merged 1 commit into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -2246,7 +2246,10 @@ public TransactionInfoList getTransactionInfoByBlockNum(long blockNum) {
TransactionInfoCapsule transactionInfoCapsule = dbManager.getTransactionHistoryStore()
.get(Sha256Hash.hash(DBConfig.isECKeyCryptoEngine(),
transaction.getRawData().toByteArray()));
transactionInfoList.addTransactionInfo(transactionInfoCapsule.getInstance());

if (transactionInfoCapsule != null) {
transactionInfoList.addTransactionInfo(transactionInfoCapsule.getInstance());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,7 @@ public class GetTransactionInfoByBlockNumServlet extends RateLimiterServlet {
private JSONObject convertLogAddressToTronAddress(TransactionInfo transactionInfo,
boolean visible) {
if (visible) {
List<Log> newLogList = new ArrayList<>();
for (Log log : transactionInfo.getLogList()) {
Log.Builder logBuilder = Log.newBuilder();
logBuilder.setData(log.getData());
logBuilder.addAllTopics(log.getTopicsList());

byte[] oldAddress = log.getAddress().toByteArray();

if (oldAddress.length == 0 || oldAddress.length > 20) {
logBuilder.setAddress(log.getAddress());
} else {
byte[] newAddress = new byte[20];
int start = 20 - oldAddress.length;
System.arraycopy(oldAddress, 0, newAddress, start, oldAddress.length);
logBuilder.setAddress(ByteString.copyFrom(MUtil.convertToTronAddress(newAddress)));
}
newLogList.add(logBuilder.build());
}
List<Log> newLogList = Util.convertLogAddressToTronAddress(transactionInfo);
transactionInfo = transactionInfo.toBuilder().clearLog().addAllLog(newLogList).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,7 @@ public class GetTransactionInfoByIdServlet extends RateLimiterServlet {
private static String convertLogAddressToTronAddress(TransactionInfo transactionInfo,
boolean visible) {
if (visible) {
List<Log> newLogList = new ArrayList<>();
for (Log log : transactionInfo.getLogList()) {
Log.Builder logBuilder = Log.newBuilder();
logBuilder.setData(log.getData());
logBuilder.addAllTopics(log.getTopicsList());

byte[] oldAddress = log.getAddress().toByteArray();
if (oldAddress.length == 0 || oldAddress.length > 20) {
logBuilder.setAddress(log.getAddress());
} else {
byte[] newAddress = new byte[20];

int start = 20 - oldAddress.length;
System.arraycopy(oldAddress, 0, newAddress, start, oldAddress.length);
logBuilder.setAddress(ByteString.copyFrom(MUtil.convertToTronAddress(newAddress)));
}
newLogList.add(logBuilder.build());
}
List<Log> newLogList = Util.convertLogAddressToTronAddress(transactionInfo);
transactionInfo = transactionInfo.toBuilder().clearLog().addAllLog(newLogList).build();
}
return JsonFormat.printToString(transactionInfo, visible);
Expand Down
28 changes: 27 additions & 1 deletion framework/src/main/java/org/tron/core/services/http/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.tron.common.utils.Commons.decodeFromBase58Check;

import java.util.ArrayList;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
Expand Down Expand Up @@ -35,15 +36,17 @@
import org.tron.common.utils.DBConfig;
import org.tron.common.utils.Hash;
import org.tron.common.utils.Sha256Hash;
import org.tron.core.Wallet;
import org.tron.core.actuator.TransactionFactory;
import org.tron.core.capsule.BlockCapsule;
import org.tron.core.capsule.TransactionCapsule;
import org.tron.core.config.args.Args;
import org.tron.core.services.http.JsonFormat.ParseException;
import org.tron.core.vm.utils.MUtil;
import org.tron.protos.Protocol.Block;
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
import org.tron.protos.Protocol.TransactionInfo;
import org.tron.protos.Protocol.TransactionInfo.Log;
import org.tron.protos.contract.SmartContractOuterClass.CreateSmartContract;

@Slf4j(topic = "API")
Expand Down Expand Up @@ -413,5 +416,28 @@ public static void processError(Exception e, HttpServletResponse response) {
}
}

public static List<Log> convertLogAddressToTronAddress(TransactionInfo transactionInfo) {
List<Log> newLogList = new ArrayList<>();

for (Log log : transactionInfo.getLogList()) {
Log.Builder logBuilder = Log.newBuilder();
logBuilder.setData(log.getData());
logBuilder.addAllTopics(log.getTopicsList());

byte[] oldAddress = log.getAddress().toByteArray();
if (oldAddress.length == 0 || oldAddress.length > 20) {
logBuilder.setAddress(log.getAddress());
} else {
byte[] newAddress = new byte[20];
int start = 20 - oldAddress.length;
System.arraycopy(oldAddress, 0, newAddress, start, oldAddress.length);
logBuilder.setAddress(ByteString.copyFrom(MUtil.convertToTronAddress(newAddress)));
}

newLogList.add(logBuilder.build());
}

return newLogList;
}

}