Skip to content

Commit 0398912

Browse files
llwslcithinker1991
authored andcommitted
event parse
event abi
1 parent 5965016 commit 0398912

File tree

4 files changed

+52
-34
lines changed

4 files changed

+52
-34
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ dependencies {
117117
compile group: 'com.google.guava', name: 'guava', version: '24.1-jre'
118118

119119
compile group: 'com.google.protobuf', name: 'protobuf-java', version: '3.4.0'
120+
compile group: 'com.google.protobuf', name: 'protobuf-java-util', version: '3.4.0'
120121

121122
compile "org.iq80.leveldb:leveldb:0.7"
122123

src/main/java/org/tron/common/logsfilter/ContractEventParserJson.java

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,24 @@ public static Map<String, String> parseTopics(List<byte[]> topicList, JSONObject
3232

3333
// in case indexed topics doesn't match
3434
if (topicsMatched(topicList, entry)) {
35-
for (int i = 0; i < inputs.size(); ++i) {
36-
JSONObject param = inputs.getJSONObject(i);
37-
Boolean indexed = param.getBoolean(INDEXED);
38-
if (indexed == null || !indexed) {
39-
continue;
40-
}
41-
if (index >= topicList.size()) {
42-
break;
43-
}
44-
String str = parseTopic(topicList.get(index++), param.getString("type"));
45-
if (StringUtils.isNotNullOrEmpty(param.getString("name"))) {
46-
map.put(param.getString("name"), str);
35+
if (inputs != null) {
36+
for (int i = 0; i < inputs.size(); ++i) {
37+
JSONObject param = inputs.getJSONObject(i);
38+
if (param != null) {
39+
Boolean indexed = param.getBoolean(INDEXED);
40+
if (indexed == null || !indexed) {
41+
continue;
42+
}
43+
if (index >= topicList.size()) {
44+
break;
45+
}
46+
String str = parseTopic(topicList.get(index++), param.getString("type"));
47+
if (StringUtils.isNotNullOrEmpty(param.getString("name"))) {
48+
map.put(param.getString("name"), str);
49+
}
50+
map.put("" + i, str);
51+
}
4752
}
48-
map.put("" + i, str);
4953
}
5054
} else {
5155
for (int i = 1; i < topicList.size(); ++i) {
@@ -82,21 +86,22 @@ public static Map<String, String> parseEventData(byte[] data,
8286
if (inputs != null) {
8387
for (Integer i = 0; i < inputs.size(); ++i) {
8488
JSONObject param = inputs.getJSONObject(i);
85-
Boolean indexed = param.getBoolean(INDEXED);
86-
if (indexed != null && indexed) {
87-
continue;
88-
}
89+
if (param != null) {
90+
Boolean indexed = param.getBoolean(INDEXED);
91+
if (indexed != null && indexed) {
92+
continue;
93+
}
8994

90-
if (startIndex == 0) {
91-
startIndex = i;
92-
}
95+
if (startIndex == 0) {
96+
startIndex = i;
97+
}
9398

94-
String str = parseDataBytes(data, param.getString("type"), index++);
95-
if (StringUtils.isNotNullOrEmpty(param.getString("name"))) {
96-
map.put(param.getString("name"), str);
99+
String str = parseDataBytes(data, param.getString("type"), index++);
100+
if (StringUtils.isNotNullOrEmpty(param.getString("name"))) {
101+
map.put(param.getString("name"), str);
102+
}
103+
map.put("" + i, str);
97104
}
98-
map.put("" + i, str);
99-
100105
}
101106
} else {
102107
map.put("0", Hex.toHexString(data));
@@ -115,14 +120,17 @@ private static boolean topicsMatched(List<byte[]> topicList, JSONObject entry) {
115120
}
116121
int inputSize = 1;
117122
JSONArray inputs = entry.getJSONArray(INPUTS);
118-
for (int i = 0; i < inputs.size(); i++) {
119-
JSONObject param = inputs.getJSONObject(i);
120-
Boolean indexed = param.getBoolean(INDEXED);
121-
if (indexed != null && indexed) {
122-
inputSize++;
123+
if (inputs != null) {
124+
for (int i = 0; i < inputs.size(); i++) {
125+
JSONObject param = inputs.getJSONObject(i);
126+
if (param != null) {
127+
Boolean indexed = param.getBoolean(INDEXED);
128+
if (indexed != null && indexed) {
129+
inputSize++;
130+
}
131+
}
123132
}
124133
}
125134
return inputSize == topicList.size();
126135
}
127-
128136
}

src/main/java/org/tron/common/runtime/vm/LogInfoTriggerParser.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package org.tron.common.runtime.vm;
22

3+
import com.google.protobuf.InvalidProtocolBufferException;
4+
import com.google.protobuf.util.JsonFormat;
35
import java.util.HashMap;
46
import java.util.LinkedList;
57
import java.util.List;
68
import java.util.Map;
9+
import lombok.extern.slf4j.Slf4j;
710
import org.apache.commons.lang3.ArrayUtils;
811
import org.apache.commons.lang3.StringUtils;
912
import org.spongycastle.util.encoders.Hex;
@@ -12,9 +15,9 @@
1215
import org.tron.common.storage.Deposit;
1316
import org.tron.core.Wallet;
1417
import org.tron.core.capsule.ContractCapsule;
15-
import org.tron.core.services.http.JsonFormat;
1618
import org.tron.protos.Protocol.SmartContract.ABI;
1719

20+
@Slf4j
1821
public class LogInfoTriggerParser {
1922

2023
private Long blockNum;
@@ -64,7 +67,13 @@ public List<ContractTrigger> parseLogInfos(List<LogInfo> logInfos, Deposit depos
6467
signMap.put(strContractAddr, creatorAddr); // mark as found.
6568

6669
if (abi != null && abi.getEntrysCount() > 0) {
67-
abiMap.put(strContractAddr, JsonFormat.printToString(abi, false));
70+
try {
71+
abiMap
72+
.put(strContractAddr, JsonFormat.printer().includingDefaultValueFields().print(abi));
73+
} catch (InvalidProtocolBufferException e) {
74+
abiMap.put(strContractAddr, "");
75+
logger.info("abi to json empty:" + txId, e);
76+
}
6877
} else {
6978
abiMap.put(strContractAddr, "");
7079
}

src/main/java/org/tron/common/runtime/vm/program/Program.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ public void callToPrecompiledAddress(MessageCall msg,
14141414
&& senderAddress != contextAddress && msg.getEndowment().value().longValueExact() > 0) {
14151415
if (!isTokenTransfer) {
14161416
try {
1417-
tranzsfer(deposit, senderAddress, contextAddress,
1417+
transfer(deposit, senderAddress, contextAddress,
14181418
msg.getEndowment().value().longValueExact());
14191419
} catch (ContractValidateException e) {
14201420
throw new BytecodeExecutionException("transfer failure");

0 commit comments

Comments
 (0)