data

package
v0.0.0-...-c096a92 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Hash                string  `json:"hash" gorm:"column:hash"`
	Number              uint64  `json:"number" gorm:"column:number"`
	Time                uint64  `json:"time" gorm:"column:time"`
	ParentHash          string  `json:"parentHash" gorm:"column:parenthash"`
	Difficulty          string  `json:"difficulty" gorm:"column:difficulty"`
	GasUsed             uint64  `json:"gasUsed" gorm:"column:gasused"`
	GasLimit            uint64  `json:"gasLimit" gorm:"column:gaslimit"`
	Nonce               string  `json:"nonce" gorm:"column:nonce"`
	Miner               string  `json:"miner" gorm:"column:miner"`
	Size                float64 `json:"size" gorm:"column:size"`
	StateRootHash       string  `json:"stateRootHash" gorm:"column:stateroothash"`
	UncleHash           string  `json:"uncleHash" gorm:"column:unclehash"`
	TransactionRootHash string  `json:"txRootHash" gorm:"column:txroothash"`
	ReceiptRootHash     string  `json:"receiptRootHash" gorm:"column:receiptroothash"`
	ExtraData           []byte  `json:"extraData" gorm:"column:extradata"`
}

Block - Block related info to be delivered to client in this format

func (*Block) MarshalBinary

func (b *Block) MarshalBinary() ([]byte, error)

MarshalBinary - Implementing binary marshalling function, to be invoked by redis before publishing data on channel

func (*Block) MarshalJSON

func (b *Block) MarshalJSON() ([]byte, error)

MarshalJSON - Custom JSON encoder

func (*Block) ToJSON

func (b *Block) ToJSON() []byte

ToJSON - Encodes into JSON, to be supplied when queried for block data

type BlockChainNodeConnection

type BlockChainNodeConnection struct {
	RPC       *ethclient.Client
	Websocket *ethclient.Client
}

BlockChainNodeConnection - Holds network connection object for blockchain nodes

Use `RPC` i.e. HTTP based connection, for querying blockchain for data Use `Websocket` for real-time listening of events in blockchain

type Blocks

type Blocks struct {
	Blocks []*Block `json:"blocks"`
}

Blocks - A set of blocks to be held, extracted from DB query result also to be supplied to client in JSON encoded form

func (*Blocks) ToJSON

func (b *Blocks) ToJSON() []byte

ToJSON - Encoding into JSON, to be invoked when delivering query result to client

type Event

type Event struct {
	Origin          string         `gorm:"column:origin"`
	Index           uint           `gorm:"column:index"`
	Topics          pq.StringArray `gorm:"column:topics;type:text[]"`
	Data            []byte         `gorm:"column:data"`
	TransactionHash string         `gorm:"column:txhash"`
	BlockHash       string         `gorm:"column:blockhash"`
}

Event - Single event entity holder, extracted from db

func (*Event) MarshalBinary

func (e *Event) MarshalBinary() ([]byte, error)

MarshalBinary - Implementing binary marshalling function, to be invoked by redis before publishing data on channel

func (*Event) MarshalJSON

func (e *Event) MarshalJSON() ([]byte, error)

MarshalJSON - Custom JSON encoder

func (*Event) ToJSON

func (e *Event) ToJSON() []byte

ToJSON - Encoding into JSON

type Events

type Events struct {
	Events []*Event `json:"events"`
}

Events - A collection of event holder, to be delivered to client in this form

func (*Events) ToJSON

func (e *Events) ToJSON() []byte

ToJSON - Encoding to JSON

type Job

type Job struct {
	Client *ethclient.Client
	DB     *gorm.DB
	Redis  *RedisInfo
	Block  uint64
	Status *StatusHolder
}

Job - For running a block fetching job

type RedisInfo

type RedisInfo struct {
	Client                                               *redis.Client
	BlockPublishTopic, TxPublishTopic, EventPublishTopic string
}

RedisInfo

type ResultStatus

type ResultStatus struct {
	Success uint64
	Failure uint64
}

ResultStatus

func (ResultStatus) Total

func (r ResultStatus) Total() uint64

Total - Returns total count of operations which were supposed to be performed

To check whether all go routines have sent their status i.e. completed their tasks or not

type StatusHolder

type StatusHolder struct {
	State *SyncState
	Mutex *sync.RWMutex
}

StatusHolder - Keeps track of progress. To be delivered when `/v1/synced` is queried

func (*StatusHolder) BlockCountInDB

func (s *StatusHolder) BlockCountInDB() uint64

BlockCountInDB - thread safe reads currently present blocks in db

func (*StatusHolder) Done

func (s *StatusHolder) Done() uint64

Done - thread safe #-of Blocks processed during uptime i.e. after last time it started

func (*StatusHolder) ElapsedTime

func (s *StatusHolder) ElapsedTime() time.Duration

ElapsedTime - thread safe uptime of the service

func (*StatusHolder) GetLatestBlockNumber

func (s *StatusHolder) GetLatestBlockNumber() uint64

GetLatestBlockNumber - thread safe read latest block number

func (*StatusHolder) IncrementBlocksInserted

func (s *StatusHolder) IncrementBlocksInserted()

IncrementBlocksInserted - thread safe increments number of blocks inserted into DB since start

func (*StatusHolder) IncrementBlocksProcessed

func (s *StatusHolder) IncrementBlocksProcessed()

IncrementBlocksProcessed - thread safe increments number of blocks processed by after it started

func (*StatusHolder) MaxBlockNumberAtStartUp

func (s *StatusHolder) MaxBlockNumberAtStartUp() uint64

MaxBlockNumberAtStartUp - thread safe read latest block number at the time of service start To determine whether a missing block related notification needs to be sent on a pubsub channel or not

func (*StatusHolder) SetLatestBlockNumber

func (s *StatusHolder) SetLatestBlockNumber(num uint64)

SetLatestBlockNumber - thread safe write latest block number

func (*StatusHolder) SetStartedAt

func (s *StatusHolder) SetStartedAt()

SetStartedAt - Sets started at time

type SyncState

type SyncState struct {
	Done                    uint64
	StartedAt               time.Time
	BlockCountAtStartUp     uint64
	MaxBlockNumberAtStartUp uint64
	NewBlocksInserted       uint64
	LatestBlockNumber       uint64
}

SyncState - Whether the service is synced with blockchain or not

func (*SyncState) BlockCountInDB

func (s *SyncState) BlockCountInDB() uint64

BlockCountInDB - Blocks currently present in database

type Transaction

type Transaction struct {
	Hash      string `json:"hash" gorm:"column:hash"`
	From      string `json:"from" gorm:"column:from"`
	To        string `json:"to" gorm:"column:to"`
	Contract  string `json:"contract" gorm:"column:contract"`
	Value     string `json:"value" gorm:"column:value"`
	Data      []byte `json:"data" gorm:"column:data"`
	Gas       uint64 `json:"gas" gorm:"column:gas"`
	GasPrice  string `json:"gasPrice" gorm:"column:gasprice"`
	Cost      string `json:"cost" gorm:"column:cost"`
	Nonce     uint64 `json:"nonce" gorm:"column:nonce"`
	State     uint64 `json:"state" gorm:"column:state"`
	BlockHash string `json:"blockHash" gorm:"column:blockhash"`
}

Transaction - Transaction holder struct, to be supplied when queried using tx hash

func (*Transaction) MarshalBinary

func (t *Transaction) MarshalBinary() ([]byte, error)

MarshalBinary - Implementing binary marshalling function, to be invoked by redis before publishing data on channel

func (*Transaction) MarshalJSON

func (t *Transaction) MarshalJSON() ([]byte, error)

MarshalJSON - Custom JSON encoder

func (*Transaction) ToJSON

func (t *Transaction) ToJSON() []byte

ToJSON - JSON encoder, to be invoked before delivering tx query data to client

type Transactions

type Transactions struct {
	Transactions []*Transaction `json:"transactions"`
}

Transactions - Multiple transactions holder struct

func (*Transactions) ToJSON

func (t *Transactions) ToJSON() []byte

ToJSON - Encoding into JSON, to be invoked when delivering to client

Jump to

Keyboard shortcuts

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