data

package
v0.2.3-rc6 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColAmount     = "amount"
	ColReferredBy = "referred_by"
	ColLevel      = "level"
	ColCountry    = "country"
)
View Source
const (
	ColReserved  = "reserved"
	ColWithdrawn = "withdrawn"
)
View Source
const (
	StatusActive   = "active"
	StatusBanned   = "banned"
	StatusLimited  = "limited"
	StatusAwaiting = "awaiting"
	StatusRewarded = "rewarded"
	StatusConsumed = "consumed"
)
View Source
const DefaultCountryCode = "default"

DefaultCountryCode is the special code, where the default settings for countries are stored. When a user's country is not found, it must be added to DB with its own code and default settings.

Variables

This section is empty.

Functions

This section is empty.

Types

type Balance

type Balance struct {
	Nullifier  string         `db:"nullifier"`
	Amount     int64          `db:"amount"`
	CreatedAt  int32          `db:"created_at"`
	UpdatedAt  int32          `db:"updated_at"`
	ReferredBy sql.NullString `db:"referred_by"`
	Rank       *int           `db:"rank"`
	Level      int            `db:"level"`
	Country    *string        `db:"country"`
}

type BalancesQ

type BalancesQ interface {
	New() BalancesQ
	Insert(Balance) error
	Update(map[string]any) error

	Page(*pgdb.OffsetPageParams) BalancesQ
	Select() ([]Balance, error)
	Get() (*Balance, error)
	// GetWithRank returns balance with rank, filtered by nullifier. No other filters can be applied.
	GetWithRank(nullifier string) (*Balance, error)
	SelectWithRank() ([]Balance, error)

	// WithoutPassportEvent returns balances which already
	// have scanned passport, but there no claimed events
	// for this. Filters are not applied.
	WithoutPassportEvent() ([]WithoutPassportEventBalance, error)
	WithoutReferralEvent() ([]ReferredReferrer, error)

	FilterByNullifier(...string) BalancesQ
	FilterDisabled() BalancesQ
}

type CountriesQ added in v0.2.1

type CountriesQ interface {
	New() CountriesQ
	Insert(countries ...Country) error
	Update(map[string]any) error
	// UpdateMany updates only reserve_limit, reserve_allowed and withdrawal_allowed
	UpdateMany([]Country) error
	Select() ([]Country, error)
	Get() (*Country, error)
	FilterByCodes(codes ...string) CountriesQ
}

type Country added in v0.2.1

type Country struct {
	Code              string `db:"code"`
	ReserveLimit      int64  `db:"reserve_limit"`
	Reserved          int64  `db:"reserved"`
	Withdrawn         int64  `db:"withdrawn"`
	ReserveAllowed    bool   `db:"reserve_allowed"`
	WithdrawalAllowed bool   `db:"withdrawal_allowed"`
}

type Event

type Event struct {
	ID           string         `db:"id"`
	Nullifier    string         `db:"nullifier"`
	Type         string         `db:"type"`
	Status       EventStatus    `db:"status"`
	CreatedAt    int32          `db:"created_at"`
	UpdatedAt    int32          `db:"updated_at"`
	Meta         Jsonb          `db:"meta"`
	PointsAmount *int64         `db:"points_amount"`
	ExternalID   sql.NullString `db:"external_id"` // hidden from client
}

type EventStatus

type EventStatus string
const (
	EventOpen      EventStatus = "open"
	EventFulfilled EventStatus = "fulfilled"
	EventClaimed   EventStatus = "claimed"
)

func (EventStatus) String

func (s EventStatus) String() string

type EventsQ

type EventsQ interface {
	New() EventsQ
	Insert(...Event) error
	Update(status EventStatus, meta json.RawMessage, points *int64) (*Event, error)
	Delete() (rowsAffected int64, err error)
	Transaction(func() error) error

	Page(*pgdb.OffsetPageParams) EventsQ
	Select() ([]Event, error)
	Get() (*Event, error)
	// Count returns the total number of events that match filters. Page is not
	// applied to this method.
	Count() (int, error)
	// SelectReopenable returns events matching criteria: there are no open or
	// fulfilled events of this type for a specific user.
	SelectReopenable() ([]ReopenableEvent, error)
	// SelectAbsentTypes returns events matching criteria: there are no events of
	// this type for a specific user. Filters are not applied to this selection.
	SelectAbsentTypes(allTypes ...string) ([]ReopenableEvent, error)

	FilterByID(...string) EventsQ
	FilterByNullifier(string) EventsQ
	FilterByStatus(...EventStatus) EventsQ
	FilterByType(...string) EventsQ
	FilterByNotType(types ...string) EventsQ
	FilterByUpdatedAtBefore(int64) EventsQ
	FilterByExternalID(string) EventsQ
	FilterInactiveNotClaimed(types ...string) EventsQ
}

type Jsonb

type Jsonb json.RawMessage

func (*Jsonb) Scan

func (j *Jsonb) Scan(src interface{}) error

func (*Jsonb) UnmarshalJSON

func (j *Jsonb) UnmarshalJSON(data []byte) error

func (*Jsonb) Value

func (j *Jsonb) Value() (driver.Value, error)

type Referral

type Referral struct {
	ID        string `db:"id"`
	Nullifier string `db:"nullifier"`
	UsageLeft int32  `db:"usage_left"`
	Status    string `db:"status"`
}

type ReferralsQ

type ReferralsQ interface {
	New() ReferralsQ
	Insert(...Referral) error
	Consume(ids ...string) (consumedIDs []string, err error)
	ConsumeFirst(nullifier string, count uint64) error

	Select() ([]Referral, error)
	Get(id string) (*Referral, error)
	Count() (uint64, error)

	Update(usageLeft int) (*Referral, error)

	WithStatus() ReferralsQ
	FilterByNullifier(string) ReferralsQ
	FilterConsumed() ReferralsQ
}

type ReferredReferrer added in v0.2.1

type ReferredReferrer struct {
	Referred string `db:"referred"`
	Referrer string `db:"referrer"`
}

type ReopenableEvent

type ReopenableEvent struct {
	Nullifier string `db:"nullifier"`
	Type      string `db:"type"`
}

ReopenableEvent is a pair that is sufficient to build a new open event with a specific type for a user

type Withdrawal

type Withdrawal struct {
	ID        string `db:"id"`
	Nullifier string `db:"nullifier"`
	Amount    int64  `db:"amount"`
	Address   string `db:"address"`
	CreatedAt int32  `db:"created_at"`
}

type WithdrawalsQ

type WithdrawalsQ interface {
	New() WithdrawalsQ
	Insert(Withdrawal) (*Withdrawal, error)

	Page(*pgdb.CursorPageParams) WithdrawalsQ
	Select() ([]Withdrawal, error)

	FilterByNullifier(string) WithdrawalsQ
}

type WithoutPassportEventBalance added in v0.2.1

type WithoutPassportEventBalance struct {
	Balance
	EventID     string      `db:"event_id"`
	EventStatus EventStatus `db:"event_status"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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