github.com/iotexproject/iotex-core@v1.14.1-rc1/consensus/consensusfsm/consensusevent.go (about)

     1  // Copyright (c) 2019 IoTeX Foundation
     2  // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
     3  // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
     4  // This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
     5  
     6  package consensusfsm
     7  
     8  import (
     9  	"time"
    10  
    11  	fsm "github.com/iotexproject/go-fsm"
    12  )
    13  
    14  // ConsensusEvent defines the event used in the fsm
    15  type ConsensusEvent struct {
    16  	fsm.Event
    17  	height       uint64
    18  	round        uint32
    19  	eventType    fsm.EventType
    20  	creationTime time.Time
    21  	data         interface{}
    22  }
    23  
    24  // NewConsensusEvent creates a new consensus event
    25  func NewConsensusEvent(
    26  	eventType fsm.EventType,
    27  	data interface{},
    28  	height uint64,
    29  	round uint32,
    30  	creationTime time.Time,
    31  ) *ConsensusEvent {
    32  	return &ConsensusEvent{
    33  		data:         data,
    34  		height:       height,
    35  		round:        round,
    36  		eventType:    eventType,
    37  		creationTime: creationTime,
    38  	}
    39  }
    40  
    41  // Height is the height of the event
    42  func (e *ConsensusEvent) Height() uint64 {
    43  	return e.height
    44  }
    45  
    46  // Round is the round of the event
    47  func (e *ConsensusEvent) Round() uint32 {
    48  	return e.round
    49  }
    50  
    51  // Type returns the event type
    52  func (e *ConsensusEvent) Type() fsm.EventType {
    53  	return e.eventType
    54  }
    55  
    56  // Timestamp is the creation time of the event
    57  func (e *ConsensusEvent) Timestamp() time.Time {
    58  	return e.creationTime
    59  }
    60  
    61  // Data returns the data of the event
    62  func (e *ConsensusEvent) Data() interface{} {
    63  	return e.data
    64  }