4
4
import java .util .LinkedList ;
5
5
import java .util .List ;
6
6
import java .util .Map ;
7
+
8
+ import jdk .nashorn .internal .objects .annotations .Setter ;
7
9
import org .apache .commons .lang3 .ArrayUtils ;
8
10
import org .spongycastle .util .encoders .Hex ;
9
11
import org .tron .common .crypto .Hash ;
10
12
import org .tron .common .logsfilter .trigger .ContractLogTrigger ;
11
13
import org .tron .common .logsfilter .trigger .ContractTrigger ;
14
+ import org .tron .common .storage .Deposit ;
12
15
import org .tron .core .Wallet ;
13
16
import org .tron .protos .Protocol .SmartContract .ABI ;
14
17
15
18
public class LogInfoTriggerParser {
16
19
17
- private ABI abi ;
18
20
private Long blockNum ;
19
21
private Long blockTimestamp ;
20
22
private String txId ;
21
- private String callerAddress ;
22
- private String creatorAddress ;
23
23
private String originAddress ;
24
- private String contractAddress ;
25
-
26
24
27
- public LogInfoTriggerParser (ABI abi ,
28
- Long blockNum ,
25
+ public LogInfoTriggerParser (Long blockNum ,
29
26
Long blockTimestamp ,
30
- byte [] txId ,
31
- byte [] callerAddress ,
32
- byte [] creatorAddress ,
33
- byte [] originAddress ,
34
- byte [] contractAddress ) {
27
+ byte [] txId , byte [] originAddress ) {
35
28
36
- this .abi = abi ;
37
29
this .blockNum = blockNum ;
38
30
this .blockTimestamp = blockTimestamp ;
39
31
this .txId = ArrayUtils .isEmpty (txId ) ? "" : Hex .toHexString (txId );
40
- this .callerAddress =
41
- ArrayUtils .isEmpty (callerAddress ) ? "" : Wallet .encode58Check (callerAddress );
42
- this .contractAddress =
43
- ArrayUtils .isEmpty (contractAddress ) ? "" : Wallet .encode58Check (contractAddress );
44
32
this .originAddress =
45
33
ArrayUtils .isEmpty (originAddress ) ? "" : Wallet .encode58Check (originAddress );
46
- this .creatorAddress =
47
- ArrayUtils .isEmpty (creatorAddress ) ? "" : Wallet .encode58Check (creatorAddress );
48
34
49
35
}
50
36
51
- public List <ContractTrigger > parseLogInfos (List <LogInfo > logInfos ) {
37
+ public List <ContractTrigger > parseLogInfos (List <LogInfo > logInfos , Deposit deposit ) {
52
38
53
39
List <ContractTrigger > list = new LinkedList <>();
54
40
if (logInfos == null || logInfos .size () <= 0 ) {
@@ -58,28 +44,45 @@ public List<ContractTrigger> parseLogInfos(List<LogInfo> logInfos) {
58
44
Map <String , ABI .Entry > fullMap = new HashMap <>();
59
45
Map <String , String > signMap = new HashMap <>();
60
46
61
- // calculate the sha3 of the event signature first.
62
- if (abi != null && abi .getEntrysCount () > 0 ) {
63
- for (ABI .Entry entry : abi .getEntrysList ()) {
64
- if (entry .getType () != ABI .Entry .EntryType .Event || entry .getAnonymous ()) {
65
- continue ;
47
+ Map <byte [], ABI > abiMap = new HashMap <>();
48
+
49
+ for (LogInfo logInfo : logInfos ) {
50
+
51
+ byte [] contractAddress = logInfo .getAddress ();
52
+ String strContractAddr = ArrayUtils .isEmpty (contractAddress ) ? "" : Wallet .encode58Check (contractAddress );
53
+ ABI abi = abiMap .get (contractAddress );
54
+ if (abi == null ) {
55
+ abi = deposit .getContract (contractAddress ).getInstance ().getAbi ();
56
+ abiMap .put (contractAddress , abi );
57
+ }
58
+ // calculate the sha3 of the event signature first.
59
+ if (abi != null && abi .getEntrysCount () > 0 ) {
60
+ for (ABI .Entry entry : abi .getEntrysList ()) {
61
+ if (entry .getType () != ABI .Entry .EntryType .Event || entry .getAnonymous ()) {
62
+ continue ;
63
+ }
64
+ String signature = getEntrySignature (entry );
65
+ String sha3 = Hex .toHexString (Hash .sha3 (signature .getBytes ()));
66
+ fullMap .put (strContractAddr + "_" + sha3 , entry );
67
+ signMap .put (strContractAddr + "_" + sha3 , signature );
66
68
}
67
- String signature = getEntrySignature (entry );
68
- String sha3 = Hex .toHexString (Hash .sha3 (signature .getBytes ()));
69
- fullMap .put (sha3 , entry );
70
- signMap .put (sha3 , signature );
71
69
}
72
70
}
71
+
73
72
int index = 1 ;
74
73
for (LogInfo logInfo : logInfos ) {
74
+
75
+ byte [] contractAddress = logInfo .getAddress ();
76
+ String strContractAddr = ArrayUtils .isEmpty (contractAddress ) ? "" : Wallet .encode58Check (contractAddress );
77
+
75
78
List <DataWord > topics = logInfo .getTopics ();
76
79
ABI .Entry entry = null ;
77
80
String signature = "" ;
78
81
if (topics != null && topics .size () > 0 && !ArrayUtils .isEmpty (topics .get (0 ).getData ())
79
82
&& fullMap .size () > 0 ) {
80
83
String firstTopic = topics .get (0 ).toString ();
81
- entry = fullMap .get (firstTopic );
82
- signature = signMap .get (firstTopic );
84
+ entry = fullMap .get (strContractAddr + "_" + firstTopic );
85
+ signature = signMap .get (strContractAddr + "_" + firstTopic );
83
86
}
84
87
85
88
boolean isEvent = (entry != null );
@@ -97,10 +100,10 @@ public List<ContractTrigger> parseLogInfos(List<LogInfo> logInfos) {
97
100
}
98
101
event .setUniqueId (txId + "_" + index );
99
102
event .setTransactionId (txId );
100
- event .setContractAddress (contractAddress );
101
- event .setCallerAddress (callerAddress );
103
+ event .setContractAddress (strContractAddr );
102
104
event .setOriginAddress (originAddress );
103
- event .setCreatorAddress (creatorAddress );
105
+ event .setCallerAddress ("" );
106
+ event .setCreatorAddress ("" );
104
107
event .setBlockNumber (blockNum );
105
108
event .setTimeStamp (blockTimestamp );
106
109
0 commit comments