44import java .util .LinkedList ;
55import java .util .List ;
66import java .util .Map ;
7+
8+ import jdk .nashorn .internal .objects .annotations .Setter ;
79import org .apache .commons .lang3 .ArrayUtils ;
810import org .spongycastle .util .encoders .Hex ;
911import org .tron .common .crypto .Hash ;
1012import org .tron .common .logsfilter .trigger .ContractLogTrigger ;
1113import org .tron .common .logsfilter .trigger .ContractTrigger ;
14+ import org .tron .common .storage .Deposit ;
1215import org .tron .core .Wallet ;
1316import org .tron .protos .Protocol .SmartContract .ABI ;
1417
1518public class LogInfoTriggerParser {
1619
17- private ABI abi ;
1820 private Long blockNum ;
1921 private Long blockTimestamp ;
2022 private String txId ;
21- private String callerAddress ;
22- private String creatorAddress ;
2323 private String originAddress ;
24- private String contractAddress ;
25-
2624
27- public LogInfoTriggerParser (ABI abi ,
28- Long blockNum ,
25+ public LogInfoTriggerParser (Long blockNum ,
2926 Long blockTimestamp ,
30- byte [] txId ,
31- byte [] callerAddress ,
32- byte [] creatorAddress ,
33- byte [] originAddress ,
34- byte [] contractAddress ) {
27+ byte [] txId , byte [] originAddress ) {
3528
36- this .abi = abi ;
3729 this .blockNum = blockNum ;
3830 this .blockTimestamp = blockTimestamp ;
3931 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 );
4432 this .originAddress =
4533 ArrayUtils .isEmpty (originAddress ) ? "" : Wallet .encode58Check (originAddress );
46- this .creatorAddress =
47- ArrayUtils .isEmpty (creatorAddress ) ? "" : Wallet .encode58Check (creatorAddress );
4834
4935 }
5036
51- public List <ContractTrigger > parseLogInfos (List <LogInfo > logInfos ) {
37+ public List <ContractTrigger > parseLogInfos (List <LogInfo > logInfos , Deposit deposit ) {
5238
5339 List <ContractTrigger > list = new LinkedList <>();
5440 if (logInfos == null || logInfos .size () <= 0 ) {
@@ -58,28 +44,43 @@ public List<ContractTrigger> parseLogInfos(List<LogInfo> logInfos) {
5844 Map <String , ABI .Entry > fullMap = new HashMap <>();
5945 Map <String , String > signMap = new HashMap <>();
6046
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+ for (LogInfo logInfo : logInfos ) {
48+
49+ byte [] contractAddress = logInfo .getAddress ();
50+ String strContractAddr = ArrayUtils .isEmpty (contractAddress ) ? "" : Wallet .encode58Check (contractAddress );
51+ if (signMap .get (strContractAddr ) == null ) {
52+ ABI abi = deposit .getContract (contractAddress ).getInstance ().getAbi ();
53+ signMap .put (strContractAddr , "1" ); // mark as found.
54+
55+ // calculate the sha3 of the event signature first.
56+ if (abi != null && abi .getEntrysCount () > 0 ) {
57+ for (ABI .Entry entry : abi .getEntrysList ()) {
58+ if (entry .getType () != ABI .Entry .EntryType .Event || entry .getAnonymous ()) {
59+ continue ;
60+ }
61+ String signature = getEntrySignature (entry );
62+ String sha3 = Hex .toHexString (Hash .sha3 (signature .getBytes ()));
63+ fullMap .put (strContractAddr + "_" + sha3 , entry );
64+ signMap .put (strContractAddr + "_" + sha3 , signature );
65+ }
6666 }
67- String signature = getEntrySignature (entry );
68- String sha3 = Hex .toHexString (Hash .sha3 (signature .getBytes ()));
69- fullMap .put (sha3 , entry );
70- signMap .put (sha3 , signature );
7167 }
7268 }
69+
7370 int index = 1 ;
7471 for (LogInfo logInfo : logInfos ) {
72+
73+ byte [] contractAddress = logInfo .getAddress ();
74+ String strContractAddr = ArrayUtils .isEmpty (contractAddress ) ? "" : Wallet .encode58Check (contractAddress );
75+
7576 List <DataWord > topics = logInfo .getTopics ();
7677 ABI .Entry entry = null ;
7778 String signature = "" ;
7879 if (topics != null && topics .size () > 0 && !ArrayUtils .isEmpty (topics .get (0 ).getData ())
7980 && fullMap .size () > 0 ) {
8081 String firstTopic = topics .get (0 ).toString ();
81- entry = fullMap .get (firstTopic );
82- signature = signMap .get (firstTopic );
82+ entry = fullMap .get (strContractAddr + "_" + firstTopic );
83+ signature = signMap .get (strContractAddr + "_" + firstTopic );
8384 }
8485
8586 boolean isEvent = (entry != null );
@@ -97,10 +98,10 @@ public List<ContractTrigger> parseLogInfos(List<LogInfo> logInfos) {
9798 }
9899 event .setUniqueId (txId + "_" + index );
99100 event .setTransactionId (txId );
100- event .setContractAddress (contractAddress );
101- event .setCallerAddress (callerAddress );
101+ event .setContractAddress (strContractAddr );
102102 event .setOriginAddress (originAddress );
103- event .setCreatorAddress (creatorAddress );
103+ event .setCallerAddress ("" );
104+ event .setCreatorAddress ("" );
104105 event .setBlockNumber (blockNum );
105106 event .setTimeStamp (blockTimestamp );
106107
0 commit comments