code.vegaprotocol.io/vega@v0.79.0/datanode/service/rewards.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package service 17 18 import ( 19 "context" 20 21 "code.vegaprotocol.io/vega/datanode/entities" 22 "code.vegaprotocol.io/vega/logging" 23 ) 24 25 type RewardStore interface { 26 Add(ctx context.Context, r entities.Reward) error 27 GetAll(ctx context.Context) ([]entities.Reward, error) 28 GetByTxHash(ctx context.Context, txHash entities.TxHash) ([]entities.Reward, error) 29 GetByCursor(ctx context.Context, partyID []string, assetID *string, fromEpoch, toEpoch *uint64, p entities.CursorPagination, teamID, gameID, marketID *string) ([]entities.Reward, entities.PageInfo, error) 30 GetSummaries(ctx context.Context, partyID []string, assetID *string) ([]entities.RewardSummary, error) 31 GetEpochSummaries(ctx context.Context, filter entities.RewardSummaryFilter, p entities.CursorPagination) ([]entities.EpochRewardSummary, entities.PageInfo, error) 32 } 33 34 type Reward struct { 35 store RewardStore 36 } 37 38 func NewReward(store RewardStore, log *logging.Logger) *Reward { 39 return &Reward{ 40 store: store, 41 } 42 } 43 44 func (r *Reward) Add(ctx context.Context, reward entities.Reward) error { 45 err := r.store.Add(ctx, reward) 46 if err != nil { 47 return err 48 } 49 return nil 50 } 51 52 func (r *Reward) GetAll(ctx context.Context) ([]entities.Reward, error) { 53 return r.store.GetAll(ctx) 54 } 55 56 func (r *Reward) GetByTxHash(ctx context.Context, txHash entities.TxHash) ([]entities.Reward, error) { 57 return r.store.GetByTxHash(ctx, txHash) 58 } 59 60 func (r *Reward) GetByCursor(ctx context.Context, partyIDs []string, assetID *string, fromEpoch, toEpoch *uint64, p entities.CursorPagination, teamID, gameID, marketID *string) ([]entities.Reward, entities.PageInfo, error) { 61 return r.store.GetByCursor(ctx, partyIDs, assetID, fromEpoch, toEpoch, p, teamID, gameID, marketID) 62 } 63 64 func (r *Reward) GetSummaries(ctx context.Context, partyIDs []string, assetID *string) ([]entities.RewardSummary, error) { 65 return r.store.GetSummaries(ctx, partyIDs, assetID) 66 } 67 68 func (r *Reward) GetEpochRewardSummaries(ctx context.Context, filter entities.RewardSummaryFilter, p entities.CursorPagination) ([]entities.EpochRewardSummary, entities.PageInfo, error) { 69 return r.store.GetEpochSummaries(ctx, filter, p) 70 }