chainindex

package module
v0.0.0-...-5038352 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README

Crypto.com Chain Indexing Service

Crypto.com Chain Indexing Service (chainindex) is a service to index all publicly available data on Crypto.com chain and persist structured information into storage.

Right now it supports Postres database and provides RESTful API as query interface.

1. Build

1.1 Build using Docker

Using Docker is the easiest way to build chainindex. The Docker image contains /app/chainindex Compiled chainindex binary /app/migrate Program to perform migration

docker build -o chainindex .
1.2 Build manually
Prerequisite
make all

2. How to Run

2.1 Prerequisite
  • Crypto.com Chain full node
  • Postgres Database
2.2 Configuration file

A sample configuration is available under config/config.sample.toml.

Copy it, update configuration based on your setup and rename it as config/config.toml.

Note: Postgres database password is not available in config.toml nor command option. You must provide it as environment variable DB_PASSWORD on start.

2.3 Postgres Database

You can have your Postgres setup locally or remotely.

Run Postgres with Docker

WARNING: The docker files available under docker/ is intended only for development and testing purpose only. Never use them in production setup.

For a local test run. A docker-compose file with Postgres database and PgAdmin console is available via running:

docker-compose --file docker/docker-compose.development.yml up -d

This will start the following docker instances on your local network when you use default credentials:

Docker image Port Username Password Other Config Mounted volume
Postgres 5432 postgres postgres Database Name = postgres; SSL = true ./pgdata-dev
PgAdmin 8080 pgadmin@localhost pgadmin N/A N/A
2.4 Execute Database Migration
Docker
docker run -it \
    --env DB_USERNAME=postgres \
    --env DB_PASSWORD=postgres \
    --env DB_HOST=host.docker.internal \
    --env DB_PORT=5432 \
    --env DB_NAME=postgres \
    --env DB_SCHEMA=public \
    chainindex /app/migrate -- -verbose up
Manual Build
./migrate.sh -- -verbose up
2.5 Run the Service
Docker
docker run \
    -v `pwd`/config:/app/config --read-only \
    -p 28857:28857 \
    --env DB_PASSWORD=postgres \
    chainindex /app/chainindex
Manual build
env DB_PASSWORD=postgres ./chainindex

3. Test

./test.sh [--install-dependency] [--no-db] [--watch]

Providing --install-dependency will attempt to install test runner Ginkgo if it is not installed before.

4. Lint

Prerequisite
./lint.sh

5. Contributing

Please abide by the Code of Conduct in all interactions, and the contributing guidelines when submitting code.

6. License

Apache 2.0

Documentation

Index

Constants

View Source
const (
	COUNCIL_NODE_UPDATE_TYPE_LEFT = iota
)
View Source
const (
	MAX_COIN_DECIMALS = 1_0000_0000
)

Variables

View Source
var (
	MAX_COIN_DECIMALS_BIGFLOAT = big.NewFloat(MAX_COIN_DECIMALS)
)

Functions

func CROStrToCoin

func CROStrToCoin(cro string) (*big.Int, error)

func CROToCoin

func CROToCoin(cro *big.Float) (*big.Int, error)

func MustCROStrToCoin

func MustCROStrToCoin(cro string) *big.Int

func MustCROToCoin

func MustCROToCoin(cro *big.Float) *big.Int

Types

type Activity

type Activity struct {
	BlockHeight                uint64
	Type                       ActivityType
	MaybeTxID                  *string
	MaybeEventPosition         *uint32
	MaybeFee                   *big.Int
	MaybeTxInputs              []TxInput
	MaybeOutputCount           *uint32
	MaybeStakingAccountAddress *string
	MaybeStakingAccountNonce   *uint64
	MaybeBonded                *big.Int
	MaybeUnbonded              *big.Int
	MaybeUnbondedFrom          *time.Time
	MaybeCouncilNodeMeta       *CouncilNode
	MaybeAffectedCouncilNode   *CouncilNode
	MaybeJailedUntil           *time.Time
	MaybePunishmentKind        *PunishmentKind
}

func (*Activity) String

func (activity *Activity) String() string

type ActivityType

type ActivityType = uint8
const (
	ACTIVITY_GENESIS ActivityType = iota
	ACTIVITY_TRANSFER
	ACTIVITY_DEPOSIT
	ACTIVITY_UNBOND
	ACTIVITY_WITHDRAW
	ACTIVITY_NODEJOIN
	ACTIVITY_UNJAIL
	ACTIVITY_REWARD
	ACTIVITY_SLASH
	ACTIVITY_JAIL
	ACTIVITY_NODEKICKED
)

type Block

type Block struct {
	Height  uint64
	Hash    string
	Time    time.Time
	AppHash string
}

func (*Block) String

func (block *Block) String() string

type BlockReward

type BlockReward struct {
	BlockHeight uint64
	Minted      *big.Int
}

func (*BlockReward) String

func (reward *BlockReward) String() string

type BlockSignature

type BlockSignature struct {
	BlockHeight        uint64
	CouncilNodeAddress string
	Signature          string
	IsProposer         bool
}

func (*BlockSignature) String

func (signature *BlockSignature) String() string

type CouncilNode

type CouncilNode struct {
	Id                         *uint64
	Name                       string
	MaybeSecurityContact       *string
	PubKeyType                 PubKeyType
	PubKey                     string
	Address                    string
	CreatedAtBlockHeight       uint64
	MaybeLastLeftAtBlockHeight *uint64
}

func (*CouncilNode) String

func (node *CouncilNode) String() string

type CouncilNodeRepository

type CouncilNodeRepository interface {
	Store(*CouncilNode) (id uint32, err error)
	FindById(id uint32) (*CouncilNode, error)
}

type CouncilNodeUpdate

type CouncilNodeUpdate struct {
	Address string
	Type    uint8
}

func (*CouncilNodeUpdate) String

func (update *CouncilNodeUpdate) String() string

type CouncilNodeUpdateType

type CouncilNodeUpdateType = uint8

type EventType

type EventType = int8
const (
	EVENT_REWARD EventType = iota
	EVENT_SLASH
	EVENT_JAIL
)

type PubKeyType

type PubKeyType = int8
const (
	PUBKEY_TYPE_ED25519 PubKeyType = iota
)

type PunishmentKind

type PunishmentKind = uint8
const (
	PUNISHMENT_KIND_NON_LIVE PunishmentKind = iota
	PUNISHMENT_KIND_BYZANTINE_FAULT
)

type StakingAccount

type StakingAccount struct {
	Address                 string
	Nonce                   uint64
	Bonded                  *big.Int
	Unbonded                *big.Int
	MaybeUnbondedFrom       *time.Time
	MaybePunishmentKind     *PunishmentKind
	MaybeJailedUntil        *time.Time
	MaybeCurrentCouncilNode *CouncilNode
}

func (*StakingAccount) String

func (account *StakingAccount) String() string

type StakingAccountRepository

type StakingAccountRepository interface {
	Store(*StakingAccount) error
	FindByAddress(string) (*StakingAccount, error)
}

type TransactionOutput

type TransactionOutput struct {
	TxId               string
	Index              uint32
	SpentAtBlockHeight uint64
}

func (*TransactionOutput) String

func (output *TransactionOutput) String() string

type TransactionType

type TransactionType = int8
const (
	TRANSACTION_TRANSFER TransactionType = iota
	TRANSACTION_DEPOSIT
	TRANSACTION_UNBOND
	TRANSACTION_WITHDRAW
	TRANSACTION_NODEJOIN
	TRANSACTION_UNJAIL
)

type TxInput

type TxInput struct {
	TxId  string
	Index uint32
}

func (*TxInput) String

func (input *TxInput) String() string

Directories

Path Synopsis
Package adapter is an alias of the interface concept in domain driven development.
Package adapter is an alias of the interface concept in domain driven development.
cmd
internal
test

Jump to

Keyboard shortcuts

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