Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private static String parseDataBytes(byte[] data, String typeStr, int index) {
private static Type basicType(String type) {
if (!Pattern.matches("^.*\\[\\d*\\]$", type)) {
// ignore not valide type such as "int92", "bytes33", these types will be compiled failed.
if ((type.startsWith("int") || type.startsWith("uint"))) {
if (type.startsWith("int") || type.startsWith("uint") || type.startsWith("trcToken")) {
return Type.INT_NUMBER;
} else if (type.equals("bool")) {
return Type.BOOL;
Expand Down
30 changes: 7 additions & 23 deletions src/main/java/org/tron/common/runtime/RuntimeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

import com.google.protobuf.ByteString;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.*;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -21,12 +20,7 @@
import org.tron.common.logsfilter.EventPluginLoader;
import org.tron.common.logsfilter.trigger.ContractTrigger;
import org.tron.common.runtime.config.VMConfig;
import org.tron.common.runtime.vm.DataWord;
import org.tron.common.runtime.vm.EnergyCost;
import org.tron.common.runtime.vm.LogInfoTriggerParser;
import org.tron.common.runtime.vm.VM;
import org.tron.common.runtime.vm.VMConstant;
import org.tron.common.runtime.vm.VMUtils;
import org.tron.common.runtime.vm.*;
import org.tron.common.runtime.vm.program.InternalTransaction;
import org.tron.common.runtime.vm.program.InternalTransaction.ExecutorType;
import org.tron.common.runtime.vm.program.InternalTransaction.TrxType;
Expand Down Expand Up @@ -94,7 +88,6 @@ public class RuntimeImpl implements Runtime {
@Setter
private boolean enableEventLinstener;


private LogInfoTriggerParser logInfoTriggerParser;

/**
Expand Down Expand Up @@ -450,10 +443,7 @@ private void create()
(EventPluginLoader.getInstance().isContractEventTriggerEnable()
|| EventPluginLoader.getInstance().isContractLogTriggerEnable())
&& isCheckTransaction()){

logInfoTriggerParser = new LogInfoTriggerParser(newSmartContract.getAbi(),
blockCap.getNum(), blockCap.getTimeStamp(), txId,
callerAddress, callerAddress, callerAddress, contractAddress);
logInfoTriggerParser = new LogInfoTriggerParser(blockCap.getNum(), blockCap.getTimeStamp(), txId, callerAddress);

}
} catch (Exception e) {
Expand Down Expand Up @@ -542,15 +532,11 @@ private void call()
}
AccountCapsule caller = this.deposit.getAccount(callerAddress);
long energyLimit;
byte[] creatorAddress = null;
byte[] originAddress = null;
if (isCallConstant(contractAddress)) {
isStaticCall = true;
energyLimit = Constant.ENERGY_LIMIT_IN_CONSTANT_TX;
} else {
originAddress = deployedContract.getInstance().getOriginAddress().toByteArray();
AccountCapsule creator = this.deposit.getAccount(originAddress);
creatorAddress = creator.getAddress().toByteArray();
AccountCapsule creator = this.deposit.getAccount(deployedContract.getInstance().getOriginAddress().toByteArray());
energyLimit = getTotalEnergyLimit(creator, caller, contract, feeLimit, callValue);
}
long maxCpuTimeOfOneTx = deposit.getDbManager().getDynamicPropertiesStore()
Expand Down Expand Up @@ -579,9 +565,7 @@ private void call()
|| EventPluginLoader.getInstance().isContractLogTriggerEnable())
&& isCheckTransaction()){

logInfoTriggerParser = new LogInfoTriggerParser(deployedContract.getInstance().getAbi(),
blockCap.getNum(), blockCap.getTimeStamp(), txId,
callerAddress, creatorAddress, originAddress, contractAddress);
logInfoTriggerParser = new LogInfoTriggerParser(blockCap.getNum(), blockCap.getTimeStamp(), txId, callerAddress);
}
}

Expand Down Expand Up @@ -660,7 +644,7 @@ public void go() {
deposit.commit();

if (logInfoTriggerParser != null){
List<ContractTrigger> triggers = logInfoTriggerParser.parseLogInfos(program.getResult().getLogInfoList());
List<ContractTrigger> triggers = logInfoTriggerParser.parseLogInfos(program.getResult().getLogInfoList(), this.deposit);
program.getResult().setTriggerList(triggers);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/tron/common/runtime/vm/DataWord.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public byte[] getClonedData() {
if (data != null){
ret = new byte[DATAWORD_UNIT_SIZE];
int dataSize = Math.min(data.length, DATAWORD_UNIT_SIZE);
System.arraycopy(data, 0, ret, DATAWORD_UNIT_SIZE - dataSize, dataSize);
System.arraycopy(data, 0, ret, 0, dataSize);
}
return ret;
}
Expand Down
69 changes: 35 additions & 34 deletions src/main/java/org/tron/common/runtime/vm/LogInfoTriggerParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,37 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import jdk.nashorn.internal.objects.annotations.Setter;
import org.apache.commons.lang3.ArrayUtils;
import org.spongycastle.util.encoders.Hex;
import org.tron.common.crypto.Hash;
import org.tron.common.logsfilter.trigger.ContractLogTrigger;
import org.tron.common.logsfilter.trigger.ContractTrigger;
import org.tron.common.storage.Deposit;
import org.tron.core.Wallet;
import org.tron.protos.Protocol.SmartContract.ABI;

public class LogInfoTriggerParser {

private ABI abi;
private Long blockNum;
private Long blockTimestamp;
private String txId;
private String callerAddress;
private String creatorAddress;
private String originAddress;
private String contractAddress;


public LogInfoTriggerParser(ABI abi,
Long blockNum,
public LogInfoTriggerParser(Long blockNum,
Long blockTimestamp,
byte[] txId,
byte[] callerAddress,
byte[] creatorAddress,
byte[] originAddress,
byte[] contractAddress) {
byte[] txId, byte[] originAddress) {

this.abi = abi;
this.blockNum = blockNum;
this.blockTimestamp = blockTimestamp;
this.txId = ArrayUtils.isEmpty(txId) ? "" : Hex.toHexString(txId);
this.callerAddress =
ArrayUtils.isEmpty(callerAddress) ? "" : Wallet.encode58Check(callerAddress);
this.contractAddress =
ArrayUtils.isEmpty(contractAddress) ? "" : Wallet.encode58Check(contractAddress);
this.originAddress =
ArrayUtils.isEmpty(originAddress) ? "" : Wallet.encode58Check(originAddress);
this.creatorAddress =
ArrayUtils.isEmpty(creatorAddress) ? "" : Wallet.encode58Check(creatorAddress);

}

public List<ContractTrigger> parseLogInfos(List<LogInfo> logInfos) {
public List<ContractTrigger> parseLogInfos(List<LogInfo> logInfos, Deposit deposit) {

List<ContractTrigger> list = new LinkedList<>();
if (logInfos == null || logInfos.size() <= 0) {
Expand All @@ -58,28 +44,43 @@ public List<ContractTrigger> parseLogInfos(List<LogInfo> logInfos) {
Map<String, ABI.Entry> fullMap = new HashMap<>();
Map<String, String> signMap = new HashMap<>();

// calculate the sha3 of the event signature first.
if (abi != null && abi.getEntrysCount() > 0) {
for (ABI.Entry entry : abi.getEntrysList()) {
if (entry.getType() != ABI.Entry.EntryType.Event || entry.getAnonymous()) {
continue;
for (LogInfo logInfo : logInfos) {

byte[] contractAddress = logInfo.getAddress();
String strContractAddr = ArrayUtils.isEmpty(contractAddress) ? "" : Wallet.encode58Check(contractAddress);
if (signMap.get(strContractAddr) == null) {
ABI abi = deposit.getContract(contractAddress).getInstance().getAbi();
signMap.put(strContractAddr, "1"); // mark as found.

// calculate the sha3 of the event signature first.
if (abi != null && abi.getEntrysCount() > 0) {
for (ABI.Entry entry : abi.getEntrysList()) {
if (entry.getType() != ABI.Entry.EntryType.Event || entry.getAnonymous()) {
continue;
}
String signature = getEntrySignature(entry);
String sha3 = Hex.toHexString(Hash.sha3(signature.getBytes()));
fullMap.put(strContractAddr + "_" + sha3, entry);
signMap.put(strContractAddr + "_" + sha3, signature);
}
}
String signature = getEntrySignature(entry);
String sha3 = Hex.toHexString(Hash.sha3(signature.getBytes()));
fullMap.put(sha3, entry);
signMap.put(sha3, signature);
}
}

int index = 1;
for (LogInfo logInfo : logInfos) {

byte[] contractAddress = logInfo.getAddress();
String strContractAddr = ArrayUtils.isEmpty(contractAddress) ? "" : Wallet.encode58Check(contractAddress);

List<DataWord> topics = logInfo.getTopics();
ABI.Entry entry = null;
String signature = "";
if (topics != null && topics.size() > 0 && !ArrayUtils.isEmpty(topics.get(0).getData())
&& fullMap.size() > 0) {
String firstTopic = topics.get(0).toString();
entry = fullMap.get(firstTopic);
signature = signMap.get(firstTopic);
entry = fullMap.get(strContractAddr + "_" + firstTopic);
signature = signMap.get(strContractAddr + "_" + firstTopic);
}

boolean isEvent = (entry != null);
Expand All @@ -97,10 +98,10 @@ public List<ContractTrigger> parseLogInfos(List<LogInfo> logInfos) {
}
event.setUniqueId(txId + "_" + index);
event.setTransactionId(txId);
event.setContractAddress(contractAddress);
event.setCallerAddress(callerAddress);
event.setContractAddress(strContractAddr);
event.setOriginAddress(originAddress);
event.setCreatorAddress(creatorAddress);
event.setCallerAddress("");
event.setCreatorAddress("");
event.setBlockNumber(blockNum);
event.setTimeStamp(blockTimestamp);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public byte[] getSender() {
}

public byte[] getReceiveAddress() {
if (sendAddress == null) {
if (receiveAddress == null) {
return EMPTY_BYTE_ARRAY;
}
return receiveAddress.clone();
Expand Down