db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package db provides the persistent and in-memory store.

Package db provides the persistent store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB is the persistent and in-memory store.

func New

func New(
	ctx context.Context,
	cfg *config.Config,
	wallet *xmr.Client,
	parentLogger *slog.Logger,
) (*DB, error)

func NewReadOnly

func NewReadOnly(
	cfg *config.Config,
	parentLogger *slog.Logger,
) (*DB, error)

func (*DB) CheckPendingPayment

func (db *DB) CheckPendingPayment(id string) (*api.Receipt, error)

CheckPendingPayment checks on a pending payment by XMR payment ID.

func (*DB) Close

func (db *DB) Close() error

Close gracefully closes the database.

func (*DB) Dump

func (db *DB) Dump() (string, error)

Dump dumps the DB to a JSONL (https://jsonlines.org/) file in the working directory.

func (*DB) Flush

func (db *DB) Flush(pending, alerts bool) error

Flush discards various parts of the database.

func (*DB) GetAlertEntry

func (db *DB) GetAlertEntry() (*api.Superchat, error)

GetAlertEntry returns the next alert entry after advancing the state. This may silently skip entries that are "stale" to prevent the backlog from growing too far.

func (*DB) GetNMostRecent

func (db *DB) GetNMostRecent(n int) ([]api.Superchat, time.Time, error)

GetNMostRecent returns the N most recent superchats. The result is further limited by the `db.max_count` config option.

func (*DB) NewPendingPayment

func (db *DB) NewPendingPayment(args *api.PendingPayment) error

NewPendingPayment creates a new pending payment.

func (*DB) Stats

func (db *DB) Stats() (*Stats, error)

Stats returns some db statistics.

type DumpEntry

type DumpEntry struct {
	// Seq is the unique sequence number for a paid superchat.
	Seq uint64 `json:"seq,omitempty"`
	// PaymentID is the XMR payment ID of a pending superchat.
	PaymentID string `json:"payment_id,omitempty"`
	// Name is the superchat sender.
	Name string `json:"name"`
	// Message is the superchat message.
	Message string `json:"msg,omitempty"`
	// Amount is the amount received.
	Amount *xmr.Quantity `json:"amount"`
	// ShowAmount indicates if the amount should be shown on stream.
	ShowAmount bool `json:"show_amount,omitempty"`
	// TxID is the XMR TxID of a paid superchat.
	TxID string `json:"txid,omitempty"`
	// Timestamp is the timestamp of when the superchat was created/paid-for.
	Timestamp time.Time `json:"ts"`
	// NotAlerted indicates if the superchat has not been displayed by
	// the alert view.
	NotAlerted bool `json:"not_alerted,omitempty"`
}

DumpEntry is a JSONL dump export record.

type Stats

type Stats struct {
	NumPendingPayment int `json:"num_pending_payment"`
	NumCompleted      int `json:"num_completed"`

	AlertID     uint64 `json:"alert_id,omitempty"`
	CompletedID uint64 `json:"completed_id,omitempty"`
}

Stats is a snapshot of the useful database statistics.

Jump to

Keyboard shortcuts

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