db

package
v0.0.0-...-1bfa4a9 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB interface {
	// Initialise the database. Init should be called once the database object
	// is created.
	Init() error

	// InsertTx inserts the transaction into the database.
	InsertTx(tx tx.Tx) error

	// Tx gets the details of the transaction with the given hash. It returns an
	// `sql.ErrNoRows` if the transaction cannot be found.
	Tx(hash id.Hash) (tx.Tx, error)

	// Txs returns transactions with the given pagination options.
	Txs(offset, limit int, latest bool) ([]tx.Tx, error)

	// Txs returns transactions with the given pagination options.
	TxsByTxid(id pack.Bytes) ([]tx.Tx, error)

	// PendingTxs returns all pending transactions in the database which are not
	// expired.
	PendingTxs(expiry time.Duration) ([]tx.Tx, error)

	// TxStatus returns the current status of the transaction with the given
	// hash.
	TxStatus(hash id.Hash) (TxStatus, error)

	// UpdateStatus updates the status of the given transaction. The status
	// cannot be updated to a previous status.
	UpdateStatus(hash id.Hash, status TxStatus) error

	// Prune deletes transactions which have expired.
	Prune(expiry time.Duration) error

	// InsertGateway inserts the gateway into the database.
	InsertGateway(address string, tx tx.Tx) error

	// Gateway gets the details of the gateway with the given gateway address. It returns an
	// `sql.ErrNoRows` if the gateway cannot be found.
	Gateway(address string) (tx.Tx, error)

	// Gateways returns gateways with the given pagination options.
	Gateways(offset, limit int) ([]tx.Tx, error)

	// GatewayCount returns the number of gateways persisted
	GatewayCount() (int, error)

	// GatewayCount returns the number of gateways persisted
	MaxGatewayCount() int
}

DB is a storage adapter (built on top of a SQL database) that stores all transaction details.

func New

func New(db *sql.DB, maxGatewayCount int) DB

New creates a new DB instance.

type GatewayStatus

type GatewayStatus uint8
const (
	GatewayStatusNil GatewayStatus = iota
	GatewayStatusEmpty
	GatewayStatusUsed
)

type Scannable

type Scannable interface {
	Scan(dest ...interface{}) error
}

type TxStatus

type TxStatus uint8
const (
	TxStatusNil TxStatus = iota
	TxStatusConfirming
	TxStatusConfirmed
	TxStatusSubmitted
)

Jump to

Keyboard shortcuts

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