reldb

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var (
	// 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")
	// ErrNoRebalanceForID means the rebalance was not found.
	ErrNoRebalanceForID = errors.New("no rebalance found for id")
)

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
	// RelayNonce is the nonce for the relay transaction.
	RelayNonce uint64
}

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.

EXTREMELY IMPORTANT: DO NOT ADD NEW VALUES TO THIS ENUM UNLESS THEY ARE AT THE END.

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
	// RelayRaceLost means another relayer has relayed the tx.
	RelayRaceLost
)

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 {
	// 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)
	// GetPendingRebalances checks fetches all pending rebalances that involve the given chainIDs.
	GetPendingRebalances(ctx context.Context, chainIDs ...uint64) ([]*Rebalance, error)
	// GetRebalance gets a rebalance by ID. Should return ErrNoRebalanceForID if not found.
	GetRebalanceByID(ctx context.Context, rebalanceID string) (*Rebalance, error)
	// GetDBStats gets the database stats.
	GetDBStats(ctx context.Context) (*sql.DBStats, error)
	// GetStatusCounts gets the counts of quote requests by status.
	GetStatusCounts(ctx context.Context, matchStatuses ...QuoteRequestStatus) (map[QuoteRequestStatus]int, error)
}

Reader is the interface for reading from the database.

type Rebalance added in v0.0.54

type Rebalance struct {
	RebalanceID     *string
	Origin          uint64
	Destination     uint64
	OriginAmount    *big.Int
	OriginTokenAddr common.Address
	Status          RebalanceStatus
	OriginTxHash    common.Hash
	DestTxHash      common.Hash
}

Rebalance represents a rebalance action.

type RebalanceStatus added in v0.0.54

type RebalanceStatus uint8

RebalanceStatus is the status of a rebalance action in the db.

const (
	// RebalanceInitiated means the rebalance transaction has been initiated.
	RebalanceInitiated RebalanceStatus = iota + 1
	// RebalancePending means the rebalance transaction has been confirmed on the origin.
	RebalancePending
	// RebalanceCompleted means the rebalance transaction has been confirmed on the destination.
	RebalanceCompleted
)

func (RebalanceStatus) GormDataType added in v0.0.54

func (r RebalanceStatus) GormDataType() string

GormDataType implements the gorm common interface for enums.

func (RebalanceStatus) Int added in v0.0.54

func (r RebalanceStatus) Int() uint8

Int returns the int value of the quote request status.

func (*RebalanceStatus) Scan added in v0.0.54

func (r *RebalanceStatus) Scan(src any) error

Scan implements the gorm common interface for enums.

func (RebalanceStatus) String added in v0.0.54

func (i RebalanceStatus) String() string

func (RebalanceStatus) Value added in v0.0.54

func (r RebalanceStatus) Value() (driver.Value, error)

Value implements the gorm common interface for enums.

type Service

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

Service is the interface for the database service.

type Writer

type Writer interface {
	// StoreQuoteRequest stores a quote request. 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
	// StoreRebalance stores a rebalance.
	StoreRebalance(ctx context.Context, rebalance Rebalance) error
	// UpdateQuoteRequestStatus updates the status of a quote request
	UpdateQuoteRequestStatus(ctx context.Context, id [32]byte, status QuoteRequestStatus, prevStatus *QuoteRequestStatus) error
	// UpdateRebalance updates the status of a rebalance action.
	// If the origin is supplied, it will be used to update the ID for the corresponding rebalance model.
	UpdateRebalance(ctx context.Context, rebalance Rebalance, updateID bool) error
	// UpdateDestTxHash updates the dest tx hash of a quote request
	UpdateDestTxHash(ctx context.Context, id [32]byte, destTxHash common.Hash) error
	// UpdateRelayNonce updates the relay nonce of a quote request
	UpdateRelayNonce(ctx context.Context, id [32]byte, nonce uint64) 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