services

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LevelInfos = []*LevelInfo{
	{Level: 1, MinWeeks: 0, Points: 0},
	{Level: 2, MinWeeks: 4, Points: 1000},
	{Level: 3, MinWeeks: 21, Points: 2000},
	{Level: 4, MinWeeks: 36, Points: 3000},
}

Functions

func Consume added in v1.0.0

func Consume(ctx context.Context, group sarama.ConsumerGroup, settings *config.Settings, statusProc *TransferStatusProcessor) error

func GetWeekNum

func GetWeekNum(t time.Time) int

GetWeekNum calculates the number of the week in which the given time lies for DIMO point issuance, which at the time of writing starts at 2022-01-31 05:00 UTC. Indexing is zero-based.

func GetWeekNumForCron

func GetWeekNumForCron(t time.Time) int

GetWeekNumForCron calculates the week number for the current run of the cron job. We expect the job to run every Monday at 05:00 UTC, but due to skew we just round the time.

func NumToWeekEnd

func NumToWeekEnd(n int) time.Time

func NumToWeekStart

func NumToWeekStart(n int) time.Time

Types

type ActivityResp

type ActivityResp struct {
	Hits struct {
		Hits []struct {
			Source struct {
				Data struct {
					Timestamp time.Time `json:"timestamp"`
				} `json:"data"`
			} `json:"_source"`
		} `json:"hits"`
	} `json:"hits"`
}

type BaselineClient added in v1.7.0

type BaselineClient struct {
	TransferService *TransferService
	DataService     DeviceActivityClient
	DevicesClient   DevicesClient
	DefsClient      IntegrationsGetter
	ContractAddress common.Address
	Week            int
	Logger          *zerolog.Logger
}

func NewBaselineRewardService added in v1.7.0

func NewBaselineRewardService(
	settings *config.Settings,
	transferService *TransferService,
	dataService DeviceActivityClient,
	devicesClient DevicesClient,
	defsClient IntegrationsGetter,
	week int,
	logger *zerolog.Logger,

) *BaselineClient

func (*BaselineClient) BaselineIssuance added in v1.7.0

func (t *BaselineClient) BaselineIssuance(issuanceWeek int) error

func (*BaselineClient) BatchTransfer added in v1.7.0

func (c *BaselineClient) BatchTransfer(requestID string, users []common.Address, values []*big.Int, vehicleIds []*big.Int) error

func (*BaselineClient) Calculate added in v1.7.0

func (t *BaselineClient) Calculate(issuanceWeek int) error

type BaselineProcessor added in v1.7.0

type BaselineProcessor struct {
	Address                common.Address
	ABI                    *abi.ABI
	DidntQualifyEvent      abi.Event
	TokensTransferredEvent abi.Event
}

type ContractEventStreamConsumer added in v1.5.0

type ContractEventStreamConsumer struct {
	Db db.Store
	// contains filtered or unexported fields
}

func NewEventConsumer added in v1.5.0

func NewEventConsumer(db db.Store, logger *zerolog.Logger, tc *TokenConfig) (*ContractEventStreamConsumer, error)

func (*ContractEventStreamConsumer) Cleanup added in v1.5.0

func (*ContractEventStreamConsumer) ConsumeClaim added in v1.5.0

func (*ContractEventStreamConsumer) Setup added in v1.5.0

type DeviceActivityClient added in v1.5.0

type DeviceActivityClient interface {
	DescribeActiveDevices(start, end time.Time) ([]*DeviceData, error)
}

type DeviceData

type DeviceData struct {
	ID           string
	Integrations []string
	Serials      []string
}

type DeviceDataClient

type DeviceDataClient interface {
	GetLastActivity(userDeviceID string) (lastActivity time.Time, seen bool, err error)
	DescribeActiveDevices(start, end time.Time) ([]*DeviceData, error)
	GetIntegrations(userDeviceID string, start, end time.Time) (ints []string, err error)
}

func NewDeviceDataClient

func NewDeviceDataClient(settings *config.Settings) DeviceDataClient

type DeviceIntegrationsResp

type DeviceIntegrationsResp struct {
	Aggregations struct {
		Integrations struct {
			Buckets []struct {
				Key string `json:"key"`
			} `json:"buckets"`
		} `json:"integrations"`
		UnitIDs struct {
			Buckets []struct {
				Key string `json:"key"`
			} `json:"buckets"`
		} `json:"unit_ids"`
	} `json:"aggregations"`
}

type DeviceListResp

type DeviceListResp struct {
	Aggregations struct {
		ActiveDevices struct {
			AfterKey struct {
				Subject *string `json:"subject"`
			} `json:"after_key"`
			Buckets []struct {
				Key struct {
					Subject string `json:"subject"`
				} `json:"key"`
				Integrations struct {
					Buckets []struct {
						Key string `json:"key"`
					} `json:"buckets"`
				} `json:"integrations"`
				UnitIDs struct {
					Buckets []struct {
						Key string `json:"key"`
					} `json:"buckets"`
				} `json:"unit_ids"`
			} `json:"buckets"`
		} `json:"active_devices"`
	} `json:"aggregations"`
}

type DevicesClient added in v1.5.0

type DevicesClient interface {
	GetUserDevice(ctx context.Context, in *pb_devices.GetUserDeviceRequest, opts ...grpc.CallOption) (*pb_devices.UserDevice, error)
}

type IntegrationsGetter added in v1.5.0

type IntegrationsGetter interface {
	GetIntegrations(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*pb_defs.GetIntegrationResponse, error)
}

type LevelInfo

type LevelInfo struct {
	Level    int
	MinWeeks int
	Points   int
}

func GetLevel

func GetLevel(connStreak int) *LevelInfo

type Referrals added in v1.7.0

type Referrals struct {
	Referees  []common.Address
	Referrers []common.Address
}

type ReferralsClient added in v1.7.0

type ReferralsClient struct {
	TransferService *TransferService
	ContractAddress common.Address
	Week            int
	Logger          *zerolog.Logger
	UsersClient     pb.UserServiceClient
}

func NewReferralBonusService added in v1.7.0

func NewReferralBonusService(
	settings *config.Settings,
	transferService *TransferService,
	week int,
	logger *zerolog.Logger,
	userClient pb.UserServiceClient) *ReferralsClient

func (*ReferralsClient) BatchTransferReferralBonuses added in v1.7.0

func (c *ReferralsClient) BatchTransferReferralBonuses(requestID string, referrees []common.Address, referrers []common.Address) error

func (*ReferralsClient) CollectReferrals added in v1.7.0

func (c *ReferralsClient) CollectReferrals(ctx context.Context, issuanceWeek int) (Referrals, error)

CollectReferrals returns address pairs for referrals completed in the given week. These will come from referees who are earning for the first time and have a referrer attached to their account.

func (*ReferralsClient) ReferralsIssuance added in v1.7.0

func (c *ReferralsClient) ReferralsIssuance(ctx context.Context) error

type ReferralsProcessor added in v1.7.0

type ReferralsProcessor struct {
	Address          common.Address
	ABI              *abi.ABI
	ReferralInvalid  abi.Event
	ReferralComplete abi.Event
}

type StreakInput

type StreakInput struct {
	ConnectedThisWeek           bool
	ExistingConnectionStreak    int
	ExistingDisconnectionStreak int
}

type StreakOutput

type StreakOutput struct {
	DisconnectionStreak int
	ConnectionStreak    int
	Points              int
}

func ComputeStreak

func ComputeStreak(i StreakInput) StreakOutput

func FakeStreak added in v1.3.0

func FakeStreak(connectionStreak int) StreakOutput

type TokenConfig added in v1.5.0

type TokenConfig struct {
	Tokens []struct {
		ChainID int64          `yaml:"chainId"`
		Address common.Address `yaml:"address"`
		RPCURL  string         `yaml:"rpcUrl"`
	} `yaml:"tokens"`
}

type TransferService added in v1.7.0

type TransferService struct {
	Producer     sarama.SyncProducer
	Consumer     sarama.ConsumerGroup
	RequestTopic string
	StatusTopic  string

	ContractAddress common.Address
	// contains filtered or unexported fields
}

func NewTokenTransferService added in v1.0.0

func NewTokenTransferService(
	settings *config.Settings,
	producer sarama.SyncProducer,

	db db.Store) *TransferService

type TransferStatusProcessor added in v1.0.0

type TransferStatusProcessor struct {
	ReferralsProcessor *ReferralsProcessor
	BaselineProcessor  *BaselineProcessor
	DB                 db.Store
	Logger             *zerolog.Logger
}

func NewStatusProcessor added in v1.0.0

func NewStatusProcessor(pdb db.Store, logger *zerolog.Logger, settings *config.Settings) (*TransferStatusProcessor, error)

Jump to

Keyboard shortcuts

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