pool

package
v1.13.28 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxParticipants = 1000
)

Variables

View Source
var (
	ErrPoolNotFound                 = errors.New("pool not found")
	ErrPoolIDExists                 = errors.New("pool id already exists")
	ErrPoolFundingDestinationExists = errors.New("pool funding address already exists")
	ErrPoolOpen                     = errors.New("pool is open")
	ErrPoolResolved                 = errors.New("pool is already resolved")
	ErrBetNotFound                  = errors.New("bet not found")
	ErrBetExists                    = errors.New("bet already exists")
	ErrMaxBetCountExceeded          = errors.New("max bet count exceeded")
	ErrMemberNotFound               = errors.New("pool member not found")
)

Functions

func BetIDString

func BetIDString(id *poolpb.BetId) string

func GetUserSummary added in v1.8.17

func GetUserSummary(ctx context.Context, pools Store, codeData codedata.Provider, userID *commonpb.UserId, pool *Pool) (*poolpb.UserPoolSummary, error)

func NewStaleEventDetector added in v1.10.5

func NewStaleEventDetector() event.StaleEventDetector[*eventpb.Event]

func PoolIDString

func PoolIDString(id *poolpb.PoolId) string

func ToBetID

func ToBetID(keyPair model.KeyPair) *poolpb.BetId

func ToPoolID

func ToPoolID(keyPair model.KeyPair) *poolpb.PoolId

func VerifyBetSignature

func VerifyBetSignature(log *zap.Logger, poolID *poolpb.PoolId, signedBet *poolpb.SignedBetMetadata, signature *commonpb.Signature) bool

func VerifyPoolSignature

func VerifyPoolSignature(log *zap.Logger, signedPool *poolpb.SignedPoolMetadata, signature *commonpb.Signature) bool

Types

type Bet

type Bet struct {
	PoolID            *poolpb.PoolId
	ID                *poolpb.BetId
	UserID            *commonpb.UserId
	SelectedOutcome   bool
	PayoutDestination *commonpb.PublicKey
	Ts                time.Time
	IsIntentSubmitted bool // Use IsPaid utility before trusting this value
	Signature         *commonpb.Signature
}

func CloneBets

func CloneBets(bets []*Bet) []*Bet

func GetBetSummary added in v1.8.17

func GetBetSummary(ctx context.Context, pools Store, codeData codedata.Provider, pool *Pool) (*poolpb.BetSummary, []*Bet, error)

todo: optimize when we don't require the entire bet list

func ToBetModel

func ToBetModel(poolID *poolpb.PoolId, proto *poolpb.SignedBetMetadata, signature *commonpb.Signature) *Bet

func (*Bet) Clone

func (b *Bet) Clone() *Bet

func (*Bet) IsPaid added in v1.8.11

func (b *Bet) IsPaid(ctx context.Context, pools Store, codeData codedata.Provider, pool *Pool) (bool, error)

func (*Bet) ToProto

func (b *Bet) ToProto() *poolpb.BetMetadata

type IntentHandler added in v1.10.5

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

todo: add tests

func NewIntentHandler added in v1.10.5

func NewIntentHandler(pools Store, codeData codedata.Provider, eventForwarder event.Forwarder) *IntentHandler

func (*IntentHandler) OnSuccessfulBetPayment added in v1.10.5

func (h *IntentHandler) OnSuccessfulBetPayment(ctx context.Context, intentRecord *codeintent.Record) error

func (*IntentHandler) ValidateBetPayment added in v1.10.5

func (h *IntentHandler) ValidateBetPayment(ctx context.Context, intentRecord *codeintent.Record) error

func (*IntentHandler) ValidateDistribution added in v1.10.5

func (h *IntentHandler) ValidateDistribution(ctx context.Context, intentRecord *codeintent.Record, actions []*codetransactionpb.Action) error

type Member added in v1.8.1

type Member struct {
	ID     []byte
	UserID *commonpb.UserId
	PoolID *poolpb.PoolId
}

func CloneMembers added in v1.8.1

func CloneMembers(members []*Member) []*Member

func (*Member) Clone added in v1.8.1

func (m *Member) Clone() *Member

type Pool

type Pool struct {
	ID                 *poolpb.PoolId
	CreatorID          *commonpb.UserId
	Name               string
	BuyInCurrency      string
	BuyInAmount        float64
	FundingDestination *commonpb.PublicKey
	IsOpen             bool
	Resolution         Resolution
	CreatedAt          time.Time
	ClosedAt           *time.Time
	Signature          *commonpb.Signature
}

func ClonePools

func ClonePools(pools []*Pool) []*Pool

func ToPoolModel

func ToPoolModel(proto *poolpb.SignedPoolMetadata, signature *commonpb.Signature) *Pool

func (*Pool) Clone

func (p *Pool) Clone() *Pool

func (*Pool) HasResolution added in v1.8.11

func (p *Pool) HasResolution() bool

func (*Pool) ToProto

func (p *Pool) ToProto() *poolpb.PoolMetadata

type Resolution added in v1.8.4

type Resolution int
const (
	ResolutionUnknown Resolution = iota
	ResolutionRefunded
	ResolutionYes
	ResolutionNo
)

func ToResolution added in v1.8.4

func ToResolution(proto *poolpb.Resolution) Resolution

func (Resolution) String added in v1.8.4

func (r Resolution) String() string

func (*Resolution) ToProto added in v1.8.4

func (r *Resolution) ToProto() *poolpb.Resolution

type Server

type Server struct {
	poolpb.UnimplementedPoolServer
	// contains filtered or unexported fields
}

func NewServer

func NewServer(
	log *zap.Logger,
	authz auth.Authorizer,
	accounts account.Store,
	pools Store,
	profiles profile.Store,
	codeData codedata.Provider,
	eventBus *event.Bus[*commonpb.UserId, *eventpb.Event],
	pusher push.Pusher,
) *Server

func (*Server) ClosePool added in v1.8.3

func (*Server) CreatePool

todo: Add buy in amount validation (min/max)

func (*Server) GetPagedPools added in v1.8.1

func (*Server) GetPool

func (*Server) MakeBet

func (*Server) ResolvePool

type StaleEventDetector added in v1.10.5

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

todo: add tests

func (*StaleEventDetector) ShouldDrop added in v1.10.5

func (d *StaleEventDetector) ShouldDrop(e *eventpb.Event) bool

type Store

type Store interface {
	// Create pool creates a new betting pool
	CreatePool(ctx context.Context, pool *Pool) error

	// ClosePool closes a pool
	ClosePool(ctx context.Context, poolID *poolpb.PoolId, closedAt time.Time, newSignature *commonpb.Signature) error

	// ResolvePool resolves a pool with an outcome
	ResolvePool(ctx context.Context, poolID *poolpb.PoolId, resolution Resolution, newSignature *commonpb.Signature) error

	// GetPoolByID gets a betting pool by ID
	GetPoolByID(ctx context.Context, poolID *poolpb.PoolId) (*Pool, error)

	// GetPoolByFundingDestination gets a betting pool by the funding destination
	GetPoolByFundingDestination(ctx context.Context, fundingDestination *commonpb.PublicKey) (*Pool, error)

	// CreateBet creates a new bet
	CreateBet(ctx context.Context, bet *Bet) error

	// UpdateBetOutcome updates an existing bet's outcome
	UpdateBetOutcome(ctx context.Context, betId *poolpb.BetId, newOutcome bool, newSignature *commonpb.Signature, newTs time.Time) error

	// MarkBetAsPaid marks a bet as paid
	MarkBetAsPaid(ctx context.Context, betId *poolpb.BetId) error

	// GetBetByID gets a bet by its ID
	GetBetByID(ctx context.Context, betID *poolpb.BetId) (*Bet, error)

	// GetBetByUser gets a bet for a pool made by a user
	GetBetByUser(ctx context.Context, poolID *poolpb.PoolId, userID *commonpb.UserId) (*Bet, error)

	// GetBetsByPool gets all bets for a given pool
	GetBetsByPool(ctx context.Context, poolID *poolpb.PoolId) ([]*Bet, error)

	// GetMember gets the pool memberships for the provided pool and user
	GetMember(ctx context.Context, poolID *poolpb.PoolId, userID *commonpb.UserId) (*Member, error)

	// GetPagedMembers gets the set of pool memberships for the provided user
	// over a paged API
	GetPagedMembers(ctx context.Context, userID *commonpb.UserId, options ...database.QueryOption) ([]*Member, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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