github.com/kisexp/xdchain@v0.0.0-20211206025815-490d6b732aa7/consensus/istanbul/ibft/types/state.go (about)

     1  package ibfttypes
     2  
     3  type State uint64
     4  
     5  const (
     6  	StateAcceptRequest State = iota
     7  	StatePreprepared
     8  	StatePrepared
     9  	StateCommitted
    10  )
    11  
    12  func (s State) String() string {
    13  	if s == StateAcceptRequest {
    14  		return "Accept request"
    15  	} else if s == StatePreprepared {
    16  		return "Preprepared"
    17  	} else if s == StatePrepared {
    18  		return "Prepared"
    19  	} else if s == StateCommitted {
    20  		return "Committed"
    21  	} else {
    22  		return "Unknown"
    23  	}
    24  }
    25  
    26  // Cmp compares s and y and returns:
    27  //   -1 if s is the previous state of y
    28  //    0 if s and y are the same state
    29  //   +1 if s is the next state of y
    30  func (s State) Cmp(y State) int {
    31  	if uint64(s) < uint64(y) {
    32  		return -1
    33  	}
    34  	if uint64(s) > uint64(y) {
    35  		return 1
    36  	}
    37  	return 0
    38  }