rewards

package
v0.0.0-...-e9c30ff Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeReward

func ComputeReward(totalAmount payment.Amount, numUsers int) payment.Amount

ComputeReward calculates how much each user should receive

Types

type ActivityChallenge

type ActivityChallenge struct {
	ChallengedAt time.Time
	ID           string
	Types        []ActivityChallengeType
	Tolerance    time.Duration
}

func (*ActivityChallenge) SerializeForAPI

func (a *ActivityChallenge) SerializeForAPI() *proto.ActivityChallenge

type ActivityChallengeType

type ActivityChallengeType string

ActivityChallengeType is a type of activity challenge

var (
	// ActivityChallengeTypeButton is a button activity challenge
	ActivityChallengeTypeButton ActivityChallengeType = "button"
	// ActivityChallengeTypeSegcha is a segcha activity challenge
	ActivityChallengeTypeSegcha ActivityChallengeType = "segcha"
	// ActivityChallengeTypeTurnstile is a Cloudflare Turnstile activity challenge
	ActivityChallengeTypeTurnstile ActivityChallengeType = "turnstile"
	// ActivityChallengeTypeModerating is a moderation activity challenge
	ActivityChallengeTypeModerating ActivityChallengeType = "moderating"
)

type ChallengeCheckFunction

type ChallengeCheckFunction func(context.Context, *ActivityChallenge, string) (bool, error)

ChallengeCheckFunction checks activity challenge response correctness

type Handler

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

Handler handles reward distribution among spectators

func NewHandler

func NewHandler(log *log.Logger,
	statsClient *statsd.Client,
	mediaQueue *mediaqueue.MediaQueue,
	ipReputationChecker *ipreputation.Checker,
	withdrawalHandler *withdrawalhandler.Handler,
	wallet *wallet.Wallet,
	collectorAccountQueue chan func(*wallet.Account, *rpc.Client, *rpc.Client),
	skipManager *skipmanager.Manager,
	chatManager *chatmanager.Manager,
	pointsManager *pointsmanager.Manager,
	notificationManager *notificationmanager.Manager,
	paymentAccountPool *payment.PaymentAccountPool,
	moderationStore moderation.Store,
	staffActivityManager *staffactivitymanager.Manager,
	challengeCheckers map[ActivityChallengeType]ChallengeCheckFunction,
	versionHashGetter func() string) (*Handler, error)

NewHandler creates a new RewardsHandler

func (*Handler) ConnectedSpectators

func (r *Handler) ConnectedSpectators() []Spectator

func (*Handler) CountConnectedSpectatorsOnRemoteAddress

func (r *Handler) CountConnectedSpectatorsOnRemoteAddress(remoteAddress string) int

func (*Handler) EstimateEligibleSpectators

func (r *Handler) EstimateEligibleSpectators() (int, bool)

func (*Handler) GetSpectator

func (r *Handler) GetSpectator(address string) (Spectator, bool)

func (*Handler) GetSpectatorActivityStatus

func (r *Handler) GetSpectatorActivityStatus(address string) proto.UserStatus

func (*Handler) MarkAddressAsActiveEvenIfChallenged

func (r *Handler) MarkAddressAsActiveEvenIfChallenged(ctx context.Context, address string) error

func (*Handler) MarkAddressAsActiveIfNotChallenged

func (r *Handler) MarkAddressAsActiveIfNotChallenged(ctx context.Context, address string) error

func (*Handler) MarkAddressAsNotLegitimate

func (r *Handler) MarkAddressAsNotLegitimate(ctx context.Context, address string)

func (*Handler) RegisterSpectator

func (r *Handler) RegisterSpectator(ctx context.Context, user auth.User) (Spectator, error)

func (*Handler) RemoteAddressesForRewardAddress

func (r *Handler) RemoteAddressesForRewardAddress(ctx context.Context, rewardAddress string) map[string]struct{}

func (*Handler) ResetAddressLegitimacyStatus

func (r *Handler) ResetAddressLegitimacyStatus(ctx context.Context, address string) error

func (*Handler) RewardsDistributed

func (r *Handler) RewardsDistributed() event.Event[RewardsDistributedEventArgs]

RewardsDistributed is the event that is fired when rewards are distributed for a queue entry

func (*Handler) SolveActivityChallenge

func (r *Handler) SolveActivityChallenge(ctxCtx context.Context, challenge string, checkResponses []string, trusted bool, clientVersion string) (skippedClientIntegrityChecks bool, err error)

func (*Handler) SpectatorConnected

func (r *Handler) SpectatorConnected() event.Event[Spectator]

SpectatorConnected is the event that is fired when a spectator establishes their first connection

func (*Handler) SpectatorDisconnected

func (r *Handler) SpectatorDisconnected() event.Event[Spectator]

SpectatorDisconnected is the event that is fired when a spectator disconnects their last remaining connection

func (*Handler) SpectatorHasActivityChallenge

func (r *Handler) SpectatorHasActivityChallenge(address string, challengeType ActivityChallengeType) bool

func (*Handler) UnregisterSpectator

func (r *Handler) UnregisterSpectator(ctx context.Context, sInterface Spectator) error

func (*Handler) Worker

func (r *Handler) Worker(ctx context.Context) error

type RewardsDistributedEventArgs

type RewardsDistributedEventArgs struct {
	RewardBudget       payment.Amount
	EligibleSpectators []string
	RequesterReward    payment.Amount
	Media              media.QueueEntry
}

RewardsDistributedEventArgs are the arguments to the event that is fired when rewards are distributed for a queue entry

type Spectator

type Spectator interface {
	User() auth.User
	OnActivityChallenge() event.Event[*ActivityChallenge]
	CurrentActivityChallenge() *ActivityChallenge
	Legitimate() (bool, time.Time)
	CurrentRemoteAddress() string
	GoodRemoteAddressReputation(context.Context, *Handler) (bool, bool)
	CountOtherConnectedSpectatorsOnSameRemoteAddress(*Handler) int
	WatchingSince() time.Time
	StoppedWatching() (bool, time.Time)
	ConnectionCount() int
}

Jump to

Keyboard shortcuts

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