The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/api/service/blockproposal/service.go

45 lines
1.3 KiB

package blockproposal
import (
"github.com/harmony-one/harmony/internal/utils"
)
6 years ago
// Service is a block proposal service.
type Service struct {
stopChan chan struct{}
stoppedChan chan struct{}
readySignal chan struct{}
waitForConsensusReady func(readySignal chan struct{}, stopChan chan struct{}, stoppedChan chan struct{})
}
6 years ago
// New returns a block proposal service.
func New(readySignal chan struct{}, waitForConsensusReady func(readySignal chan struct{}, stopChan chan struct{}, stoppedChan chan struct{})) *Service {
return &Service{readySignal: readySignal, waitForConsensusReady: waitForConsensusReady}
}
6 years ago
// StartService starts block proposal service.
func (s *Service) StartService() {
s.stopChan = make(chan struct{})
s.stoppedChan = make(chan struct{})
s.Init()
s.Run(s.stopChan, s.stoppedChan)
}
6 years ago
// Init initializes block proposal service.
func (s *Service) Init() {
}
6 years ago
// Run runs block proposal.
func (s *Service) Run(stopChan chan struct{}, stoppedChan chan struct{}) {
s.waitForConsensusReady(s.readySignal, s.stopChan, s.stoppedChan)
}
6 years ago
// StopService stops block proposal service.
func (s *Service) StopService() {
6 years ago
utils.GetLogInstance().Info("Stopping block proposal service.")
s.stopChan <- struct{}{}
<-s.stoppedChan
utils.GetLogInstance().Info("Role conversion stopped.")
}