Documentation
¶
Overview ¶
Package db contains the logic necessary to store BTRY's information.
Index ¶
- Variables
- func AddPagination(query string, offset, limit uint64, sortField string, reverse bool) string
- func BulkInsertValues(rows, values int) string
- func UpdatePrizes(amount uint64, prizes []*PrizesRow) error
- type Bet
- type BetsStore
- type BetsStoreMock
- type DB
- type LightningStore
- type LightningStoreMock
- type LotteriesStore
- type LotteriesStoreMock
- type NotificationsStore
- type NotificationsStoreMock
- type PrizesRow
- type PrizesStore
- type PrizesStoreMock
- type Winner
- type WinnersStore
- type WinnersStoreMock
Constants ¶
This section is empty.
Variables ¶
var ErrInsufficientPrizes = errors.New("withdrawal amount is higher than assigned prizes")
ErrInsufficientPrizes is returned when the user requests more than he has.
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.
var ErrNoChatID = errors.New("no chat ID linked to this public key")
Functions ¶
func AddPagination ¶
AddPagination returns the pagination part of an SQL query.
func BulkInsertValues ¶
BulkInsertValues builds a query to insert multiple values in a single database call.
func UpdatePrizes ¶
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 ¶
BetsStoreMock is a mocked implementation of the bets store.
func NewBetsStoreMock ¶
func NewBetsStoreMock() *BetsStoreMock
NewBetsStoreMock returns a mocked bets store.
func (*BetsStoreMock) GetPrizePool ¶
func (b *BetsStoreMock) GetPrizePool(lotteryHeight uint32) (uint64, error)
GetPrizePool 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.
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 ¶
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 ¶
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 ¶
NotificationsStoreMock is a mocked implementation of the Notifications store.
func NewNotificationsStoreMock ¶
func NewNotificationsStoreMock() *NotificationsStoreMock
NewNotificationsStoreMock returns a mocked Notifications store.
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 ¶
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.
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 ¶
WinnersStoreMock is a mocked implementation of a winners store.
func NewWinnersStoreMock ¶
func NewWinnersStoreMock() *WinnersStoreMock
NewWinnersStoreMock returns a mocked winners store.