Skip to content

Commit 70ffb70

Browse files
author
wubinTron
committed
add solidity event
1 parent 8a0fc0f commit 70ffb70

File tree

8 files changed

+78
-0
lines changed

8 files changed

+78
-0
lines changed

api/src/main/java/org/tron/common/logsfilter/IPluginEventListener.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ public interface IPluginEventListener extends ExtensionPoint {
2020

2121
public void handleContractEventTrigger(Object data);
2222

23+
public void handleSolidityTrigger(Object trigger);
24+
2325
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.tron.common.logsfilter.trigger;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
public class SolidityTrigger extends Trigger {
7+
@Getter
8+
@Setter
9+
private long latestSolidifiedBlockNumber;
10+
11+
@Override
12+
public String toString() {
13+
return new StringBuilder().append("triggerName: ").append(getTriggerName())
14+
.append("timestamp: ")
15+
.append(timeStamp)
16+
.append(", latestSolidifiedBlockNumber: ")
17+
.append(latestSolidifiedBlockNumber).toString();
18+
}
19+
}

plugins/kafkaplugin/src/main/java/org/tron/eventplugin/Constant.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ public class Constant {
55
public static final int TRANSACTION_TRIGGER = 1;
66
public static final int CONTRACTLOG_TRIGGER = 2;
77
public static final int CONTRACTEVENT_TRIGGER = 3;
8+
public static final int SOLIDITY_TRIGGER = 4;
89

910
public static final String BLOCK_TRIGGER_NAME = "blockTrigger";
1011
public static final String TRANSACTION_TRIGGER_NAME = "transactionTrigger";
1112
public static final String CONTRACTLOG_TRIGGER_NAME = "contractLogTrigger";
1213
public static final String CONTRACTEVENT_TRIGGER_NAME = "contractEventTrigger";
14+
public static final String SOLIDITY_TRIGGER_NAME = "solidityTrigger";
1315

1416
private Constant(){}
1517
}

plugins/kafkaplugin/src/main/java/org/tron/eventplugin/KafkaEventListener.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ public void handleTransactionTrigger(Object data) {
5656
MessageSenderImpl.getInstance().getTriggerQueue().offer((String)data);
5757
}
5858

59+
@Override
60+
public void handleSolidityTrigger(Object data) {
61+
if (Objects.isNull(data)){
62+
return;
63+
}
64+
65+
MessageSenderImpl.getInstance().getTriggerQueue().offer((String)data);
66+
}
67+
5968
@Override
6069
public void handleContractLogTrigger(Object data) {
6170
if (Objects.isNull(data)){

plugins/kafkaplugin/src/main/java/org/tron/eventplugin/MessageSenderImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class MessageSenderImpl{
2424
private String transactionTopic = "";
2525
private String contractEventTopic = "";
2626
private String contractLogTopic = "";
27+
private String solidityTopic = "";
2728

2829
private Thread triggerProcessThread;
2930
private boolean isRunTriggerProcessThread = true;
@@ -75,6 +76,9 @@ else if (triggerType == Constant.CONTRACTEVENT_TRIGGER){
7576
else if (triggerType == Constant.CONTRACTLOG_TRIGGER){
7677
contractLogTopic = topic;
7778
}
79+
else if (triggerType == Constant.SOLIDITY_TRIGGER) {
80+
solidityTopic = topic;
81+
}
7882
}
7983

8084

@@ -175,6 +179,13 @@ public void handleContractEventTrigger(Object data) {
175179
MessageSenderImpl.getInstance().sendKafkaRecord(Constant.CONTRACTEVENT_TRIGGER, contractEventTopic, data);
176180
}
177181

182+
public void handleSolidityTrigger(Object data) {
183+
if (Objects.isNull(data) || Objects.isNull(solidityTopic)){
184+
return;
185+
}
186+
MessageSenderImpl.getInstance().sendKafkaRecord(Constant.SOLIDITY_TRIGGER, contractEventTopic, data);
187+
}
188+
178189
private Runnable triggerProcessLoop =
179190
() -> {
180191
while (isRunTriggerProcessThread) {
@@ -197,6 +208,9 @@ else if (triggerData.contains(Constant.CONTRACTLOG_TRIGGER_NAME)){
197208
else if (triggerData.contains(Constant.CONTRACTEVENT_TRIGGER_NAME)){
198209
handleContractEventTrigger(triggerData);
199210
}
211+
else if (triggerData.contains(Constant.SOLIDITY_TRIGGER_NAME)) {
212+
handleSolidityTrigger(triggerData);
213+
}
200214
} catch (InterruptedException ex) {
201215
log.info(ex.getMessage());
202216
Thread.currentThread().interrupt();

plugins/mongodbplugin/src/main/java/org/tron/eventplugin/Constant.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ public class Constant {
55
public static final int TRANSACTION_TRIGGER = 1;
66
public static final int CONTRACTLOG_TRIGGER = 2;
77
public static final int CONTRACTEVENT_TRIGGER = 3;
8+
public static final int SOLIDITY_TRIGGER = 4;
89

910
public static final String BLOCK_TRIGGER_NAME = "blockTrigger";
1011
public static final String TRANSACTION_TRIGGER_NAME = "transactionTrigger";
1112
public static final String CONTRACTLOG_TRIGGER_NAME = "contractLogTrigger";
1213
public static final String CONTRACTEVENT_TRIGGER_NAME = "contractEventTrigger";
14+
public static final String SOLIDITY_TRIGGER_NAME = "solidityTrigger";
1315

1416
private Constant(){}
1517
}

plugins/mongodbplugin/src/main/java/org/tron/eventplugin/MongodbEventListener.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,13 @@ public void handleContractEventTrigger(Object data) {
7373

7474
MongodbSenderImpl.getInstance().getTriggerQueue().offer((String)data);
7575
}
76+
77+
@Override
78+
public void handleSolidityTrigger(Object data) {
79+
if (Objects.isNull(data)){
80+
return;
81+
}
82+
83+
MongodbSenderImpl.getInstance().getTriggerQueue().offer((String)data);
84+
}
7685
}

plugins/mongodbplugin/src/main/java/org/tron/eventplugin/MongodbSenderImpl.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class MongodbSenderImpl{
2929
private String transactionTopic = "";
3030
private String contractEventTopic = "";
3131
private String contractLogTopic = "";
32+
private String solidityTopic = "";
3233

3334
private Thread triggerProcessThread;
3435
private boolean isRunTriggerProcessThread = true;
@@ -206,6 +207,8 @@ else if (triggerType == Constant.CONTRACTEVENT_TRIGGER){
206207
}
207208
else if (triggerType == Constant.CONTRACTLOG_TRIGGER){
208209
contractLogTopic = topic;
210+
} else if (triggerType == Constant.SOLIDITY_TRIGGER) {
211+
solidityTopic = topic;
209212
}
210213
else {
211214
return;
@@ -250,6 +253,22 @@ public void run() {
250253
}
251254
}
252255

256+
public void handleSolidityTrigger(Object data) {
257+
if (Objects.isNull(data) || Objects.isNull(solidityTopic)){
258+
return;
259+
}
260+
261+
MongoTemplate template = mongoTemplateMap.get(solidityTopic);
262+
if (Objects.nonNull(template)) {
263+
service.execute(new Runnable() {
264+
@Override
265+
public void run() {
266+
template.addEntity((String)data);
267+
}
268+
});
269+
}
270+
}
271+
253272
public void handleContractLogTrigger(Object data) {
254273
if (Objects.isNull(data) || Objects.isNull(contractLogTopic)){
255274
return;
@@ -316,6 +335,8 @@ else if (triggerData.contains(Constant.CONTRACTLOG_TRIGGER_NAME)){
316335
}
317336
else if (triggerData.contains(Constant.CONTRACTEVENT_TRIGGER_NAME)){
318337
handleContractEventTrigger(triggerData);
338+
} else if (triggerData.contains(Constant.SOLIDITY_TRIGGER_NAME)) {
339+
handleSolidityTrigger(triggerData);
319340
}
320341
} catch (InterruptedException ex) {
321342
log.info(ex.getMessage());

0 commit comments

Comments
 (0)