iotex-analyser

command module
v1.17.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

README

Overview

IoTeX Analyzer is a project developed by the IoTeX team to enable asynchronous analysis of IoTeX blockchain data. It allows for indexing the data on the IoTeX blockchain and storing it in a database of your choice among MySQL, PostgreSQL, or SQLite3. Additionally, any other storage can be supported by writing a plugin.

Technical architecture of Iotex analyser

Feature

With iotex-analyser, you can deploy your plugins without any downtime and dynamically load and unload them. The plugins directory includes several basic functions, and you can write your own plugins to customize and enhance the desired functionality.

Running using Docker Compose

docker-compose up

Building from source

Build

Clone this repository and build the service including plugins with:

git clone https://github.com/iotexproject/iotex-analyser.git
cd iotex-analyser
make

Or build the service only with:

make build
Run

You need to create the database before you start server. Below, we use docker to run a Postgres database service:

docker run --name postgres12 -e POSTGRES_PASSWORD=admin --publish 5432:5432 -d postgres:12-alpine

Below we show a simple config.ymlfor the IoTeX Analyser service:

server:
  #loaded default plugin list
  plugins:
    - block.so
#database config
database:
  driver: postgres
  host: 127.0.0.1
  port: 5432
  user: postgres
  password: admin
  name: test
iotex:
  chainEndPoint: api.testnet.iotex.one:80
blockDB:
  dbPath: chain.db
log:
  zap:
    level: info

where:ì for chain.db we can use the snapshot with index data:

Commands

Start IoTeX Analyser with:

./iotex-analyser -c config.yml server

Dynamically load a plugin with:

./iotex-analyser -c config.yml plugin load simple.so

Dynamically unload a plugin with:

./iotex-analyser -c config.yml plugin unload simple.so

List running plugins with:

./iotex-analyser -c config.yml plugin info

GraphQL Support

Hasura is a GraphQL Engine, a tool that places a GraphQL API in front of a PostgreSQL Database.

Hasura Console: https://iotexscout.io/hasura/console

GraphQL Endpoint: https://iotexscout.io/hasura/v1/graphql

plugin lists

Creating plugins

Any plugin is required to be implemented according to the following adapter interface:

type Adapter interface {
	Name() string
	Version() string
	Type() Type
	Start(context.Context) error
	Stop(context.Context) error
	PutBlock(context.Context, *block.Block) error
}

The following code (included in simple/simple.go) demonstrates how to write a simple plugin:

package main

import (
	"context"

  "github.com/iotexproject/iotex-analyser/db"
	"github.com/iotexproject/iotex-analyser/plugin"
	"github.com/iotexproject/iotex-core/v2/blockchain/block"
)

type simplePlugin struct {
}

func (b simplePlugin) Name() string {
	return "simple"
}

func (b simplePlugin) Type() plugin.Type {
	return plugin.TypeStandard
}

func (b simplePlugin) Start(ctx context.Context) error {
	return nil
}

func (b simplePlugin) PutBlock(ctx context.Context, blk *block.Block) error {
  fmt.Printf("block height: %d\n", blk.Height())
  // sync update indexer height
  return db.UpdateIndexHeight(b.Name(), blk.Height())
}

func (b simplePlugin) Stop(ctx context.Context) error {
	return nil
}

func (b simplePlugin) Version() string {
	return "0.0.1"
}

// exported
var Plugin = simplePlugin{}

Build your plugin
make plugin name=simple

This will generates a file of simple.so in the current directory, and then load and run the plugin with the following command.

./iotex-analyser -c config.yml plugin load simple.so

After successfully running the plugin, the server will output something like:

block height: 1
...
block height: 3

License

This project is licensed under the Apache License 2.0.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd
plugins
account_income command
account_meta command
account_vote command
action_type command
block command
block_action command
block_footer command
block_meta command
block_meta_v2 command
block_receipts command
block_reward command
block_supply command
candidate command
candidate_v1 command
candidatelist command
clickhouse command
clickhouse_v1 command
delegate command
delegate_record command
erc1155 command
erc1155_v2 command
erc1967_proxy command
erc20 command
erc20_ch command
erc20_meta command
erc20_v2 command
erc721 command
erc721_v2 command
erc721_v2_ch command
gastracker command
hermes command
illegal_action command
inscription command
metrics command
monitor command
probation command
reward_history command
staking_actions command
staking_bucket command
verifying command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL