db

package
v0.0.0-...-412688d Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrZeroTimestamp signals that the caller attempted to insert deposits
	// with a timestamp of zero.
	ErrZeroTimestamp = errors.New("timestamp is zero")

	// ErrUnknownDeposit signals that the target deposit could not be found.
	ErrUnknownDeposit = errors.New("unknown deposit")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Host is the database hostname.
	Host string

	Port uint16

	// User is the database user to log in as.
	User string

	// Password is the user's password to authenticate.
	Password string

	// DBName is the name of the database to connect to.
	DBName string

	// EnableSSL enables SLL on the connection if set to true.
	EnableSSL bool
}

Config houses the data required to connect to a Postgres backend.

func (Config) WithDB

func (c Config) WithDB() string

WithDB returns the connection string with a specific database to connect to.

func (Config) WithoutDB

func (c Config) WithoutDB() string

WithoutDB returns the connection string without connecting to a specific database.

type ConfirmationInfo

type ConfirmationInfo struct {
	TxnHash        common.Hash
	BlockNumber    uint64
	BlockTimestamp time.Time
}

ConfirmationInfo holds metadata about a tx on either the L1 or L2 chain.

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database provides a Go API for accessing Teleportr read/write operations.

func Open

func Open(cfg Config) (*Database, error)

Open creates a new database connection to the configured Postgres backend and applies any migrations.

func (*Database) Close

func (d *Database) Close() error

Close closes the connection to the database.

func (*Database) CompletedTeleports

func (d *Database) CompletedTeleports() ([]Teleport, error)

CompletedTeleports returns the set of all deposits that have also been disbursed.

func (*Database) ConfirmedDeposits

func (d *Database) ConfirmedDeposits(blockNumber, confirmations uint64) ([]Deposit, error)

ConfirmedDeposits returns the set of all deposits that have sufficient confirmation, but do not have a recorded disbursement.

func (*Database) DeletePendingTx

func (d *Database) DeletePendingTx(startID, endID uint64) error

DeletePendingTx removes any pending txs with matching start and end ids. This allows the caller to remove any logically-conflicting pending txs from the database after successfully processing the outcomes.

func (*Database) LastProcessedBlock

func (d *Database) LastProcessedBlock() (*uint64, error)

func (*Database) LatestDisbursementID

func (d *Database) LatestDisbursementID() (*uint64, error)

LatestDisbursementID returns the latest deposit id known to the database that has a recorded disbursement.

func (*Database) ListPendingTxs

func (d *Database) ListPendingTxs() ([]PendingTx, error)

ListPendingTxs returns all pending txs stored in the database.

func (*Database) LoadTeleportByDepositHash

func (d *Database) LoadTeleportByDepositHash(
	txHash common.Hash,
) (*Teleport, error)

func (*Database) LoadTeleportsByAddress

func (d *Database) LoadTeleportsByAddress(
	addr common.Address,
) ([]Teleport, error)

func (*Database) Migrate

func (d *Database) Migrate() error

Migrate applies all existing migrations to the open database.

func (*Database) UpsertDeposits

func (d *Database) UpsertDeposits(
	deposits []Deposit,
	lastProcessedBlock uint64,
) error

UpsertDeposits inserts a list of deposits into the database, or updats an existing deposit in place if the same ID is found.

func (*Database) UpsertDisbursement

func (d *Database) UpsertDisbursement(
	id uint64,
	txnHash common.Hash,
	blockNumber uint64,
	blockTimestamp time.Time,
	success bool,
) error

UpsertDisbursement inserts a disbursement, or updates an existing record in-place if the ID already exists.

func (*Database) UpsertPendingTx

func (d *Database) UpsertPendingTx(pendingTx PendingTx) error

UpsertPendingTx inserts a disbursement, or updates the entry if the TxHash already exists.

type Deposit

type Deposit struct {
	ID      uint64
	Address common.Address
	Amount  *big.Int

	ConfirmationInfo
}

Deposit represents an event emitted from the TeleportrDeposit contract on L1, along with additional info about the tx that generated the event.

type Disbursement

type Disbursement struct {
	Success bool

	ConfirmationInfo
}

type PendingTx

type PendingTx struct {
	// Txhash is the tx hash of the disbursement tx.
	TxHash common.Hash

	// StartID is the deposit id of the first disbursement, inclusive.
	StartID uint64

	// EndID is the deposit id fo the last disbursement, exclusive.
	EndID uint64
}

PendingTx encapsulates the metadata stored about published disbursement txs.

type Scanner

type Scanner interface {
	Scan(...interface{}) error
}

type Teleport

type Teleport struct {
	Deposit

	Disbursement *Disbursement
}

Teleport represents the combination of an L1 deposit and its disbursement on L2. Disburment will be nil if the L2 disbursement has not occurred.

Jump to

Keyboard shortcuts

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