base

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package base contains the base implementation for different sql driers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAllModels

func GetAllModels() (allModels []interface{})

GetAllModels gets all models to migrate see: https://medium.com/@SaifAbid/slice-interfaces-8c78f8b6345d for an explanation of why we can't do this at initialization time

Types

type Rebalance added in v0.0.54

type Rebalance struct {
	CreatedAt       time.Time
	UpdatedAt       time.Time
	RebalanceID     sql.NullString
	Origin          uint64
	Destination     uint64
	OriginAmount    string
	OriginTokenAddr sql.NullString
	Status          reldb.RebalanceStatus
	OriginTxHash    sql.NullString
	DestTxHash      sql.NullString
	TokenName       string
}

Rebalance is the event model for a rebalance action.

func FromRebalance added in v0.0.54

func FromRebalance(rebalance reldb.Rebalance) Rebalance

FromRebalance converts a rebalance to a db object.

func (Rebalance) ToRebalance added in v0.5.0

func (r Rebalance) ToRebalance() (*reldb.Rebalance, error)

ToRebalance converts a db object to a rebalance.

type RequestForQuote

type RequestForQuote struct {
	// CreatedAt is the creation time
	CreatedAt time.Time
	// UpdatedAt is the update time
	UpdatedAt time.Time
	// TransactionID is the transaction id of the event
	TransactionID string `gorm:"column:transaction_id;primaryKey"`
	// OriginChainID is the origin chain for the transactions
	OriginChainID uint32
	// DestChainID is the destination chain for the tx
	DestChainID uint32
	// OriginSender is the original sender
	OriginSender string
	// DestRecipient is the recipient of the destination tx
	DestRecipient string
	// OriginToken is the origin token address
	OriginToken string
	// OriginAmountOriginal is the origin amount used for preicison
	OriginAmountOriginal string
	// OriginTokenDecimals is the origin token decimals
	OriginTokenDecimals uint8
	// DestToken is the destination token address
	DestToken string
	// DestTokenDecimals is the destination token decimal count
	DestTokenDecimals uint8
	// OriginAmount is the origin amount stored for sorting.
	// This is not the source of truth, but is approximate
	OriginAmount decimal.Decimal `gorm:"index"`
	// OriginTxHash is the origin tx hash
	OriginTxHash sql.NullString
	// DestAmountOriginal is the original amount used for precision
	DestAmountOriginal string
	// DestAmountOriginal is the original destination amount
	DestAmount decimal.Decimal `gorm:"index"`
	// DestTxHash is the destination tx hash
	DestTxHash sql.NullString
	// Deadline is the deadline for the relay
	Deadline time.Time `gorm:"index"`
	// OriginNonce is the nonce on the origin chain in the app.
	// this is not effected by the message.sender nonce.
	OriginNonce int `gorm:"index"`
	// Status is the current status of the event
	Status reldb.QuoteRequestStatus
	// BlockNumber is the block number of the event
	BlockNumber uint64
	// RawRequest is the raw request, hex encoded.
	RawRequest string
	// SendChainGas is true if the chain should send gas
	SendChainGas bool
	// RelayNonce is the nonce for the relay transaction.
	RelayNonce uint64
}

RequestForQuote is the primary event model.

func FromQuoteRequest

func FromQuoteRequest(request reldb.QuoteRequest) RequestForQuote

FromQuoteRequest converts a quote request to an object that can be stored in the db. TODO: add validation for deadline > uint64 TODO: roundtripper test.

func (RequestForQuote) ToQuoteRequest

func (r RequestForQuote) ToQuoteRequest() (*reldb.QuoteRequest, error)

ToQuoteRequest converts a db object to a quote request.

type Store

type Store struct {
	listenerDB.ChainListenerDB
	// contains filtered or unexported fields
}

Store implements the service.

func NewStore

func NewStore(db *gorm.DB, metrics metrics.Handler) *Store

NewStore creates a new store.

func (Store) DB

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

DB gets the database object for mutation outside of the lib.

func (Store) GetDBStats added in v0.25.0

func (s Store) GetDBStats(ctx context.Context) (*sql.DBStats, error)

GetDBStats gets the database stats.

func (Store) GetPendingRebalances added in v0.13.3

func (s Store) GetPendingRebalances(ctx context.Context, chainIDs ...uint64) ([]*reldb.Rebalance, error)

GetPendingRebalances checks fetches all pending rebalances that involve the given chainIDs. Note that no chainID filtering will be done if no chainID is specified.

func (Store) GetQuoteRequestByID

func (s Store) GetQuoteRequestByID(ctx context.Context, id [32]byte) (*reldb.QuoteRequest, error)

GetQuoteRequestByID gets a quote request by id. Should return ErrNoQuoteForID if not found.

func (Store) GetQuoteRequestByOriginTxHash added in v0.0.15

func (s Store) GetQuoteRequestByOriginTxHash(ctx context.Context, txHash common.Hash) (*reldb.QuoteRequest, error)

GetQuoteRequestByOriginTxHash gets a quote request by tx hash. Should return ErrNoQuoteForID if not found.

func (Store) GetQuoteResultsByStatus

func (s Store) GetQuoteResultsByStatus(ctx context.Context, matchStatuses ...reldb.QuoteRequestStatus) (res []reldb.QuoteRequest, _ error)

GetQuoteResultsByStatus gets quote results by status.

func (Store) GetRebalanceByID added in v0.5.0

func (s Store) GetRebalanceByID(ctx context.Context, rebalanceID string) (*reldb.Rebalance, error)

GetRebalanceByID gets a rebalance by id. Should return ErrNoRebalanceForID if not found.

func (Store) GetStatusCounts added in v0.29.21

func (s Store) GetStatusCounts(ctx context.Context, matchStatuses ...reldb.QuoteRequestStatus) (map[reldb.QuoteRequestStatus]int, error)

GetStatusCounts gets the counts of quote requests by status.

func (Store) StoreQuoteRequest

func (s Store) StoreQuoteRequest(ctx context.Context, request reldb.QuoteRequest) error

StoreQuoteRequest stores a quote request.

func (Store) StoreRebalance added in v0.0.54

func (s Store) StoreRebalance(ctx context.Context, rebalance reldb.Rebalance) error

StoreRebalance stores a rebalance action.

func (Store) SubmitterDB

func (s Store) SubmitterDB() submitterDB.Service

SubmitterDB gets the submitter database object for mutation outside of the lib.

func (Store) UpdateDestTxHash

func (s Store) UpdateDestTxHash(ctx context.Context, id [32]byte, destTxHash common.Hash) error

UpdateDestTxHash todo: db test.

func (Store) UpdateLatestRebalance added in v1.1.4

func (s Store) UpdateLatestRebalance(ctx context.Context, rebalance reldb.Rebalance) error

UpdateLatestRebalance updates a rebalance model. This handles the case where rebalance ID is not unique, so we update the latest rebalance that matches origin / destination and has a non-terminal rebalance status.

func (Store) UpdateQuoteRequestStatus

func (s Store) UpdateQuoteRequestStatus(ctx context.Context, id [32]byte, status reldb.QuoteRequestStatus, prevStatus *reldb.QuoteRequestStatus) error

UpdateQuoteRequestStatus todo: db test.

func (Store) UpdateRebalance added in v0.5.0

func (s Store) UpdateRebalance(ctx context.Context, rebalance reldb.Rebalance, updateID bool) error

UpdateRebalance updates the rebalance status.

func (Store) UpdateRelayNonce added in v0.25.0

func (s Store) UpdateRelayNonce(ctx context.Context, id [32]byte, nonce uint64) error

UpdateRelayNonce todo: db test.

Jump to

Keyboard shortcuts

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