github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/dkg/state.go (about)

     1  package dkg
     2  
     3  import (
     4  	"fmt"
     5  	"sync"
     6  )
     7  
     8  // State captures the state of an in-progress DKG.
     9  type State uint32
    10  
    11  const (
    12  	Init State = iota
    13  	Phase1
    14  	Phase2
    15  	Phase3
    16  	End
    17  	Shutdown
    18  )
    19  
    20  // String returns the string representation of a State
    21  func (s State) String() string {
    22  	switch s {
    23  	case Init:
    24  		return "Init"
    25  	case Phase1:
    26  		return "Phase1"
    27  	case Phase2:
    28  		return "Phase2"
    29  	case Phase3:
    30  		return "Phase3"
    31  	case End:
    32  		return "End"
    33  	case Shutdown:
    34  		return "Shutdown"
    35  	default:
    36  		return fmt.Sprintf("Unknown %d", s)
    37  	}
    38  }
    39  
    40  // Manager wraps a State with get and set methods
    41  type Manager struct {
    42  	sync.Mutex
    43  	state State
    44  }
    45  
    46  // GetState returns the current state.
    47  func (m *Manager) GetState() State {
    48  	m.Lock()
    49  	defer m.Unlock()
    50  	return m.state
    51  }
    52  
    53  // SetState sets the state.
    54  func (m *Manager) SetState(s State) {
    55  	m.Lock()
    56  	defer m.Unlock()
    57  	m.state = s
    58  }