db

package
v0.0.95 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 11 Imported by: 24

Documentation

Overview

Package db provides a database interface for the submitter.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoNonceForChain = errors.New("no nonce exists for this chain")

ErrNoNonceForChain is the error returned when there is no nonce for a given chain id.

Functions

This section is empty.

Types

type Service

type Service interface {
	// GetNonceForChainID gets the nonce for a given chain id.
	GetNonceForChainID(ctx context.Context, fromAddress common.Address, chainID *big.Int) (nonce uint64, err error)
	// PutTXS stores a tx in the database.
	PutTXS(ctx context.Context, txs ...TX) error
	// GetTXS gets all txs for a given address and chain id. If chain id is nil, it will get all txs for the address.
	GetTXS(ctx context.Context, fromAddress common.Address, chainID *big.Int, statuses ...Status) (txs []TX, err error)
	// MarkAllBeforeOrAtNonceReplacedOrConfirmed marks all txs for a given chain id and address before a given nonce as replaced or confirmed.
	// TODO: cleaner function name
	MarkAllBeforeOrAtNonceReplacedOrConfirmed(ctx context.Context, signer common.Address, chainID *big.Int, nonce uint64) error
	// DBTransaction executes a transaction on the database.
	// the function passed in will be passed a new service that is scoped to the transaction.
	DBTransaction(ctx context.Context, f TransactionFunc) error
	// GetAllTXAttemptByStatus gets all txs for a given address and chain id with a given status.
	GetAllTXAttemptByStatus(ctx context.Context, fromAddress common.Address, chainID *big.Int, matchStatuses ...Status) (txs []TX, err error)
}

Service is the interface for the tx queue database. note: the other files in this package (base, sqlite, mysql) provide a suggested implementation. you can implement these yourself. If you plan on importing them, you should wrap in your own service.

type Status

type Status uint8

Status is the status of a tx.

const (
	// Pending is the status of a tx that has not been processed yet.
	Pending Status = iota + 1 // Pending
	// Stored is the status of a tx that has been stored.
	Stored // Stored
	// Submitted is the status of a tx that has been submitted.
	Submitted // Submitted
	// FailedSubmit is the status of a tx that has failed to submit.
	FailedSubmit // Failed
	// ReplacedOrConfirmed is the status of a tx that has been replaced by a new tx or confirmed. The actual status will be set later.
	ReplacedOrConfirmed // ReplacedOrConfirmed
	// Replaced is the status of a tx that has been replaced by a new tx.
	Replaced // Replaced
	// Confirmed is the status of a tx that has been confirmed.
	Confirmed // Confirmed
)

Important: do not modify the order of these constants. if one needs to be removed, replace it with a no-op status.

func (Status) GormDataType

func (s Status) GormDataType() string

GormDataType returns the gorm data type for the status.

func (Status) Int

func (s Status) Int() uint8

Int returns the uint8 representation of the status.

func (*Status) Scan

func (s *Status) Scan(src interface{}) error

Scan implements the gorm Scanner interface.

func (Status) String

func (i Status) String() string

func (*Status) Value

func (s *Status) Value() (driver.Value, error)

Value implements the gorm Valuer interface.

type TX

type TX struct {
	// inherited from types.Transaction
	*types.Transaction

	// Status is the status of the transaction
	Status Status
	// contains filtered or unexported fields
}

TX is a superset of transaction that includes the gas price.

func NewTX

func NewTX(tx *types.Transaction, status Status) TX

NewTX creates a new TX for use in the db package.

func (*TX) CreationTime

func (t *TX) CreationTime() time.Time

CreationTime is the time the transaction was last updated.

func (*TX) UnsafeSetCreationTime

func (t *TX) UnsafeSetCreationTime(creationTime time.Time)

UnsafeSetCreationTime is an unsafe setter for the creation time it is called unsafe to force you to read this comment telling you this should only be called if you are creating a db implementation of this package. this should not be called in the submmiter itself or any other package.

type TransactionFunc

type TransactionFunc func(ctx context.Context, svc Service) error

TransactionFunc is a function that can be passed to DBTransaction.

Directories

Path Synopsis
Package txdb provides a database implementation that simplements the submitter db service.
Package txdb provides a database implementation that simplements the submitter db service.

Jump to

Keyboard shortcuts

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