reldb

package
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package reldb contains the datbaase interface for the rfq relayer. All data store types must confrm to this interface.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoLatestBlockForChainID is returned when no block exists for the chain.
	ErrNoLatestBlockForChainID = errors.New("no latest block for chainId")
	// ErrNoQuoteForID means the quote was not found.
	ErrNoQuoteForID = errors.New("no quote found for tx id")
	// ErrNoQuoteForTxHash means the quote was not found.
	ErrNoQuoteForTxHash = errors.New("no quote found for tx hash")
)

Functions

This section is empty.

Types

type QuoteRequest

type QuoteRequest struct {
	BlockNumber         uint64
	OriginTokenDecimals uint8
	RawRequest          []byte
	DestTokenDecimals   uint8
	TransactionID       [32]byte
	Sender              common.Address
	Transaction         fastbridge.IFastBridgeBridgeTransaction
	// Status is the quote request status
	Status       QuoteRequestStatus
	OriginTxHash common.Hash
	DestTxHash   common.Hash
}

QuoteRequest is the quote request object.

func (QuoteRequest) GetDestIDPair

func (q QuoteRequest) GetDestIDPair() string

GetDestIDPair gets the destination chain id and token address pair. for some reason, this is specified as [chainid]-[tokenaddr] in the config. this represents the destination pair.

func (QuoteRequest) GetOriginIDPair

func (q QuoteRequest) GetOriginIDPair() string

GetOriginIDPair gets the origin chain id and token address pair. for some reason, this is specified as [chainid]-[tokenaddr] in the config. this represents the origin pair.

type QuoteRequestStatus

type QuoteRequestStatus uint8

QuoteRequestStatus is the status of a quote request in the db. This is the primary mechanism for moving data through the app.

TODO: consider making this an interface and exporting that.

const (
	// Seen means the quote request has been seen by the relayer, but not processed or committed to.
	Seen QuoteRequestStatus = iota + 1
	// NotEnoughInventory means the relayer does not have enough inventory to process the request.
	// This can be retried at a later time.
	NotEnoughInventory
	// DeadlineExceeded means the quote request has exceeded the deadline.
	// This is a terminal state.
	DeadlineExceeded
	// WillNotProcess means the relayer will not process the request for some reason.
	// This is a terminal state.
	WillNotProcess
	// CommittedPending means the relayer has committed liquidity to the request to the chain, but it is not yet confirmed on chain.
	CommittedPending
	// CommittedConfirmed means the relayer has committed liquidity to the request to the chain, and original bridge tx has been confirmed on chain.
	CommittedConfirmed
	// RelayStarted means the relayer has called Relay() on the destination chain.
	RelayStarted
	// RelayCompleted means the relayer has called Relay() on the destination chain, and the tx has been confirmed on chain.
	RelayCompleted
	// ProvePosting means the relayer has called Prove() on the origin chain.
	ProvePosting
	// ProvePosted means the relayer has called Prove() on the origin chain, and the tx has been confirmed on chain.
	ProvePosted
	// ClaimPending means the relayer has called Claim() on the origin chain.
	ClaimPending
	// ClaimCompleted means the relayer has called Claim() on the origin chain, and the tx has been confirmed on chain.
	ClaimCompleted
)

func (QuoteRequestStatus) GormDataType

func (q QuoteRequestStatus) GormDataType() string

GormDataType implements the gorm common interface for enums.

func (QuoteRequestStatus) Int

func (q QuoteRequestStatus) Int() uint8

Int returns the int value of the quote request status.

func (*QuoteRequestStatus) Scan

func (q *QuoteRequestStatus) Scan(src any) error

Scan implements the gorm common interface for enums.

func (QuoteRequestStatus) String

func (i QuoteRequestStatus) String() string

func (QuoteRequestStatus) Value

func (q QuoteRequestStatus) Value() (driver.Value, error)

Value implements the gorm common interface for enums.

type Reader

type Reader interface {
	// LatestBlockForChain gets the latest block for a given chain id.
	LatestBlockForChain(ctx context.Context, chainID uint64) (uint64, error)
	// GetQuoteRequestByID gets a quote request by id. Should return ErrNoQuoteForID if not found
	GetQuoteRequestByID(ctx context.Context, id [32]byte) (*QuoteRequest, error)
	// GetQuoteRequestByOriginTxHash gets a quote request by origin tx hash. Should return ErrNoQuoteForTxHash if not found
	GetQuoteRequestByOriginTxHash(ctx context.Context, txHash common.Hash) (*QuoteRequest, error)
	// GetQuoteResultsByStatus gets quote results by status
	GetQuoteResultsByStatus(ctx context.Context, matchStatuses ...QuoteRequestStatus) (res []QuoteRequest, _ error)
}

Reader is the interface for reading from the database.

type Service

type Service interface {
	Reader
	// SubmitterDB returns the submitter database service.
	SubmitterDB() submitterDB.Service
	Writer
}

Service is the interface for the database service.

type Writer

type Writer interface {
	// PutLatestBlock upsers the latest block on a given chain id to be new height.
	PutLatestBlock(ctx context.Context, chainID, height uint64) error
	// StoreQuoteRequest stores a quote reuquest. If one already exists, only  the status will be updated
	// TODO: find a better way to describe this in the name
	StoreQuoteRequest(ctx context.Context, request QuoteRequest) error
	// UpdateQuoteRequestStatus updates the status of a quote request
	UpdateQuoteRequestStatus(ctx context.Context, id [32]byte, status QuoteRequestStatus) error
	// UpdateDestTxHash updates the dest tx hash of a quote request
	UpdateDestTxHash(ctx context.Context, id [32]byte, destTxHash common.Hash) error
}

Writer is the interface for writing to the database.

Directories

Path Synopsis
Package base contains the base implementation for different sql driers.
Package base contains the base implementation for different sql driers.
Package connect contains the database connection logic for the RFQ relayer.
Package connect contains the database connection logic for the RFQ relayer.
Package mysql provides a common interface for starting sql-lite databases
Package mysql provides a common interface for starting sql-lite databases
Package sqlite provides a common interface for starting sql-lite databases
Package sqlite provides a common interface for starting sql-lite databases

Jump to

Keyboard shortcuts

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