Skip to content

Commit 9050dfd

Browse files
authored
Merge pull request tronprotocol#12 from tronprotocol/master
merge master to add_sasl
2 parents d37c2f1 + 613b484 commit 9050dfd

File tree

10 files changed

+109
-16
lines changed

10 files changed

+109
-16
lines changed

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@
33
import org.pf4j.ExtensionPoint;
44

55
public interface IPluginEventListener extends ExtensionPoint {
6-
public void setServerAddress(String address);
6+
void setServerAddress(String address);
77

8-
public void setTopic(int eventType, String topic);
8+
void setTopic(int eventType, String topic);
99

10-
public void setDBConfig(String dbConfig);
10+
void setDBConfig(String dbConfig);
1111

1212
// start should be called after setServerAddress, setTopic, setDBConfig
13-
public void start();
13+
void start();
1414

15-
public void handleBlockEvent(Object data);
15+
void handleBlockEvent(Object data);
1616

17-
public void handleTransactionTrigger(Object data);
17+
void handleTransactionTrigger(Object data);
1818

19-
public void handleContractLogTrigger(Object data);
19+
void handleContractLogTrigger(Object data);
2020

21-
public void handleContractEventTrigger(Object data);
21+
void handleContractEventTrigger(Object data);
22+
23+
void handleSolidityTrigger(Object trigger);
2224

2325
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
20+
public SolidityTrigger() {
21+
setTriggerName(Trigger.SOLIDITY_TRIGGER_NAME);
22+
}
23+
}

api/src/main/java/org/tron/common/logsfilter/trigger/Trigger.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ public class Trigger {
1616
public static final int TRANSACTION_TRIGGER = 1;
1717
public static final int CONTRACTLOG_TRIGGER = 2;
1818
public static final int CONTRACTEVENT_TRIGGER = 3;
19+
public static final int SOLIDITY_TRIGGER = 4;
1920

2021
public static final String BLOCK_TRIGGER_NAME = "blockTrigger";
2122
public static final String TRANSACTION_TRIGGER_NAME = "transactionTrigger";
2223
public static final String CONTRACTLOG_TRIGGER_NAME = "contractLogTrigger";
2324
public static final String CONTRACTEVENT_TRIGGER_NAME = "contractEventTrigger";
25+
public static final String SOLIDITY_TRIGGER_NAME = "solidityTrigger";
2426
}

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: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void handleBlockEvent(Object data) {
4444
return;
4545
}
4646

47-
MessageSenderImpl.getInstance().getTriggerQueue().offer((String)data);
47+
MessageSenderImpl.getInstance().getTriggerQueue().offer(data);
4848
}
4949

5050
@Override
@@ -53,7 +53,16 @@ public void handleTransactionTrigger(Object data) {
5353
return;
5454
}
5555

56-
MessageSenderImpl.getInstance().getTriggerQueue().offer((String)data);
56+
MessageSenderImpl.getInstance().getTriggerQueue().offer(data);
57+
}
58+
59+
@Override
60+
public void handleSolidityTrigger(Object data) {
61+
if (Objects.isNull(data)){
62+
return;
63+
}
64+
65+
MessageSenderImpl.getInstance().getTriggerQueue().offer(data);
5766
}
5867

5968
@Override
@@ -62,7 +71,7 @@ public void handleContractLogTrigger(Object data) {
6271
return;
6372
}
6473

65-
MessageSenderImpl.getInstance().getTriggerQueue().offer((String)data);
74+
MessageSenderImpl.getInstance().getTriggerQueue().offer(data);
6675
}
6776

6877
@Override
@@ -71,6 +80,6 @@ public void handleContractEventTrigger(Object data) {
7180
return;
7281
}
7382

74-
MessageSenderImpl.getInstance().getTriggerQueue().offer((String)data);
83+
MessageSenderImpl.getInstance().getTriggerQueue().offer(data);
7584
}
7685
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class MessageSenderImpl{
2727
private String transactionTopic = "";
2828
private String contractEventTopic = "";
2929
private String contractLogTopic = "";
30+
private String solidityTopic = "";
3031

3132
private Thread triggerProcessThread;
3233
private boolean isRunTriggerProcessThread = true;
@@ -78,6 +79,9 @@ else if (triggerType == Constant.CONTRACTEVENT_TRIGGER){
7879
else if (triggerType == Constant.CONTRACTLOG_TRIGGER){
7980
contractLogTopic = topic;
8081
}
82+
else if (triggerType == Constant.SOLIDITY_TRIGGER) {
83+
solidityTopic = topic;
84+
}
8185
}
8286

8387

@@ -202,6 +206,13 @@ public void handleContractEventTrigger(Object data) {
202206
MessageSenderImpl.getInstance().sendKafkaRecord(Constant.CONTRACTEVENT_TRIGGER, contractEventTopic, data);
203207
}
204208

209+
public void handleSolidityTrigger(Object data) {
210+
if (Objects.isNull(data) || Objects.isNull(solidityTopic)){
211+
return;
212+
}
213+
MessageSenderImpl.getInstance().sendKafkaRecord(Constant.SOLIDITY_TRIGGER, contractEventTopic, data);
214+
}
215+
205216
private Runnable triggerProcessLoop =
206217
() -> {
207218
while (isRunTriggerProcessThread) {
@@ -224,6 +235,9 @@ else if (triggerData.contains(Constant.CONTRACTLOG_TRIGGER_NAME)){
224235
else if (triggerData.contains(Constant.CONTRACTEVENT_TRIGGER_NAME)){
225236
handleContractEventTrigger(triggerData);
226237
}
238+
else if (triggerData.contains(Constant.SOLIDITY_TRIGGER_NAME)) {
239+
handleSolidityTrigger(triggerData);
240+
}
227241
} catch (InterruptedException ex) {
228242
log.info(ex.getMessage());
229243
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: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void handleBlockEvent(Object data) {
4444
return;
4545
}
4646

47-
MongodbSenderImpl.getInstance().getTriggerQueue().offer((String)data);
47+
MongodbSenderImpl.getInstance().getTriggerQueue().offer(data);
4848
}
4949

5050
@Override
@@ -53,7 +53,7 @@ public void handleTransactionTrigger(Object data) {
5353
return;
5454
}
5555

56-
MongodbSenderImpl.getInstance().getTriggerQueue().offer((String)data);
56+
MongodbSenderImpl.getInstance().getTriggerQueue().offer(data);
5757
}
5858

5959
@Override
@@ -62,7 +62,7 @@ public void handleContractLogTrigger(Object data) {
6262
return;
6363
}
6464

65-
MongodbSenderImpl.getInstance().getTriggerQueue().offer((String)data);
65+
MongodbSenderImpl.getInstance().getTriggerQueue().offer(data);
6666
}
6767

6868
@Override
@@ -71,6 +71,15 @@ public void handleContractEventTrigger(Object data) {
7171
return;
7272
}
7373

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

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

Lines changed: 24 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;
@@ -133,6 +134,9 @@ private void createCollections(){
133134

134135
mongoManager.createCollection(contractEventTopic);
135136
createMongoTemplate(contractEventTopic);
137+
138+
mongoManager.createCollection(solidityTopic);
139+
createMongoTemplate(solidityTopic);
136140
}
137141

138142
private void loadMongoConfig(){
@@ -206,6 +210,8 @@ else if (triggerType == Constant.CONTRACTEVENT_TRIGGER){
206210
}
207211
else if (triggerType == Constant.CONTRACTLOG_TRIGGER){
208212
contractLogTopic = topic;
213+
} else if (triggerType == Constant.SOLIDITY_TRIGGER) {
214+
solidityTopic = topic;
209215
}
210216
else {
211217
return;
@@ -250,6 +256,22 @@ public void run() {
250256
}
251257
}
252258

259+
public void handleSolidityTrigger(Object data) {
260+
if (Objects.isNull(data) || Objects.isNull(solidityTopic)){
261+
return;
262+
}
263+
264+
MongoTemplate template = mongoTemplateMap.get(solidityTopic);
265+
if (Objects.nonNull(template)) {
266+
service.execute(new Runnable() {
267+
@Override
268+
public void run() {
269+
template.addEntity((String)data);
270+
}
271+
});
272+
}
273+
}
274+
253275
public void handleContractLogTrigger(Object data) {
254276
if (Objects.isNull(data) || Objects.isNull(contractLogTopic)){
255277
return;
@@ -316,6 +338,8 @@ else if (triggerData.contains(Constant.CONTRACTLOG_TRIGGER_NAME)){
316338
}
317339
else if (triggerData.contains(Constant.CONTRACTEVENT_TRIGGER_NAME)){
318340
handleContractEventTrigger(triggerData);
341+
} else if (triggerData.contains(Constant.SOLIDITY_TRIGGER_NAME)) {
342+
handleSolidityTrigger(triggerData);
319343
}
320344
} catch (InterruptedException ex) {
321345
log.info(ex.getMessage());

0 commit comments

Comments
 (0)