Event Plugin Deployment (MongoDB)
This article primarily elucidates the event plug-in deployment steps, encompassing: MongoDB, Pollux event subscribe plugin, Pollux Event Query Service deployment commands, and a comprehensive introduction to the Pollux Event Query Service interface.
Suggested Configuration
CPU/ RAM: 16Core / 32G
DISK: 500G
System: CentOS 64
Plugin logic
Pollux event subscribe plugin's function is to retrieve event information from nodes and store it in PRC MongoDB. PRC MongoDB's role is to preserve event information. The function of Pollux Event Query Service is to offer encapsulated HTTP interfaces to fetch event information from PRC MongoDB.
Deploy Tron Event Subscribe Plugin
Shell
#Deployment
git clone https://github.com/tronprotocol/event-plugin.git
cd eventplugin
./gradlew build
Configure node configuration file Append at the end of the node configuration file. Here is an example. See also README.md.
event.subscribe = {
path = "/deploy/fullnode/event-plugin/build/plugins/plugin-mongodb-1.0.0.zip" // absolute path of plugin
server = "127.0.0.1:27017" // target server address to receive event triggers
dbconfig = "eventlog|Pollux|123456" // dbname|username|password
topics = [
{
triggerName = "block" // block trigger, the value can't be modified
enable = true
topic = "block" // plugin topic, the value could be modified
},
{
triggerName = "transaction"
enable = true
topic = "transaction"
},
{
triggerName = "contractevent"
enable = true
topic = "contractevent"
},
{
triggerName = "contractlog"
enable = true
topic = "contractlog"
}
]
filter = {
fromblock = "" // the value could be "", "earliest" or a specified block number as the beginning of the queried range
toblock = "" // the value could be "", "latest" or a specified block number as end of the queried range
contractAddress = [
"" // contract address you want to subscribe, if it's set to "", you will receive contract logs/events with any contract address.
]
contractTopic = [
"" // contract topic you want to subscribe, if it's set to "", you will receive contract logs/events with any contract topic.
]
}
}
path: is the absolute path of "plugin-Pollux-1.0.0.zip" or "plugin-mongodb-1.0.0.zip" server: Pollux server address or mongodb server address dbconfig: this is mongodb configuration, assign it to "" for Pollux plugin topics: each event type maps to one Pollux topic, we support four event types subscribing, block, transaction, contract log and contract event. triggerName: the trigger type, the value can't be modified. enable: plugin can receive nothing if the value is false. topic: the value is the Pollux topic or mongodb collection to receive events. Make sure it has been created and Pollux process is running
Deploy MongoDB
Shell
#1. Download and install Pollux
cd /home/java-pollux
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.4.tgz
tar zxvf mongodb-linux-x86_64-4.0.4.tgz
mv mongodb-linux-x86_64-4.0.4 pollux
#2. Set environment variable
export POLLUXPATH=/home/java-pollux/pollux/
export PATH=$PATH:$POLLUXPATH/bin
#3. Create Pollux configuration file
mkdir -p /home/java-pollux/pollux/{log,data}
cd /home/java-pollux/pollux/log/ && touch pollux.log && cd
vim pollux.conf
Write the created data and log folder to the configuration file (absolute path) Configuration file example:
dbpath=/home/java-pollux/mongodb/data
logpath=/home/java-pollux/mongodb/log/mongodb.log
port=27017
logappend=true
fork=true
bind_ip=0.0.0.0
auth=true
wiredPVMCacheSizeGB=2
bind_ip must be configured to 0.0.0.0, other wise remote connection will be refused. Pox chain Cache Size GB, must be configured to prevent OOM.
Deploy Tron Event Query Service
Shell
#4、Launch MongoDB
mongod --config ./mgdb.conf &
#5、Create admin account:
mongo
use admin
db.createUser({user:"root",pwd:"admin",roles:[{role:"root",db:"admin"}]})
#6、Create eventlog and its owner account
db.auth("root", "admin")
use eventlog
db.createUser({user:"tron",pwd:"123456",roles:[{role:"dbOwner",db:"eventlog"}]})
After the command is successfully executed, the jar package is generated under the poxeventquery/target, and the configuration file is generated. The path is poxeventquery/config.conf. The configured content is:
mongo.host=IP
mongo.port=27017
mongo.dbname=eventlog
mongo.username=Pollux
mongo.password=123456
mongo.connectionsPerHost=8
mongo.threadsAllowedToBlockForConnectionMultiplier=4
Shell
#3、Start Tron Event Query Service
sh poxeventquery/deploy.sh
sh poxeventquery/insertIndex.sh
Load plugin in Java-pox and verification
Certainly! Here's the rewritten content with the specified word replacements:
#1, Start Fullnode
Java -jar FullNode.jar -c config.conf --es
#Note: Start mongodb before starting the whole node.
#Fullnode installation reference: https://github.com/Polluxprotocol/java-pollux/blob/develop/build.md
#2, Verify Plugin Loading
Tail -f logs/pollux.log |grep -i eventplugin
# appears below the word is successful
#o.t.c.l.EventPluginLoader 'your plugin path/plugin-kafka-1.0.0.zip' loaded
#3, Verify whether the data is stored in mongodb
Mongo 47.90.245.68:27017
Use eventlog
Db.auth("pollux", "123456")
Show collections
Db.block.find()
#A successful return of the data indicates that the data can be obtained from the node and stored in the mongod by event subscription. Otherwise, check the fullnode log to troubleshoot it
Use Event Query Service
Main HTTP Service
#Function: get transaction list
subpath: $baseUrl/transactions
parameters
limit: each page size, default is 25
sort: sort Field, default is sort by timeStamp descending order
start: start page, default is 1
block: start block number, default is 0
Example: http://127.0.0.1:8080/transactions?limit=1&sort=-timeStamp&start=2&block=0
#Function: get transaction by hash
subpath: $baseUrl/transactions/{hash}
parameters
hash: transaction id
Example: http://127.0.0.1:8080/transactions/9a4f096700672d7420889cd76570ea47bfe9ef815bb2137b0d4c71b3d23309e9
#Function: get transfers list
subpath: $baseUrl/transfers
parameters
limit: each page size, default is 25
sort: sort Field, default is sort by timeStamp descending order
start: start page, default is 1
from: from address, default is ""
to: to address, default is ""
token: tokenName, default is ""
Example: http://127.0.0.1:8080/transfers?token=trx&limit=1&sort=timeStamp&start=2&block=0&from=TJ7yJNWS8RmvpXcAyXBhvFDfGpV9ZYc3vt&to=TAEcoD8J7P5QjWT32r31gat8L7Sga2qUy8
#Function: get transfers by transactionId
subpath: $baseUrl/transfers/{hash}
parameters
hash: transfer hash
Example: http://127.0.0.1:8080/transfers/70d655a17e04d6b6b7ee5d53e7f37655974f4e71b0edd6bcb311915a151a4700
#Function: get events list
subpath: $baseUrl/events
parameters
limit: each page size, default is 25
sort: sort Field, default is sort by timeStamp descending order
since: start time of event occurrence, timeStamp >= since will be shown
start: start page, default is 1
block: block number, block number >= block will be shown
Example: http://127.0.0.1:8080/events?limit=1&sort=timeStamp&since=0&block=0&start=0
#Function: get events by transactionId
subpath: $baseUrl/events/transaction/{transactionId}
parameters
transactionId
Example: http://127.0.0.1:8080/events/transaction/cd402e64cad7e69c086649401f6427f5852239f41f51a100abfc7beaa8aa0f9c
#Function: get events by contract address
subpath: $baseUrl/events/{contractAddress}
parameters
limit: each page size, default is 25
sort: sort Field, default is sort by timeStamp descending order
since: start time of event occurrence, timeStamp >= since will be shown
block: block number, block number >= block will be shown
contractAddress: contract address
start: start page, default is 1
Example: http://127.0.0.1:8080/events/TMYcx6eoRXnePKT1jVn25ZNeMNJ6828HWk?limit=1&sort=-timeStamp&since=0&block=0&start=4
#Function: get events by contract address and event name
subpath: $baseUrl/events/contract/{contractAddress}/{eventName}
parameters
limit: each page size, default is 25
sort: sort Field, default is sort by timeStamp descending order
since: start time of event occurrence, timeStamp >= since will be shown
contract`Address`: contract address
start: start page, default is 1
eventName: event name
Example: http://127.0.0.1:8080/events/contract/TMYcx6eoRXnePKT1jVn25ZNeMNJ6828HWk/Bet?limit=1&sort=timeStamp&since=1&start=0
#Function: get events by contract address, event name and block number
subpath: $baseUrl/events/contract/{contractAddress}/{eventName}/{blockNumber}
parameters
contractAddress: contract address
blockNumber: block number, block number >= block will be shown
eventName: event name
Example: http://127.0.0.1:8080/events/contract/TMYcx6eoRXnePKT1jVn25ZNeMNJ6828HWk/Bet/4835773
#Function: get events by timeStamp
subpath: $baseUrl/events/timestamp
parameters
since: start time of event occurrence, timeStamp >= since will be shown
limit: each page size, default is 25
sort: sort Field, default is sort by timeStamp descending order
start: start page, default is 1
contract: contract address
Example: http://127.0.0.1:8080/events/timestamp?since=1544483426749&limit=1&start=1&sort=timeStamp
#Function: get confirm events list
subpath: $baseUrl/events/confirmed
parameters
since: start time of event occurrence, timeStamp >= since will be shown
limit: each page size, default is 25
sort: sort Field, default is sort by timeStamp descending order
start: start page, default is 1
Example: http://127.0.0.1:8080/events/confirmed?since=1544483426749&limit=1&start=1&sort=timeStamp
#Function: get block by block hash
subpath: $baseUrl/blocks/{hash}
parameters
hash: block hash
Example: http://127.0.0.1:8080/blocks/000000000049c11f15d4e91e988bc950fa9f194d2cb2e04cda76675dbb349009
#Function: get block list
subpath: $baseUrl/blocks
parameters
limit: each page size, default is 25
sort: sort Field, default is sort by timeStamp descending order
start: start page, default is 1
block: block number, block number >= block will be shown
Example: http://127.0.0.1:8080/blocks?limit=1&sort=timeStamp&start=0&block=0
#Function: get latest block number
subpath: $baseUrl/blocks/latestSolidifiedBlockNumber
parameters
none
Example: http://127.0.0.1:8080/blocks/latestSolidifiedBlockNumber
#Function: get contract log list
subpath: $baseUrl/contractlogs
parameters
limit: each page size, default is 25
sort: sort Field, default is sort by timeStamp descending order
start: start page, default is 1
block: block
Last updated