code.vegaprotocol.io/vega@v0.79.0/core/events/referral_program.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 events
    17  
    18  import (
    19  	"context"
    20  	"time"
    21  
    22  	"code.vegaprotocol.io/vega/core/types"
    23  	eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1"
    24  )
    25  
    26  type ReferralProgramStarted struct {
    27  	*Base
    28  	e eventspb.ReferralProgramStarted
    29  }
    30  
    31  func (t ReferralProgramStarted) StreamMessage() *eventspb.BusEvent {
    32  	busEvent := newBusEventFromBase(t.Base)
    33  	busEvent.Event = &eventspb.BusEvent_ReferralProgramStarted{
    34  		ReferralProgramStarted: &t.e,
    35  	}
    36  
    37  	return busEvent
    38  }
    39  
    40  func NewReferralProgramStartedEvent(ctx context.Context, p *types.ReferralProgram, epochTime time.Time, epoch uint64) *ReferralProgramStarted {
    41  	return &ReferralProgramStarted{
    42  		Base: newBase(ctx, ReferralProgramStartedEvent),
    43  		e: eventspb.ReferralProgramStarted{
    44  			Program:   p.IntoProto(),
    45  			StartedAt: epochTime.UnixNano(),
    46  			AtEpoch:   epoch,
    47  		},
    48  	}
    49  }
    50  
    51  func (r ReferralProgramStarted) GetReferralProgramStarted() *eventspb.ReferralProgramStarted {
    52  	return &r.e
    53  }
    54  
    55  func ReferralProgramStartedEventFromStream(ctx context.Context, be *eventspb.BusEvent) *ReferralProgramStarted {
    56  	return &ReferralProgramStarted{
    57  		Base: newBaseFromBusEvent(ctx, ReferralProgramStartedEvent, be),
    58  		e:    *be.GetReferralProgramStarted(),
    59  	}
    60  }
    61  
    62  type ReferralProgramUpdated struct {
    63  	*Base
    64  	e eventspb.ReferralProgramUpdated
    65  }
    66  
    67  func (t ReferralProgramUpdated) StreamMessage() *eventspb.BusEvent {
    68  	busEvent := newBusEventFromBase(t.Base)
    69  	busEvent.Event = &eventspb.BusEvent_ReferralProgramUpdated{
    70  		ReferralProgramUpdated: &t.e,
    71  	}
    72  
    73  	return busEvent
    74  }
    75  
    76  func (r ReferralProgramUpdated) GetReferralProgramUpdated() *eventspb.ReferralProgramUpdated {
    77  	return &r.e
    78  }
    79  
    80  func NewReferralProgramUpdatedEvent(ctx context.Context, p *types.ReferralProgram, epochTime time.Time, epoch uint64) *ReferralProgramUpdated {
    81  	return &ReferralProgramUpdated{
    82  		Base: newBase(ctx, ReferralProgramUpdatedEvent),
    83  		e: eventspb.ReferralProgramUpdated{
    84  			Program:   p.IntoProto(),
    85  			UpdatedAt: epochTime.UnixNano(),
    86  			AtEpoch:   epoch,
    87  		},
    88  	}
    89  }
    90  
    91  func ReferralProgramUpdatedEventFromStream(ctx context.Context, be *eventspb.BusEvent) *ReferralProgramUpdated {
    92  	return &ReferralProgramUpdated{
    93  		Base: newBaseFromBusEvent(ctx, ReferralProgramUpdatedEvent, be),
    94  		e:    *be.GetReferralProgramUpdated(),
    95  	}
    96  }
    97  
    98  type ReferralProgramEnded struct {
    99  	*Base
   100  	e eventspb.ReferralProgramEnded
   101  }
   102  
   103  func (t ReferralProgramEnded) StreamMessage() *eventspb.BusEvent {
   104  	busEvent := newBusEventFromBase(t.Base)
   105  	busEvent.Event = &eventspb.BusEvent_ReferralProgramEnded{
   106  		ReferralProgramEnded: &t.e,
   107  	}
   108  
   109  	return busEvent
   110  }
   111  
   112  func (t ReferralProgramEnded) GetReferralProgramEnded() *eventspb.ReferralProgramEnded {
   113  	return &t.e
   114  }
   115  
   116  func NewReferralProgramEndedEvent(ctx context.Context, version uint64, id string, epochTime time.Time, epoch uint64) *ReferralProgramEnded {
   117  	return &ReferralProgramEnded{
   118  		Base: newBase(ctx, ReferralProgramEndedEvent),
   119  		e: eventspb.ReferralProgramEnded{
   120  			Version: version,
   121  			Id:      id,
   122  			EndedAt: epochTime.UnixNano(),
   123  			AtEpoch: epoch,
   124  		},
   125  	}
   126  }
   127  
   128  func ReferralProgramEndedEventFromStream(ctx context.Context, be *eventspb.BusEvent) *ReferralProgramEnded {
   129  	return &ReferralProgramEnded{
   130  		Base: newBaseFromBusEvent(ctx, ReferralProgramEndedEvent, be),
   131  		e:    *be.GetReferralProgramEnded(),
   132  	}
   133  }