Git Product home page Git Product logo

codechain-indexer's Introduction

CodeChain Indexer Build Status codecov

A blockchain data indexing tool for CodeChain

Table of Contents

Install

Requirements

The software dependencies required to install and run CodeChain-indexer are:

  • Latest version of the CodeChain
  • PostgreSQL v11.*
  • Nodejs higher than version 10

Download

Download CodeChain-indexer code from the GitHub repository

git clone [email protected]:kodebox-io/codechain-indexer.git
cd codechain-indexer

Install packages

Use yarn package manager to install packages

yarn install

Before start

Dependency

  • Get CodeChain ready with the CodeChain RPC server
  • Get PostgreSQL database ready for indexing block data

Create the database and user on the PostgreSQL

Update configuration

Update ./create_user_and_db.sql and config/* files before creating database schema. If you want to create a production datatabase, please create config/production.json by copying config/dev.json

Mac
# Download postgresql with Homebrew
brew install postgresql
brew services start postgresql

# Create users and databases
psql postgres -f create_user_and_db.sql

# Create tables for production
NODE_ENV=production yarn migrate

# Create tables for development
yarn run migrate
Ubuntu
# Download postgresql
sudo apt install postgresql postgresql-contrib

# Create users and databases
sudo -u postgres psql -f create_user_and_db.sql

# Create tables for production
NODE_ENV=production yarn migrate

# Create tables for development
yarn migrate

Run (for development)

yarn run start

# You can change the host of CodeChain and DB host on the config/dev.json

Check CCCChanges

If you run the Indexer with the environment ENABLE_CCC_CHANGES_CHECK variable, the Indexer checks to see if CCCChanges is well calculated. If you want to receive an email when an error is found, please set the SENDGRID_API_KEY and SENDGRID_TO variables. If you want to receive a slack notification, please set the SLACK_WEBHOOK variable.

Run (for production)

yarn build
NODE_ENV=production node ./build/index.js

# You can change the host of CodeChain and DB host on the config/production.json

Test

# Create the test database
NODE_ENV=test yarn run migrate

# Start testing
yarn run test

API document

NODE_ENV=dev yarn run start

# Swagger UI is running at "http://host:port/api-docs/"

Tools

Delete all database data

yarn run reset

codechain-indexer's People

Contributors

dependabot[bot] avatar foriequal0 avatar joojis avatar kseo avatar majecty avatar misilvia avatar remagpie avatar sgkim126 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

codechain-indexer's Issues

Add a new endpoint for the chart on the explorer

I need some API to draw the chart on the explorer's main page.

/log/count
params

  • filter ( ex block, tx, assetTransfer, assetMint, setRegularKey ... (tx types))
  • date ( ex 2018-09-20)

returns

  • number ( ex 10)

SequelizeDatabaseError: invalid input syntax for type numeric: "0186a0"

This error occurred at 1b68ea1

{ SequelizeDatabaseError: invalid input syntax for type numeric: "0186a0"                                                                                                                                                                
    at Query.formatError (/home/ubuntu/indexer/node_modules/sequelize/lib/dialects/postgres/query.js:363:16)                                                                                                                             
    at query.catch.err (/home/ubuntu/indexer/node_modules/sequelize/lib/dialects/postgres/query.js:86:18)                                                                                                                                
    at tryCatcher (/home/ubuntu/indexer/node_modules/sequelize/node_modules/bluebird/js/release/util.js:16:23)                                                                                                                           
    at Promise._settlePromiseFromHandler (/home/ubuntu/indexer/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:512:31)                                                                                                
    at Promise._settlePromise (/home/ubuntu/indexer/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:569:18)                                                                                                           
    at Promise._settlePromise0 (/home/ubuntu/indexer/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:614:10)                                                                                                          
    at Promise._settlePromises (/home/ubuntu/indexer/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:690:18)                                                                                                          
    at _drainQueueStep (/home/ubuntu/indexer/node_modules/sequelize/node_modules/bluebird/js/release/async.js:138:12)                                                                                                                    
    at _drainQueue (/home/ubuntu/indexer/node_modules/sequelize/node_modules/bluebird/js/release/async.js:131:9)                                                                                                                         
    at Async._drainQueues (/home/ubuntu/indexer/node_modules/sequelize/node_modules/bluebird/js/release/async.js:147:5)                                                                                                                  
    at Immediate.Async.drainQueues [as _onImmediate] (/home/ubuntu/indexer/node_modules/sequelize/node_modules/bluebird/js/release/async.js:17:14)                                                                                       
    at runCallback (timers.js:705:18)                                                                                                                                                                                                    
    at tryOnImmediate (timers.js:676:5)                                                                                                                                                                                                  
    at processImmediate (timers.js:658:5)                                                                                                                                                                                                
    at process.topLevelDomainCallback (domain.js:120:23)                                                                                                                                                                                 
  name: 'SequelizeDatabaseError',                                                                                                                                                                                                        
  parent:                                                                                                                                                                                                                                
   { error: invalid input syntax for type numeric: "0186a0"                                                                                                                                                                              
       at Connection.parseE (/home/ubuntu/indexer/node_modules/pg/lib/connection.js:554:11)                                                                                                                                              
       at Connection.parseMessage (/home/ubuntu/indexer/node_modules/pg/lib/connection.js:379:19)                                                                                                                                        
       at Socket.<anonymous> (/home/ubuntu/indexer/node_modules/pg/lib/connection.js:119:22)                                                                                                                                             
       at Socket.emit (events.js:182:13)                                                                                                                                                                                                 
       at Socket.EventEmitter.emit (domain.js:441:20)                                                                                                                                                                                    
       at addChunk (_stream_readable.js:283:12)                                                                                                                                                                                          
       at readableAddChunk (_stream_readable.js:264:11)                                                                                                                                                                                  
       at Socket.Readable.push (_stream_readable.js:219:10)                                                                                                                                                                              
       at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)                                                                                                                                                           
     name: 'error',                                                                                                                                                                                                                      
     length: 108,                                                                                                                                                                                                                        
     severity: 'ERROR',                                                                                                                                                                                                                  
     code: '22P02',                                                                                                                                                                                                                      
     detail: undefined,                                                                                                                                                                                                                  
     hint: undefined,
     position: '207',
     internalPosition: undefined,
     internalQuery: undefined,
     where: undefined,
     schema: undefined,
     table: undefined,
     column: undefined,
     dataType: undefined,
     constraint: undefined,
     file: 'numeric.c',
     line: '621',
     routine: 'numeric_in',
     sql:
      'INSERT INTO "Pays" ("transactionHash","receiver","quantity","createdAt","updatedAt") VALUES (\'bb27d1caed7ad9acf82e30810fea166d432d8aa145ce6579f1b06a74d98994be\',\'wccq8hpt3p988eu5ch62zr92wmd5fjfs7rp354vjgay\',\'0186a0\',\'2019-02-01 09:44:00.218 +00:00\',\'2019-02-01 09:44:00.218 +00:00\') RETURNING *;' },
  original:
   { error: invalid input syntax for type numeric: "0186a0"
       at Connection.parseE (/home/ubuntu/indexer/node_modules/pg/lib/connection.js:554:11)
       at Connection.parseMessage (/home/ubuntu/indexer/node_modules/pg/lib/connection.js:379:19)
       at Socket.<anonymous> (/home/ubuntu/indexer/node_modules/pg/lib/connection.js:119:22)
       at Socket.emit (events.js:182:13)
       at Socket.EventEmitter.emit (domain.js:441:20)
       at addChunk (_stream_readable.js:283:12)
       at readableAddChunk (_stream_readable.js:264:11)
       at Socket.Readable.push (_stream_readable.js:219:10)
       at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
     name: 'error',
     length: 108,
     severity: 'ERROR',
     code: '22P02',
     detail: undefined,
     hint: undefined,
     position: '207',
     internalPosition: undefined,
     internalQuery: undefined,
     where: undefined,
     schema: undefined,
     table: undefined,
     column: undefined,
     dataType: undefined,
     constraint: undefined,
     file: 'numeric.c',
     line: '621',
     routine: 'numeric_in',
     sql:
      'INSERT INTO "Pays" ("transactionHash","receiver","quantity","createdAt","updatedAt") VALUES (\'bb27d1caed7ad9acf82e30810fea166d432d8aa145ce6579f1b06a74d98994be\',\'wccq8hpt3p988eu5ch62zr92wmd5fjfs7rp354vjgay\',\'0186a0\',\'2019-02-01 09:44:00.218 +00:00\',\'2019-02-01 09:44:00.218 +00:00\') RETURNING *;' },
  sql:
   'INSERT INTO "Pays" ("transactionHash","receiver","quantity","createdAt","updatedAt") VALUES (\'bb27d1caed7ad9acf82e30810fea166d432d8aa145ce6579f1b06a74d98994be\',\'wccq8hpt3p988eu5ch62zr92wmd5fjfs7rp354vjgay\',\'0186a0\',\'2019-02-01 09:44:00.218 +00:00\',\'2019-02-01 09:44:00.218 +00:00\') RETURNING *;' }
{ code: 103, message: 'DBError' }

Yarn run test fails if the instructions are followed

FAIL test/pending-tx.spec.ts
FAIL test/db-block-interface.spec.ts
FAIL test/mint-transfer.spec.ts
FAIL test/snapshot.spec.ts (31.591s)
FAIL test/wrap-unwrap.spec.ts (5.398s)
FAIL test/store-and-remove.spec.ts (6.713s)
FAIL test/log.spec.ts (13.904s)

Test Suites: 7 failed, 4 passed, 11 total
Tests: 21 failed, 19 passed, 40 total
Snapshots: 0 total
Time: 96.003s
Ran all test suites.

Tested in
Ubuntu 18.04.1 LTS
nodejs v10.15.1
psql (PostgreSQL) 11.1 (Ubuntu 11.1-3.pgdg18.04+1)
codechain commit 7e689aa86d95f100cc121837cb076b4e77e4957f ( Feb 7, 2019 )
index commit e0f5542 ( Feb 3, 2019 )

for more information, please check the link

Add a sync parameter to the API

Now the worker synchronizes the CodeChain and DB on every 10sec. Add waitForRefresh parameter so the user can get the latest data.

InvalidTransaction Error

{ code: 104, message: 'InvalidTransaction' }

Currently, the indexer fails to get an invoice in some cases. (In the corgi network, the TransferAsset tx in the block 1410)

I did some debug, and, I found that the tracker values(the SDK one and the CodeChain one) do match but the hash values don't.

CodeChain log:

#815501000 2019-02-08 22:01:38  http.worker0 INFO tx  Cannot apply InnerTx(0x11f2…9ebe): AssetNotFound(0x410000005ddc08b053c6c943a020f7aae2cd1618f23f2992d4836c855c7c8d0f)
parcel_address_entries ParcelHash: 0x82c1626da1289f38e2f05a7529d3422a2c0aa5980825a443cad6b572f110a3c2
parcel_address_entries ParcelAddress: ParcelAddress { block_hash: 0xd164a4628e0267d4610d4552d43ffd908d35021ce3400e4a1352ffa1334b4a22, index: 0 }

indexer log:

tx hash (ParcelHash):
a983019920bb5da87e76cac900558c8af02d6c6349eb46b7ea41303087c12167
tx tracker (InnerTx):
11f21e6077e2545ef7278ec15c4d5c176d89249e4b78c797345644b9c5279ebe

I need to find why the hash values don't match. It may be an SDK problem.

Normalize transaction table schema.

Currently, the action table has many nullable fields to store handle the various transaction type.
It makes hard to add a new field.
I'll normalize the table schema.

In README, no dependency help commands for linux

In README, the commands for installing dependencies are only for macOS currently.

Please add commands for linux.
such as
sudo apt-get install postgresql-11
/usr/lib/postgresql/11/bin/pg_ctl -D /var/lib/postgresql/11/main -l logfile start
sudo -u postgres psql -f create_user_and_db.sql

Test indexing all types of transactions

  • MintAsset
  • TrransferAsset
  • ChangeAssetScheme
  • IncreaseAssetSupply
  • WrapCCC
  • UnwrapCCC
  • Pay
  • SetRegularKey
  • CreateShard
  • SetShardOwners
  • SetShardUsers
  • Store
  • Remove
  • Custom

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.