consumer

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package consumer provides a consumer for the database. It deals with querying, parsing, and storing logs.

Index

Constants

This section is empty.

Variables

View Source
var ErrTokenDoesNotExist = errors.New("token id does not exist")

ErrTokenDoesNotExist indicates the queried for token does not exist.

Functions

func BoolToUint8 added in v0.0.9

func BoolToUint8(input *bool) *uint8

BoolToUint8 is a helper function to handle bool to uint8 conversion for clickhouse.

func GetAmountUSD added in v0.0.9

func GetAmountUSD(amount *big.Int, decimals uint8, price *float64) *float64

GetAmountUSD computes the USD value of a token amount.

func GetDefiLlamaData added in v0.0.9

func GetDefiLlamaData(ctx context.Context, timestamp int, coinGeckoID *string) (*float64, *string)

GetDefiLlamaData does a get request to defi llama for the symbol and price for a token.

func GetTokenMetadataWithTokenID added in v0.0.9

func GetTokenMetadataWithTokenID(ctx context.Context, timestamp int, tokenID *string) (*float64, *string)

GetTokenMetadataWithTokenID gets the token metadata (symbol, price).

func GetTokenMetadataWithTokenSymbol added in v0.0.9

func GetTokenMetadataWithTokenSymbol(ctx context.Context, timestamp int, tokenSymbol *string) (*float64, *string)

GetTokenMetadataWithTokenSymbol gets the token metadata (symbol, price).

func OpenYaml added in v0.0.9

func OpenYaml(path string) (map[string]string, error)

OpenYaml opens yaml file with coin gecko ID mapping and returns it.

func ToNullString added in v0.0.9

func ToNullString(str *string) sql.NullString

ToNullString is a helper function to convert values to null string.

Types

type BridgeConfigFetcher

type BridgeConfigFetcher struct {
	// contains filtered or unexported fields

} // TODO switch bridge config based on block number

BridgeConfigFetcher is the fetcher for the bridge config contract.

func NewBridgeConfigFetcher

func NewBridgeConfigFetcher(bridgeConfigAddress common.Address, bridgeConfigRef *bridgeconfig.BridgeConfigRef) (*BridgeConfigFetcher, error)

NewBridgeConfigFetcher creates a new config fetcher. Backend must be an archive backend.

func (*BridgeConfigFetcher) GetToken

func (b *BridgeConfigFetcher) GetToken(ctx context.Context, chainID uint32, tokenID *string, blockNumber uint32) (token *bridgeconfig.BridgeConfigV3Token, err error)

GetToken gets the token from the bridge config contract. Requires an archived note.

func (*BridgeConfigFetcher) GetTokenID

func (b *BridgeConfigFetcher) GetTokenID(ctx context.Context, chainID uint32, tokenAddress common.Address) (tokenID *string, err error)

GetTokenID gets the token id from the bridge config contract.

type BridgeParser

type BridgeParser struct {

	// Filterer is the bridge Filterer we use to parse events
	Filterer *bridge.SynapseBridgeFilterer
	// contains filtered or unexported fields
}

BridgeParser parses events from the bridge contract.

func NewBridgeParser

func NewBridgeParser(consumerDB db.ConsumerDB, bridgeAddress common.Address, bridgeConfigFetcher BridgeConfigFetcher, consumerFetcher *Fetcher) (*BridgeParser, error)

NewBridgeParser creates a new parser for a given bridge.

func (*BridgeParser) EventType

func (p *BridgeParser) EventType(log ethTypes.Log) (_ bridgeTypes.EventType, ok bool)

EventType returns the event type of a bridge log.

func (*BridgeParser) ParseAndStore

func (p *BridgeParser) ParseAndStore(ctx context.Context, log ethTypes.Log, chainID uint32) error

ParseAndStore parses the bridge logs and stores them in the database.

nolint:gocognit,cyclop,dupl

type Fetcher

type Fetcher struct {
	// contains filtered or unexported fields
}

Fetcher is the fetcher for the events. It uses GQL.

func NewFetcher

func NewFetcher(fetchClient *client.Client) *Fetcher

NewFetcher creates a new fetcher.

func (Fetcher) FetchLastBlock added in v0.0.11

func (f Fetcher) FetchLastBlock(ctx context.Context, chainID uint32) (uint64, error)

FetchLastBlock fetches the last block that Scribe has stored.

func (Fetcher) FetchLastIndexed added in v0.0.11

func (f Fetcher) FetchLastIndexed(ctx context.Context, chainID uint32, contractAddress string) (uint64, error)

FetchLastIndexed fetches the last indexed block per contract.

func (Fetcher) FetchLogsInRange

func (f Fetcher) FetchLogsInRange(ctx context.Context, chainID uint32, startBlock, endBlock uint64, contractAddress common.Address) ([]ethTypes.Log, error)

FetchLogsInRange fetches logs in a range with the GQL client.

func (Fetcher) FetchTxSender added in v0.0.9

func (f Fetcher) FetchTxSender(ctx context.Context, chainID uint32, txHash string) (string, error)

FetchTxSender fetches the sender of a transaction.

func (Fetcher) TimeToBlockNumber added in v0.0.9

func (f Fetcher) TimeToBlockNumber(ctx context.Context, chainID uint32, startHeight, targetTime uint64) (uint64, error)

TimeToBlockNumber returns the first block number after the given time.

type Parser

type Parser interface {
	// ParseAndStore parses the logs and stores them in the database.
	ParseAndStore(ctx context.Context, log ethTypes.Log, chainID uint32) error
}

Parser parses events and stores them.

type SwapFetcher added in v0.0.9

type SwapFetcher struct {
	// contains filtered or unexported fields
}

SwapFetcher is the fetcher for token data from the swap contract.

func NewSwapFetcher added in v0.0.9

func NewSwapFetcher(swapAddress common.Address, backend bind.ContractBackend) (*SwapFetcher, error)

NewSwapFetcher creates a new swap fetcher. Backend must be an archive backend.

func (*SwapFetcher) GetTokenMetaData added in v0.0.9

func (s *SwapFetcher) GetTokenMetaData(ctx context.Context, tokenIndex uint8) (*string, *uint8)

GetTokenMetaData gets the token from the erc20 token contract given a swap contract token id.

type SwapParser

type SwapParser struct {

	// Filterer is the swap Filterer we use to parse events
	Filterer *swap.SwapFlashLoanFilterer
	// contains filtered or unexported fields
}

SwapParser parses events from the swap contract.

func NewSwapParser

func NewSwapParser(consumerDB db.ConsumerDB, swapAddress common.Address, swapFetcher SwapFetcher, consumerFetcher *Fetcher) (*SwapParser, error)

NewSwapParser creates a new parser for a given bridge.

func (*SwapParser) EventType

func (p *SwapParser) EventType(log ethTypes.Log) (_ swapTypes.EventType, ok bool)

EventType returns the event type of a swap log.

func (*SwapParser) ParseAndStore

func (p *SwapParser) ParseAndStore(ctx context.Context, log ethTypes.Log, chainID uint32) error

ParseAndStore parses and stores the swap logs.

Directories

Path Synopsis
Package backfill provides a command to backfill the consumer database.
Package backfill provides a command to backfill the consumer database.
Package client provides a GraphQL client for consuming logs.
Package client provides a GraphQL client for consuming logs.
contrib
Package main generates a GQL client.
Package main generates a GQL client.
Package node contains the node for the explorer service.
Package node contains the node for the explorer service.

Jump to

Keyboard shortcuts

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