Guidelines
- Introduction
- Installation
- Quick Start
Guides
- Introductions
- Build local test node
- Smart Contract - ABI Files
- Smart Contract——JS Contract
- Deploy Contracts
- Test Contract
- Develop DApp Client
Smart Contracts
- Contract Introduction
- ABI File
- Database
- Account Authority
- Call In-contract
- Notification
System Contracts
- Resources
- Account
- Permission
Token Contracts
- Transfer
- Token
- Token Exchange
- Contract Sub-Wallet
Node Guide
- Node Introduction
- Add to nodes network
- Node Data Persistence
Access Guide
- FO 接入安全指南
Node Data Persistence
In buisness, we often have needs to query history data, such as: a certain account’s transfer history, but considering performance, performing self historic data query in EOS is not a great solution, also EOS’ history API module has slow iterations, even about to be abandoned.
If the data onchain can be real-time synced locally, seperating node services and buisness query, then efficiency can be greatly improved.
In FIBOS, we offer three solutions for you to choose for your own scenario.
Emitter Plug In
emitter is an event listening plugin, can easily listen to events of transaction, block, and irreversible_block. You can use it to listen in, and store the corresponding data according to your own needs.
Advantages
- No restrictions such as that of mongo plugins, and have the ability to store data according to your business needs.
- Compared to history plugin, uses less RAM.
Usage
Open the working directory node.js
and add the emitter plugin:
1 | var fibos = require('fibos'); |
Operate FIBOS runtime environment
1 | fibos node.js |
eosio
already started block production, print transaction, block, and irreversible_block data obtain.
Next, synch and swave the data to MySql database, the steps are as follows:
- Connect MySql Database
Use db.open or db.openMySQL to create, the create method:
1 | var mysql = db.openMySQL('mysql://user:pass@host/db'); |
- Run a sql command and return the result, can format string based on parameters
1 | mysql.execute(String sql,...args); |
Call Parameters:
sql:String,formatted string, optional parameters specified with ?. Example: ‘INSERT INTO TABLENAME (name…) VALUES (value);’
args:…,Optional parameter list
1 | var fibos = require('fibos'); |
Other
Data on the block can not only be saved to MySql database, it can also be sync and sacved to other databses under the db module
.
Example:
- sqlite
mongodbnote that emitter does not support mongob. Because it supports EOS’ mongodb plugin, FIBJS disabled the mongodb plugin.leveldb
- Redis
fibos-tracker framework
fibos-tracker is a FIBOS blockchain data GraphQL API service framework, realized based off fib-app, current version is v1.1.0.
Project Website: https://github.com/FIBOSIO/fibos-tracker
Its main functions are:
- Provide emitter listening events to FIBOS block date
- Provide http service, supports call of GraphQL
- Supports using ORM model to customize own data model model, custom data table and custom hook listening data
Quick Installation
1 | fibos --install fibos-tracker |
Framework clarification
Framework defaultly saves block, transaction and actions base data
blocks table data
Field | Type | Note |
---|---|---|
id | Number | Self-Growing id |
block_num | Number | Block Height |
block_time | Date | Block Date |
producer_block_id | String | block hash |
producer | String | block producer |
status | String | Reversible status |
createdAt | Date | Record creation time |
updatedAt | Date | Record update time |
transactions table data
Field | Type | Note |
---|---|---|
id | Number | Self-Growing id |
trx_id | String | Transaction hash |
rawData | JSON | Raw Data |
block_id | String | Block Height (Links blocks) |
createdAt | Date | Record creation time |
updatedAt | Date | record update time |
actions table data
Field | Type | Note |
---|---|---|
id | Number | Self-Growing id |
contract_name | String | Contract Name |
action | String | action Name |
authorization | Array | authorize account |
data | JSON | Transaction data |
transaction_id | Number | Transaction id (Regard Table transactions) |
parent_id | Number | parent action id (Regard Table actions) |
createdAt | Date | Record creation time |
updatedAt | Date | Record update time |
API Introduction
Tracker.Config
Config is global attribute of Tracker, it can be used to quickly modify settings, such as: modify the storage engine configuration.
Example:
1 | const Tracker = require("fibos-tracker"); |
name | desc | default |
---|---|---|
DBconnString | Data storage engine | Default use SQLite storage engine |
isFilterNullBlock | Whether to filter empty blocks | Default true |
isSyncSystemBlock | Whether to store default data | Default false |
tracker.app
fib-app instance app object, for details please refer to fib-app documentation.
tracker.app object supports rounting access.
Example:
1 | const http = require("http"); |
tracker.emitter
Uses with action plugin of FIBOS.
Example:
1 | const fibos = require("fibos"); |
params | type | desc |
---|---|---|
fibos | fibos object | / |
tracker.diagram
Generate data table associated diagram, if self-defined data tabled, must call tracker.use then run.
Example:
1 | const Tracker = require("fibos-tracker"); |
tracker.stop
Safe stops tracker
Example:
1 | const Tracker = require("fibos-tracker"); |
tracker.use
Self-define hook listening data, use ORM model to define DB storage and process.
Example:
1 | const fibos = require("fibos"); |
defines supports arrays, fulfills operational senarios that some model requires multiple tables.
tracker.use Parameter Definitions:
params | type | desc |
---|---|---|
model | Object | Custom data object, includes defines and hook |
model
Parameter Definitions
key | type | desc | params |
---|---|---|---|
defines | Function | Use ORM model to define data table, provides API access | (db) => {} parameter db is ORM object,can be used to operate data layers |
hooks | Function | supports filter of action data’s hook function | (db, messages) => {} parameter db is ORM object,messages is action Raw data collection |
hooks filter rules clarification:
- filter certain contract, such as:
eosio.token
- filter certain action of contract, such as:
eosio.token/transfer
hooks messages data clarification:
For easy hooks development, pass of messages is optimized:
- All action that satisfy the filter rule are merged into an array to pass
- All action in array that satisfy the filter rule including this layer action and all below layer inline_action, if there are action in above layers, will carry parent attribute, identifu]y the action data of the upper parent.
Note: Each layer parent_id
is the DB self-growth id of the level’s action
.
Example return structure:
1 | [ |
tracker.Queues
When tracker is handling event data, it will first be saved to the queue. When you are restoring data or resetting environment, it is suggested to clean up the environment.
Example:
1 | const fibos = require("fibos"); |
Quick Application
After understanding fibos-tracker, let us start writing, using framework to write a blockchain data storage display application.
Integrating with FIBOS’ emitter, create an application. It can sync FIBOS TestNet network block data, and use GraphQL to obtain application data.
Prepare Environment
- Install FIBOS
- Prepare sample directory
1 | :$ mkdir example;cd example |
Write Example
genesis.json is the network config of FIBOS TestNet.
index.js :
1 | const http = require("http"); |
Startup Services
1 | fibos index.js |
Return the following means startup is sucessful, and is sync writing data.
1 | putLog emitter-running: 1.54080331e+12ms |
Use GraphQL method to obtain application data
- FIBOS GraphQL Client
fibjs Example:
1 | const http = require("http"); |
- Web GraphQL Client
jQuery Ajax Example:
1 | let graphql = function(body) { |
GraphQL Get application - data list
1 | graphql(` |
GraphQL Get application - detail data
1 | graphql(` |
For more detailed information and high level usage and examples of the framework, please visit project website
mongoDB Plugin
EOS itself provides pljug in for mongoDB (eosio::mongo_db_plugin), FIBOS also uses this feature. The implementation principle of this module is synching the block data to mongoDB. This makes mongoDB a centralized data storage.
We will start locally a FIBOS node service, creating account and query within mongoDB.
Start mongod service
If you have not installed mongoDB, please refer to Install mongoDB Community Edition.
First we will start the mongod service, the command is a follows:
1 | fibos$ mongod |
If it returns the following, it means startup of mongod service is successful.
1 | 2018-08-08T09:52:09.459+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none' |
Start FIBOS Runtime
If you have not installed FIBOS, please refer to Install runtime environment.
To sync data to mongoDB, all thats needed is to add fibos.load('mongo_db')
to the code in the getting started tutorial, loading the mongo_db module into FIBOS. Only with three lines, FIBOS will sync block data automatically to mongoDB. Its very convieniant.
The port number and database name can be changedm in this tutorial the port number is 27017, and the database name is eosmain. The following code is saved to ./local/node.js
.
1 | var fibos = require('fibos'); |
Start FIBOS Runtime:
1 | fibos$ fibos ./local/node.js |
After startup, we will see the following return in the mongd logs:
1 | 2018-08-08T11:33:42.867+0800 I NETWORK [listener] connection accepted from 127.0.0.1:54259 #2 (2 connections now open) |
Through the log we can see that FIBOS has done the following for us:
- Create collections: accounts, actions, block_states, transaction_traces, transactions
- Create the necessary indexes for each collection
We go into mongoDB’s client mongo to query, and we see that the eosmain database was successfully created:
1 | > show dbs |
Going to the eosmain database, we find that FIBOS has created 5 collections in mongoDB:
1 | > use eosmain |
We can directly query data from the accounts collection:
1 | > db.accounts.find() |
and will find that a system account eosio’s data has already been synched to mongoDB.