db

package
v0.0.0-...-91dbc65 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package db contains the logic necessary to store BTRY's information.

Index

Constants

This section is empty.

Variables

View Source
var ErrInsufficientPrizes = errors.New("withdrawal amount is higher than assigned prizes")

ErrInsufficientPrizes is returned when the user requests more than he has.

View Source
var ErrNoAddress = errors.New("no lightning address linked to this public key")

ErrNoAddress is thrown when a public key does not have any lightning address linked to it.

View Source
var ErrNoChatID = errors.New("no chat ID linked to this public key")

Functions

func AddPagination

func AddPagination(query string, offset, limit uint64, sortField string, reverse bool) string

AddPagination returns the pagination part of an SQL query.

func BulkInsertValues

func BulkInsertValues(rows, values int) string

BulkInsertValues builds a query to insert multiple values in a single database call.

func UpdatePrizes

func UpdatePrizes(amount uint64, prizes []*PrizesRow) error

UpdatePrizes substracts the amount from the prizes.

Types

type Bet

type Bet struct {
	PublicKey string `json:"public_key,omitempty" db:"public_key"`
	Index     uint64 `json:"index,omitempty"`
	Tickets   uint64 `json:"tickets,omitempty"`
}

Bet represents a user bet.

type BetsStore

type BetsStore interface {
	Add(bet Bet) error
	GetPrizePool(lotteryHeight uint32) (uint64, error)
	List(lotteryHeight uint32, offset, limit uint64, reverse bool) ([]Bet, error)
}

BetsStore contains the methods used to store and retrieve bets from the database.

type BetsStoreMock

type BetsStoreMock struct {
	mock.Mock
}

BetsStoreMock is a mocked implementation of the bets store.

func NewBetsStoreMock

func NewBetsStoreMock() *BetsStoreMock

NewBetsStoreMock returns a mocked bets store.

func (*BetsStoreMock) Add

func (b *BetsStoreMock) Add(bet Bet) error

Add mock.

func (*BetsStoreMock) GetPrizePool

func (b *BetsStoreMock) GetPrizePool(lotteryHeight uint32) (uint64, error)

GetPrizePool mock.

func (*BetsStoreMock) List

func (b *BetsStoreMock) List(lotteryHeight uint32, offset, limit uint64, reverse bool) ([]Bet, error)

List mock.

type DB

type DB struct {
	Bets          BetsStore
	Lightning     LightningStore
	Lotteries     LotteriesStore
	Notifications NotificationsStore
	Prizes        PrizesStore
	Winners       WinnersStore
	// contains filtered or unexported fields
}

DB represents the application database.

func Open

func Open(config config.DB) (*DB, error)

Open opens the database.

func (*DB) Close

func (db *DB) Close() error

Close releases all related resources.

type LightningStore

type LightningStore interface {
	GetAddress(publicKey string) (string, error)
	SetAddress(publicKey, address string) error
}

LightningStore contains the methods used to store and retrieve lightning addresses from the database.

type LightningStoreMock

type LightningStoreMock struct {
	mock.Mock
}

LightningStoreMock is a mocked implementation of a lightning store.

func NewLightningStoreMock

func NewLightningStoreMock() *LightningStoreMock

NewLightningStoreMock returns a mocked lightning store.

func (*LightningStoreMock) GetAddress

func (l *LightningStoreMock) GetAddress(publicKey string) (string, error)

Get mock.

func (*LightningStoreMock) SetAddress

func (l *LightningStoreMock) SetAddress(publicKey, address string) error

Set mock.

type LotteriesStore

type LotteriesStore interface {
	AddHeight(height uint32) error
	DeleteHeight(height uint32) error
	GetNextHeight() (uint32, error)
	ListHeights(offset, limit uint64, reverse bool) ([]uint32, error)
}

LotteriesStore contains the methods used to store and retrieve lotteries from the database.

type LotteriesStoreMock

type LotteriesStoreMock struct {
	mock.Mock
}

LotteriesStoreMock is a mocked implementation of the Lottery store.

func NewLotteriesStoreMock

func NewLotteriesStoreMock() *LotteriesStoreMock

NewLotteriesStoreMock returns a mocked Lottery store.

func (*LotteriesStoreMock) AddHeight

func (l *LotteriesStoreMock) AddHeight(height uint32) error

AddHeight mock.

func (*LotteriesStoreMock) DeleteHeight

func (l *LotteriesStoreMock) DeleteHeight(height uint32) error

DeleteHeight mock.

func (*LotteriesStoreMock) GetNextHeight

func (l *LotteriesStoreMock) GetNextHeight() (uint32, error)

GetNextHeight mock.

func (*LotteriesStoreMock) ListHeights

func (l *LotteriesStoreMock) ListHeights(offset, limit uint64, reverse bool) ([]uint32, error)

ListHeights mock.

type NotificationsStore

type NotificationsStore interface {
	Add(publicKey string, chatID int64) error
	GetChatID(publicKey string) (int64, error)
}

NotificationsStore contains the methods used to store and retrieve notifications from the database.

type NotificationsStoreMock

type NotificationsStoreMock struct {
	mock.Mock
}

NotificationsStoreMock is a mocked implementation of the Notifications store.

func NewNotificationsStoreMock

func NewNotificationsStoreMock() *NotificationsStoreMock

NewNotificationsStoreMock returns a mocked Notifications store.

func (*NotificationsStoreMock) Add

func (n *NotificationsStoreMock) Add(publicKey string, chatID int64) error

Add mock.

func (*NotificationsStoreMock) GetChatID

func (n *NotificationsStoreMock) GetChatID(publicKey string) (int64, error)

GetChatID mock.

type PrizesRow

type PrizesRow struct {
	RowID  int    `db:"rowid"`
	Amount uint64 `db:"amount"`
}

PrizesRow represent a prizes table row.

type PrizesStore

type PrizesStore interface {
	Expire(lotteryHeight uint32) (uint64, error)
	Get(publicKey string) (uint64, error)
	Set(lotteryHeight uint32, winners []Winner) error
	Withdraw(publicKey string, amount uint64) error
}

PrizesStore contains the methods used to store and retrieve prizes from the database.

type PrizesStoreMock

type PrizesStoreMock struct {
	mock.Mock
}

PrizesStoreMock is a mocked implementation of a prizes store.

func NewPrizesStoreMock

func NewPrizesStoreMock() *PrizesStoreMock

NewPrizesStoreMock returns a mocked prizes store.

func (*PrizesStoreMock) Expire

func (w *PrizesStoreMock) Expire(height uint32) (uint64, error)

Expire mock.

func (*PrizesStoreMock) Get

func (w *PrizesStoreMock) Get(publicKey string) (uint64, error)

Get mock.

func (*PrizesStoreMock) Set

func (w *PrizesStoreMock) Set(lotteryHeight uint32, winners []Winner) error

Set mock.

func (*PrizesStoreMock) Withdraw

func (w *PrizesStoreMock) Withdraw(publicKey string, amount uint64) error

Withdraw mock.

type Winner

type Winner struct {
	PublicKey string `json:"public_key,omitempty" db:"public_key"`
	Prize     uint64 `json:"prize,omitempty"`
	Ticket    uint64 `json:"ticket,omitempty"`
}

Winner represents a user that had a winning ticket.

type WinnersStore

type WinnersStore interface {
	Add(lotteryHeight uint32, winners []Winner) error
	List(lotteryHeight uint32) ([]Winner, error)
}

WinnersStore contains the methods used to store and retrieve winners from the database.

type WinnersStoreMock

type WinnersStoreMock struct {
	mock.Mock
}

WinnersStoreMock is a mocked implementation of a winners store.

func NewWinnersStoreMock

func NewWinnersStoreMock() *WinnersStoreMock

NewWinnersStoreMock returns a mocked winners store.

func (*WinnersStoreMock) Add

func (w *WinnersStoreMock) Add(height uint32, winners []Winner) error

Add mock.

func (*WinnersStoreMock) List

func (w *WinnersStoreMock) List(height uint32) ([]Winner, error)

List mock.

Jump to

Keyboard shortcuts

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