Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@
import org.pf4j.ExtensionPoint;

public interface IPluginEventListener extends ExtensionPoint {
void setServerAddress(String address);

void setTopic(int eventType, String topic);
void setServerAddress(String address);

void setDBConfig(String dbConfig);
void setTopic(int eventType, String topic);

// start should be called after setServerAddress, setTopic, setDBConfig
void start();
void setDBConfig(String dbConfig);

void handleBlockEvent(Object data);
// start should be called after setServerAddress, setTopic, setDBConfig
void start();

void handleTransactionTrigger(Object data);
void handleBlockEvent(Object data);

void handleContractLogTrigger(Object data);
void handleTransactionTrigger(Object data);

void handleContractEventTrigger(Object data);
void handleContractLogTrigger(Object data);

void handleSolidityTrigger(Object trigger);
void handleContractEventTrigger(Object data);

void handleSolidityLogTrigger(Object trigger);
void handleSolidityTrigger(Object trigger);

void handleSolidityEventTrigger(Object trigger);
void handleSolidityLogTrigger(Object trigger);

int getPendingSize();
void handleSolidityEventTrigger(Object trigger);

int getPendingSize();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.Setter;

public class BlockLogTrigger extends Trigger {

@Getter
@Setter
private long blockNumber;
Expand All @@ -24,7 +25,6 @@ public class BlockLogTrigger extends Trigger {
@Setter
private List<String> transactionList = new ArrayList<>();


/**
* address of witness
*/
Expand All @@ -46,23 +46,14 @@ public BlockLogTrigger() {

@Override
public String toString() {
return new StringBuilder().append("triggerName: ").append(getTriggerName())
.append("timestamp: ")
.append(timeStamp)
.append(", blockNumber: ")
.append(blockNumber)
.append(", blockhash: ")
.append(blockHash)
.append(", transactionSize: ")
.append(transactionSize)
.append(", transactionList: ")
.append(transactionList)
.append(", witnessAddress: ")
.append(witnessAddress)
.append(", witnessPayPerBlock: ")
.append(witnessPayPerBlock)
.append(", witnessMap: ")
.append(witnessMap)
.toString();
return "triggerName: " + getTriggerName()
+ ", timestamp: " + timeStamp
+ ", blockNumber: " + blockNumber
+ ", blockhash: " + blockHash
+ ", transactionSize: " + transactionSize
+ ", transactionList: " + transactionList
+ ", witnessAddress: " + witnessAddress
+ ", witnessPayPerBlock: " + witnessPayPerBlock
+ ", witnessMap: " + witnessMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class ContractEventTrigger extends ContractTrigger {
@Setter
private Map<String, String> dataMap;


public ContractEventTrigger() {
super();
setTriggerName(Trigger.CONTRACTEVENT_TRIGGER_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Setter;

public class ContractLogTrigger extends ContractTrigger {

/**
* topic list produced by the smart contract LOG function
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
import lombok.Setter;

public class SolidityTrigger extends Trigger {

@Getter
@Setter
private long latestSolidifiedBlockNumber;

@Override
public String toString() {
return new StringBuilder().append("triggerName: ").append(getTriggerName())
.append("timestamp: ")
.append(timeStamp)
.append(", latestSolidifiedBlockNumber: ")
.append(latestSolidifiedBlockNumber).toString();
return "triggerName: " + getTriggerName()
+ ", timestamp: " + timeStamp
+ ", latestSolidifiedBlockNumber: " + latestSolidifiedBlockNumber;
}

public SolidityTrigger() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.tron.common.logsfilter.trigger;

import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Setter;

public class Trigger {

@Getter
@Setter
protected long timeStamp;
Expand Down
154 changes: 77 additions & 77 deletions app/src/main/java/org/tron/eventplugin/app/PluginLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,97 +13,97 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.tron.eventplugin.app;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.util.List;
import java.util.Objects;
import org.pf4j.CompoundPluginDescriptorFinder;
import org.pf4j.DefaultPluginManager;
import org.pf4j.ManifestPluginDescriptorFinder;
import org.pf4j.PluginManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.pf4j.DefaultPluginManager;
import org.pf4j.PluginManager;
import org.tron.common.logsfilter.IPluginEventListener;
import org.tron.common.logsfilter.trigger.BlockLogTrigger;
import org.tron.common.logsfilter.trigger.Trigger;

import java.io.File;
import java.util.List;
import java.util.Objects;

public class PluginLauncher {
private static final Logger logger = LoggerFactory.getLogger(PluginLauncher.class);

public static void main(String[] args) {
String path = "/Users/tron/sourcecode/eventplugin/build/plugins/plugin-mongodb-1.0.0.zip";

File dir = new File(path);
// create the plugin manager
final PluginManager pluginManager = new DefaultPluginManager(dir.toPath()) {
@Override
protected CompoundPluginDescriptorFinder createPluginDescriptorFinder() {
return new CompoundPluginDescriptorFinder()
.add(new ManifestPluginDescriptorFinder());
}
};

File file = new File(path);

pluginManager.loadPlugin(file.toPath());
pluginManager.startPlugins();

List<IPluginEventListener> eventListeners;
eventListeners = pluginManager.getExtensions(IPluginEventListener.class);

if (Objects.isNull(eventListeners)) return;

eventListeners.forEach(listener -> {
listener.setServerAddress("127.0.0.1:27017");
});

eventListeners.forEach(listener -> {
listener.setDBConfig("eventlog|tron|123456");
});

eventListeners.forEach(listener -> {
listener.setTopic(Trigger.BLOCK_TRIGGER, "block");
listener.setTopic(Trigger.TRANSACTION_TRIGGER, "transaction");
listener.setTopic(Trigger.CONTRACTEVENT_TRIGGER, "contractevent");
listener.setTopic(Trigger.CONTRACTLOG_TRIGGER, "contractlog");
listener.setTopic(Trigger.SOLIDITY_TRIGGER, "solidity");
listener.setTopic(Trigger.SOLIDITY_EVENT, "solidityevent");
listener.setTopic(Trigger.SOLIDITY_LOG, "soliditylog");

});

eventListeners.forEach(listener -> {
listener.start();
});

ObjectMapper objectMapper = new ObjectMapper();
for (int index = 0; index < 1000; ++index){
BlockLogTrigger trigger = new BlockLogTrigger();
trigger.setBlockNumber(index);
trigger.setBlockHash("000000000002f5834df6036318999576bfa23ff1a57e0538fa87d5a90319659e");
trigger.setTimeStamp(System.currentTimeMillis());
trigger.setTransactionSize(100);

eventListeners.forEach(listener -> {
try {
listener.handleBlockEvent(objectMapper.writeValueAsString(trigger));
} catch (com.fasterxml.jackson.core.JsonProcessingException e) {
e.printStackTrace();
}
});
}

while (true){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
private static final Logger logger = LoggerFactory.getLogger(PluginLauncher.class);

public static void main(String[] args) {
String path = "/Users/tron/sourcecode/eventplugin/build/plugins/plugin-mongodb-1.0.0.zip";

File dir = new File(path);
// create the plugin manager
final PluginManager pluginManager = new DefaultPluginManager(dir.toPath()) {
@Override
protected CompoundPluginDescriptorFinder createPluginDescriptorFinder() {
return new CompoundPluginDescriptorFinder()
.add(new ManifestPluginDescriptorFinder());
}
};

File file = new File(path);

pluginManager.loadPlugin(file.toPath());
pluginManager.startPlugins();

List<IPluginEventListener> eventListeners;
eventListeners = pluginManager.getExtensions(IPluginEventListener.class);

if (Objects.isNull(eventListeners)) {
return;
}

eventListeners.forEach(listener -> {
listener.setServerAddress("127.0.0.1:27017");
});

eventListeners.forEach(listener -> {
listener.setDBConfig("eventlog|tron|123456");
});

eventListeners.forEach(listener -> {
listener.setTopic(Trigger.BLOCK_TRIGGER, "block");
listener.setTopic(Trigger.TRANSACTION_TRIGGER, "transaction");
listener.setTopic(Trigger.CONTRACTEVENT_TRIGGER, "contractevent");
listener.setTopic(Trigger.CONTRACTLOG_TRIGGER, "contractlog");
listener.setTopic(Trigger.SOLIDITY_TRIGGER, "solidity");
listener.setTopic(Trigger.SOLIDITY_EVENT, "solidityevent");
listener.setTopic(Trigger.SOLIDITY_LOG, "soliditylog");
});

eventListeners.forEach(IPluginEventListener::start);

ObjectMapper objectMapper = new ObjectMapper();
for (int index = 0; index < 1000; ++index) {
BlockLogTrigger trigger = new BlockLogTrigger();
trigger.setBlockNumber(index);
trigger.setBlockHash("000000000002f5834df6036318999576bfa23ff1a57e0538fa87d5a90319659e");
trigger.setTimeStamp(System.currentTimeMillis());
trigger.setTransactionSize(100);

eventListeners.forEach(listener -> {
try {
listener.handleBlockEvent(objectMapper.writeValueAsString(trigger));
} catch (com.fasterxml.jackson.core.JsonProcessingException e) {
e.printStackTrace();
}
});
}

//pluginManager.stopPlugins();
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

//pluginManager.stopPlugins();
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package org.tron.eventplugin;

public class Constant {
public static final int BLOCK_TRIGGER = 0;
public static final int TRANSACTION_TRIGGER = 1;
public static final int CONTRACTLOG_TRIGGER = 2;
public static final int CONTRACTEVENT_TRIGGER = 3;
public static final int SOLIDITY_TRIGGER = 4;
public static final int SOLIDITY_EVENT = 5;
public static final int SOLIDITY_LOG = 6;

public static final String BLOCK_TRIGGER_NAME = "blockTrigger";
public static final String TRANSACTION_TRIGGER_NAME = "transactionTrigger";
public static final String CONTRACTLOG_TRIGGER_NAME = "contractLogTrigger";
public static final String CONTRACTEVENT_TRIGGER_NAME = "contractEventTrigger";
public static final String SOLIDITY_TRIGGER_NAME = "solidityTrigger";
public static final String SOLIDITYLOG_TRIGGER_NAME = "solidityLogTrigger";
public static final String SOLIDITYEVENT_TRIGGER_NAME = "solidityEventTrigger";
public static final int BLOCK_TRIGGER = 0;
public static final int TRANSACTION_TRIGGER = 1;
public static final int CONTRACTLOG_TRIGGER = 2;
public static final int CONTRACTEVENT_TRIGGER = 3;
public static final int SOLIDITY_TRIGGER = 4;
public static final int SOLIDITY_EVENT = 5;
public static final int SOLIDITY_LOG = 6;

private Constant(){}
public static final String BLOCK_TRIGGER_NAME = "blockTrigger";
public static final String TRANSACTION_TRIGGER_NAME = "transactionTrigger";
public static final String CONTRACTLOG_TRIGGER_NAME = "contractLogTrigger";
public static final String CONTRACTEVENT_TRIGGER_NAME = "contractEventTrigger";
public static final String SOLIDITY_TRIGGER_NAME = "solidityTrigger";
public static final String SOLIDITYLOG_TRIGGER_NAME = "solidityLogTrigger";
public static final String SOLIDITYEVENT_TRIGGER_NAME = "solidityEventTrigger";

private Constant() {
}
}
Loading