Event Subscribe

This article mainly explains the event plug-in deployment steps, including: MongoDB, Vision event subscribe plugin, Vision Event Query Service deployment commands, and detailed introduction to the Vision Event Query Service interface.

Suggested Configuration

  • CPU/ RAM: 16Core / 32G
  • DISK: 500G
  • System: CentOS 64/Ubuntu 16.04+

Plugin logic

  • Vision event subscribe plugin's function is to get event information from nodes and store it in MongoDB
  • MongoDB's function is to save event information
  • The function of Vision Event Query Service is to provide the encapsulated http interfaces to get event information from MongoDB.

Deploy Vision event subscribe plugin

#Deployment
git clone https://github.com/vision-consensus/vision-event-plugin.git
cd vision-event-plugin
./gradlew build

Configuration file -- Field parsing

  • path: is the absolute path of "plugin-mongodb-1.0.0.zip"
  • server: ip:port (mongodb)
  • dbconfig: mongodb configuration
  • topics: event type
  • triggerName: the trigger type, the value can't be modified
  • enable: receive or not, set true or false
  • topic: the value is mongodb collection to receive events
event.subscribe = {
  native = {
    useNativeQueue = false // if true, use native message queue, else use event plugin.
    bindport = 5555 // bind port
    sendqueuelength = 1000 //max length of send queue
  }
  path = "/data/vision/mongoplugin/plugin-mongodb-1.0.0.zip" // absolute path of plugin
  server = "127.0.0.1:37017" // target server address to receive event triggers
  dbconfig = "eventlog|vision|123456" // dbname|username|password
  contractParse = true,
  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"
    },
    {
      triggerName = "solidity" // solidity block event trigger, the value can't be modified
      enable = true            // the default value is true
      topic = "solidity"
    },
    {
      triggerName = "solidityevent"
      enable = true
      topic = "solidityevent"
    },
    {
      triggerName = "soliditylog"
      enable = true
      topic = "soliditylog"
    }
  ]
  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.
    ]
  }
}

Deploy Vision Event Query Service

#Deployment
git clone https://github.com/vision-consensus/vision-event-query.git 
cd vision-event-query
docker-compose -d up

Configuration file -- Field parsing

  • MONGO_HOST: host ip, not use localhost or 127.0.0.1
  • (optional) MONGO_PORT: for visioneventquery access mongodb, if modified, keep same with mongodb's port.
  • (optional) MONGO_INITDB_DATABASE:the database to record event logs, if modified, keep same with visioneventquery.
  • (optional) MONGO_DATEBASE_USERNAME:username to access database, if modified, keep same with visioneventquery.
  • (optional) MONGO_DATEBASE_PASSWORD:password to access database, if modified, keep same with visioneventquery.
version: '2.2'

services:
  mongodb:
    image: 'mongo:4.0'
    environment:
      MONGO_INITDB_ROOT_USERNAME: "root"   #the root username in mongodb
      MONGO_INITDB_ROOT_PASSWORD: "123456" #the raot password in mongodb
      MONGO_INITDB_DATABASE: "eventlog"    #the database of event log in mongodb
      MONGO_DATEBASE_USERNAME: "vision"    #the username of database event log
      MONGO_DATEBASE_PASSWORD: "123456"    #the password of database event log
    ports:
      - "37017:27017" # keep same with visioneventquery's parameter MONGO_PORT
    volumes:
      - 'mongodb_data:/data/db'
      - './mongo_init.sh:/docker-entrypoint-initdb.d/mongo_init.sh'
    networks:
      - eventquery

  visioneventquery:
    build:
      context: ./
    volumes:
      - 'eq_data:/usr/app'
    ports:
      - "8080:8080"
    environment:
      EQ_JAVA_OPTS: "-Xmx256m"
      MONGO_HOST: "192.168.2.239"        # should be replaced by machine ip address
      MONGO_PORT: "37017"                # same with the mongodb mapping port
      MONGO_INITDB_DATABASE: "eventlog"  # keep same with mongodb's parameter MONGO_INITDB_DATABASE
      MONGO_DATEBASE_USERNAME: "vision"  # keep same with mongodb's parameter MONGO_DATEBASE_USERNAME
      MONGO_DATEBASE_PASSWORD: "123456"  # keep same with mongodb's parameter MONGO_DATEBASE_PASSWORD
    networks:
      - eventquery
    depends_on:
      - mongodb

networks:
  eventquery:
    driver: bridge

volumes:
  mongodb_data:
    driver: local
  eq_data:
    driver: local

Load plugin in Vision and verification

#1、start event server firstly (details as above chapter Deploy Vision Event Query Service)
docker-compose -d up

#2、After configured the confifuration of Fullnode, start fullnode with parameter "--es" to run plugin process
java -jar FullNode.jar -c config.conf --es

#2、verify the plugin status
tail -f logs/vision.log |grep -i eventplugin
#appears below the word is successful
#o.t.c.l.EventPluginLoader 'your plugin path/plugin-mongodb-1.0.0.zip' loaded

#3、Verify whether event server running well
http://localhost:8080/blocks

Use Event Query Service

  • Main HTTP Service
** baseUrl: localhost

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://baseUrl/transactions?limit=1&sort=-timeStamp&start=2&block=0


Function: get transaction by hash
subpath: $baseUrl/transactions/{hash}
parameters   
hash: transaction id
Example: http://baseUrl/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://baseUrl/transfers?token=vs&limit=1&sort=timeStamp&start=2&block=0&from=VYKDHeQfG38C62Xo8tHLrGWiw5o9hL3QEK&to=TAEcoD8J7P5QjWT32r31gat8L7Sga2qUy8


Function: get transfers by transactionId
subpath: $baseUrl/transfers/{hash}
parameters   
hash: transfer hash
Example: http://baseUrl/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://baseUrl/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://baseUrl/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://baseUrl/events/VYKDHeQfG38C62Xo8tHLrGWiw5o9hL3QEK?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://baseUrl/events/contract/VYKDHeQfG38C62Xo8tHLrGWiw5o9hL3QEK/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://baseUrl/events/contract/VYKDHeQfG38C62Xo8tHLrGWiw5o9hL3QEK/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://baseUrl/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://baseUrl/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://baseUrl/blocks/000000000049c11f15d4x91e988bc950fa9f194d2cb2e04cda76675dbb349009


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://baseUrl/blocks?limit=1&sort=timeStamp&start=0&block=0


Function: get latest block number
subpath: $baseUrl/blocks/latestSolidifiedBlockNumber
parameters   
none
Example: http://baseUrl/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 number, block number >= block will be shown 
Example: http://baseUrl/contractlogs


Function: get contract log list based on transactionId
subpath: $baseUrl/contractlogs/transaction/{transactionId}
parameters   
transactionId
Example: http://baseUrl/contractlogs/transaction/{transactionId}


Function: post abi string and get contract log list based on transactionId
subpath: $baseUrl/contract/transaction/{transactionId}
parameters   
transactionId
body:
abi: user self upload abi
Example: http://baseUrl/contract/transaction/{transactionId}


Function: get contract log list based on contractAddress
subpath: $baseUrl/contractlogs/contract/{contractAddress}
parameters   
contractAddress
Example: http://baseUrl/contractlogs/contract/{contractAddress}


Function: post abi string and get contract log list based on contractAddress
subpath: $baseUrl/contract/contractAddress/{contractAddress}
parameters   
contractAddress
abi: user self upload abi
Example: http://baseUrl/contract/contractAddress/{contractAddress}


Function: get contract log list based on uniqueId
subpath: $baseUrl/contractlogs/uniqueId/{uniqueId}
parameters   
uniqueId
Example: http://baseUrl/eventquery/contractlogs/uniqueId/{uniqueId}


Function: post abi string and get contract log list based on uniqueId
subpath: $baseUrl/contract/uniqueId/{uniqueId}
parameters   
uniqueId
abi: user self upload abi
Example: http://baseUrl/contract/uniqueId/{uniqueId}