sql

package
v0.0.41 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sql contains the sql store.

Index

Constants

This section is empty.

Variables

View Source
var (
	// TxHashFieldName is the field name of the tx hash.
	TxHashFieldName string
	// ChainIDFieldName gets the chain id field name.
	ChainIDFieldName string
	// BlockNumberFieldName is the name of the block number field.
	BlockNumberFieldName string
	// ContractAddressFieldName is the address of the contract.
	ContractAddressFieldName string
	// InsertTimeFieldName is the insert time field name.
	InsertTimeFieldName string
	// EventTypeFieldName is the event type field name.
	EventTypeFieldName string
	// AmountFieldName is the amount field name.
	AmountFieldName string
	// EventIndexFieldName is the event index field name.
	EventIndexFieldName string
	// DestinationChainIDFieldName is the destination chain id field name.
	DestinationChainIDFieldName string
	// TokenFieldName is the token field name.
	TokenFieldName string
	// RecipientFieldName is the recipient field name.
	RecipientFieldName string
	// KappaFieldName is the kappa field name.
	KappaFieldName string
	// DestinationKappaFieldName is the destination kappa field name.
	DestinationKappaFieldName string
	// SenderFieldName is the sender field name.
	SenderFieldName string
	// TimeStampFieldName is the timestamp field name.
	TimeStampFieldName string
	// AmountUSDFieldName is the amount in USD field name.
	AmountUSDFieldName string
	// TokenDecimalFieldName is the token decimal field name.
	TokenDecimalFieldName string
)
View Source
var PageSize = 100

PageSize is the amount of entries per page of events.

Functions

This section is empty.

Types

type BridgeEvent

type BridgeEvent struct {
	// InsertTime is the time the event was inserted into the database.
	InsertTime uint64 `gorm:"column:insert_time"`
	// ContractAddress is the address of the contract that generated the event.
	ContractAddress string `gorm:"column:contract_address"`
	// ChainID is the chain id of the contract that generated the event.
	ChainID uint32 `gorm:"column:chain_id"`
	// EventType is the type of the event.
	EventType uint8 `gorm:"column:event_type"`
	// BlockNumber is the block number of the event.
	BlockNumber uint64 `gorm:"column:block_number"`
	// TxHash is the transaction hash of the event.
	TxHash string `gorm:"column:tx_hash"`
	// Token is the address of the token.
	Token string `gorm:"column:token"`
	// Amount is the amount of tokens.
	Amount *big.Int `gorm:"column:amount;type:UInt256"`
	// EventIndex is the index of the log.
	EventIndex uint64 `gorm:"column:event_index"`
	// DestinationKappa is the destination kappa.
	DestinationKappa string `gorm:"column:destination_kappa"`
	// Sender is the address of the sender.
	Sender string `gorm:"column:sender"`

	// Recipient is the address to send the tokens to.
	Recipient sql.NullString `gorm:"column:recipient"`
	// RecipientBytes is the recipient address in bytes.
	RecipientBytes sql.NullString `gorm:"column:recipient_bytes"`
	// DestinationChainID is the chain id of the chain to send the tokens to.
	DestinationChainID *big.Int `gorm:"column:destination_chain_id;type:UInt256"`
	// Fee is the fee.
	Fee *big.Int `gorm:"column:fee;type:UInt256"`
	// Kappa is theFee keccak256 hash of the transaction.
	Kappa sql.NullString `gorm:"column:kappa"`
	// TokenIndexFrom is the index of the from token in the pool.
	TokenIndexFrom *big.Int `gorm:"column:token_index_from;type:UInt256"`
	// TokenIndexTo is the index of the to token in the pool.
	TokenIndexTo *big.Int `gorm:"column:token_index_to;type:UInt256"`
	// MinDy is the minimum amount of tokens to receive.
	MinDy *big.Int `gorm:"column:min_dy;type:UInt256"`
	// Deadline is the deadline of the transaction.
	Deadline *big.Int `gorm:"column:deadline;type:UInt256"`
	// SwapSuccess is whether the swap was successful.
	SwapSuccess *big.Int `gorm:"column:swap_success;type:UInt256"`
	// SwapTokenIndex is the index of the token in the pool.
	SwapTokenIndex *big.Int `gorm:"column:swap_token_index;type:UInt256"`
	// SwapMinAmount is the minimum amount of tokens to receive.
	SwapMinAmount *big.Int `gorm:"column:swap_min_amount;type:UInt256"`
	// SwapDeadline is the deadline of the swap transaction.
	SwapDeadline *big.Int `gorm:"column:swap_deadline;type:UInt256"`
	// TokenID is the token's ID.
	TokenID sql.NullString `gorm:"column:token_id"`
	// AmountUSD is the amount in USD.
	AmountUSD *float64 `gorm:"column:amount_usd;type:Float64"`
	// FeeAmountUSD is the fee amount in USD.
	FeeAmountUSD *float64 `gorm:"column:fee_amount_usd;type:Float64"`
	// TokenDecimal is the token's decimal.
	TokenDecimal *uint8 `gorm:"column:token_decimal"`
	// TokenSymbol is the token's symbol from coin gecko.
	TokenSymbol sql.NullString `gorm:"column:token_symbol"`
	// TimeStamp is the timestamp of the block in which the event occurred.
	TimeStamp *uint64 `gorm:"column:timestamp"`
}

BridgeEvent stores data for emitted events from the Bridge contract.

type LastBlock added in v0.0.11

type LastBlock struct {
	// ChainID is the chain id of the chain.
	ChainID uint32 `gorm:"column:chain_id"`
	// BlockNumber is the last block number that the explorer has backfilled to.
	BlockNumber uint64 `gorm:"column:block_number"`
	// ContractAddress is the address of the contract that generated the event.
	ContractAddress string `gorm:"column:contract_address"`
}

LastBlock stores the last block number that the explorer has backfilled to on each chain.

type MessageBusEvent added in v0.0.19

type MessageBusEvent struct {
	// InsertTime is the time the event was inserted into the database
	InsertTime uint64 `gorm:"column:insert_time"`
	// ContractAddress is the address of the contract that generated the event
	ContractAddress string `gorm:"column:contract_address"`
	// ChainID is the chain id of the contract that generated the event
	ChainID uint32 `gorm:"column:chain_id"`
	// BlockNumber is the block number of the event
	BlockNumber uint64 `gorm:"column:block_number"`
	// TxHash is the transaction hash of the event
	TxHash string `gorm:"column:tx_hash"`
	// EventType is the type of the event
	EventType uint8 `gorm:"column:event_type"`
	// EventIndex is the index of the log
	EventIndex uint64 `gorm:"column:event_index"`
	// Sender is the address of the sender
	Sender string `gorm:"column:sender"`

	// MessageId is the message id of the event.
	MessageID sql.NullString `gorm:"column:message_id"`
	// SourceChainID is the chain id of the message's source chain.
	SourceChainID *big.Int `gorm:"column:source_chain_id;type:UInt256"`
	// Status is the status of the event.
	Status sql.NullString `gorm:"column:status"`
	// SourceAddress is the address that the message will be passed from.
	SourceAddress sql.NullString `gorm:"column:source_address"`
	// DestinationAddress is the address that the message will be passed to.
	DestinationAddress sql.NullString `gorm:"column:destination_address"`
	// DestinationChainID is the chain id of the message's destination chain.
	DestinationChainID *big.Int `gorm:"column:destination_chain_id;type:UInt256"`
	// Nonce is the nonce of the message. It is equivalent to the nonce on the origin chain.
	Nonce *big.Int `gorm:"column:nonce;type:UInt256"`
	// Message is the message.
	Message sql.NullString `gorm:"column:message"`
	// Receiver is the receiver of the event.
	Receiver sql.NullString `gorm:"column:receiver"`
	// Options are the options chosen for the message.
	Options sql.NullString `gorm:"column:options"`
	// Fee is the fee of the message.
	Fee *big.Int `gorm:"column:fee;type:UInt256"`
	// RevertedReason is the reason a call was reverted.
	RevertedReason sql.NullString `gorm:"column:reverted_reason"`
	// TimeStamp is the timestamp in which the record was inserted.
	TimeStamp *uint64 `gorm:"column:timestamp"`
}

MessageBusEvent stores data for emitted events from the message bus contract.

type Store

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

Store is the clickhouse store. It extends the base store for sqlite specific queries.

func OpenGormClickhouse

func OpenGormClickhouse(ctx context.Context, address string, readOnly bool) (*Store, error)

OpenGormClickhouse opens a gorm connection to clickhouse.

func (*Store) GetAddressRanking added in v0.0.15

func (s *Store) GetAddressRanking(ctx context.Context, query string) ([]*model.AddressRanking, error)

GetAddressRanking gets AddressRanking for a given query.

func (*Store) GetBridgeEvent added in v0.0.15

func (s *Store) GetBridgeEvent(ctx context.Context, query string) (*BridgeEvent, error)

GetBridgeEvent returns a bridge event.

func (*Store) GetBridgeEvents added in v0.0.25

func (s *Store) GetBridgeEvents(ctx context.Context, query string) ([]BridgeEvent, error)

GetBridgeEvents returns bridge events.

func (*Store) GetDateResults added in v0.0.15

func (s *Store) GetDateResults(ctx context.Context, query string) ([]*model.DateResult, error)

GetDateResults returns the dya by day data.

func (*Store) GetFloat64 added in v0.0.15

func (s *Store) GetFloat64(ctx context.Context, query string) (float64, error)

GetFloat64 gets a float64 from a given query.

func (*Store) GetStringArray added in v0.0.15

func (s *Store) GetStringArray(ctx context.Context, query string) ([]string, error)

GetStringArray returns a string array for a given query.

func (*Store) GetTokenCounts added in v0.0.25

func (s *Store) GetTokenCounts(ctx context.Context, query string) ([]*model.TokenCountResult, error)

GetTokenCounts returns Tx counts.

func (*Store) GetTxCounts added in v0.0.25

func (s *Store) GetTxCounts(ctx context.Context, query string) ([]*model.TransactionCountResult, error)

GetTxCounts returns Tx counts.

func (*Store) GetUint64 added in v0.0.15

func (s *Store) GetUint64(ctx context.Context, query string) (uint64, error)

GetUint64 gets a uint64 from a given query.

func (*Store) PartialInfosFromIdentifiers added in v0.0.9

func (s *Store) PartialInfosFromIdentifiers(ctx context.Context, query string) ([]*model.PartialInfo, error)

PartialInfosFromIdentifiers returns events given identifiers. If order is true, the events are ordered by block number.

func (*Store) PartialInfosFromIdentifiersByChain added in v0.0.25

func (s *Store) PartialInfosFromIdentifiersByChain(ctx context.Context, query string) (map[int]*model.PartialInfo, error)

PartialInfosFromIdentifiersByChain returns events given identifiers. If order is true, the events are ordered by block number.

func (*Store) StoreEvent

func (s *Store) StoreEvent(ctx context.Context, event interface{}) error

StoreEvent stores a generic event that has the proper fields set by `eventToBridgeEvent`.

func (*Store) StoreEvents added in v0.0.31

func (s *Store) StoreEvents(ctx context.Context, events []interface{}) error

StoreEvents stores a list of events in batches.

func (*Store) StoreLastBlock added in v0.0.11

func (s *Store) StoreLastBlock(ctx context.Context, chainID uint32, blockNumber uint64, contractAddress string) error

StoreLastBlock stores the last block number that has been backfilled for a given chain.

func (*Store) UNSAFE_DB added in v0.0.9

func (s *Store) UNSAFE_DB() *gorm.DB

UNSAFE_DB gets the underlying gorm db.

type SwapEvent

type SwapEvent struct {
	// InsertTime is the time the event was inserted into the database.
	InsertTime uint64 `gorm:"column:insert_time"`
	// ContractAddress is the address of the contract that generated the event.
	ContractAddress string `gorm:"column:contract_address"`
	// ChainID is the chain id of the contract that generated the event.
	ChainID uint32 `gorm:"column:chain_id"`
	// BlockNumber is the block number of the event.
	BlockNumber uint64 `gorm:"column:block_number"`
	// TxHash is the transaction hash of the event.
	TxHash string `gorm:"column:tx_hash"`
	// EventType is the type of the event.
	EventType uint8 `gorm:"column:event_type"`
	// EventIndex is the index of the log.
	EventIndex uint64 `gorm:"column:event_index"`
	// Sender is the address of the sender.
	Sender string `gorm:"column:sender"`

	// Amount is the amount of tokens..
	Amount map[uint8]string `gorm:"column:amount;type:Map(UInt8, String)"`
	// AmountFee is the amount of fees.
	AmountFee map[uint8]string `gorm:"column:amount_fee;type:Map(UInt8, String)"`
	// ProtocolFee is the protocol fee.
	ProtocolFee *big.Int `gorm:"column:protocol_fee;type:UInt256"`
	// Buyer is the address of the buyer.
	Buyer sql.NullString `gorm:"column:buyer"`
	// TokensSold is the amount of tokens sold.
	TokensSold *big.Int `gorm:"column:tokens_sold;type:UInt256"`
	// SoldID is the id of the token sold.
	SoldID *big.Int `gorm:"column:sold_id;type:UInt256"`
	// TokensBought is the amount of tokens bought.
	TokensBought *big.Int `gorm:"column:tokens_bought;type:UInt256"`
	// BoughtID is the id of the token bought.
	BoughtID *big.Int `gorm:"column:bought_id;type:UInt256"`
	// Provider is the address of the provider.
	Provider sql.NullString `gorm:"column:provider"`
	// Invariant is the invariant of the pool.
	Invariant *big.Int `gorm:"column:invariant;type:UInt256"`
	// LPTokenAmount is the amount of LP tokens.
	LPTokenAmount *big.Int `gorm:"column:lp_token_amount;type:UInt256"`
	// LPTokenSupply is the supply of the LP token.
	LPTokenSupply *big.Int `gorm:"column:lp_token_supply;type:UInt256"`
	// NewAdminFee is the new admin fee.
	NewAdminFee *big.Int `gorm:"column:new_admin_fee;type:UInt256"`
	// NewSwapFee is the new swap fee.
	NewSwapFee *big.Int `gorm:"column:new_swap_fee;type:UInt256"`
	// OldA is the old A value.
	OldA *big.Int `gorm:"column:old_a;type:UInt256"`
	// NewA is the new A value.
	NewA *big.Int `gorm:"column:new_a;type:UInt256"`
	// InitialTime is the initial time.
	InitialTime *big.Int `gorm:"column:initial_time;type:UInt256"`
	// FutureTime is the future time.
	FutureTime *big.Int `gorm:"column:future_time;type:UInt256"`
	// CurrentA is the current A value.
	CurrentA *big.Int `gorm:"column:current_a;type:UInt256"`
	// Time is the time.
	Time *big.Int `gorm:"column:time;type:UInt256"`
	// Receiver is the address of the receiver.
	Receiver sql.NullString `gorm:"column:receiver"`
	// TokenPrices are the prices of each token at the given time.
	TokenPrices map[uint8]float64 `gorm:"column:amount_usd;type:Map(UInt8, Float64)"`
	// TokenDecimal is the token's decimal.
	TokenDecimal map[uint8]uint8 `gorm:"column:token_decimal;type:Map(UInt8, UInt8)"`
	// TokenSymbol is the token's symbol from coingecko.
	TokenSymbol map[uint8]string `gorm:"column:token_symbol;type:Map(UInt8, String)"`
	// TimeStamp is the timestamp of the block in which the event occurred.
	TimeStamp *uint64 `gorm:"column:timestamp"`
}

SwapEvent stores data for emitted events from the Swap contract.

Jump to

Keyboard shortcuts

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