base

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 18 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 LastIndexed

type LastIndexed struct {
	// CreatedAt is the creation time
	CreatedAt time.Time
	// UpdatedAt is the update time
	UpdatedAt time.Time
	// DeletedAt time
	DeletedAt gorm.DeletedAt `gorm:"index"`
	// ChainID is the chain id of the chain we're watching blocks on. This is our primary index.
	ChainID uint64 `gorm:"column:chain_id;primaryKey;autoIncrement:false"`
	// BlockHeight is the highest height we've seen on the chain
	BlockNumber int `gorm:"block_number"`
}

LastIndexed is used to make sure we haven't missed any events while offline. since we event source - rather than use a state machine this is needed to make sure we haven't missed any events by allowing us to go back and source any events we may have missed.

this does not inherit from gorm.model to allow us to use ChainID as a primary key.

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
}

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 {
	// 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) 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) LatestBlockForChain

func (s Store) LatestBlockForChain(ctx context.Context, chainID uint64) (uint64, error)

LatestBlockForChain gets the latest block for a chain.

func (Store) PutLatestBlock

func (s Store) PutLatestBlock(ctx context.Context, chainID, height uint64) error

PutLatestBlock upserts the latest block into the database.

func (Store) StoreQuoteRequest

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

StoreQuoteRequest stores a quote request.

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) UpdateQuoteRequestStatus

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

UpdateQuoteRequestStatus todo: db test.

Jump to

Keyboard shortcuts

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