|
|
@ -8,11 +8,13 @@ import ( |
|
|
|
type Service struct { |
|
|
|
type Service struct { |
|
|
|
stopChan chan struct{} |
|
|
|
stopChan chan struct{} |
|
|
|
stoppedChan chan struct{} |
|
|
|
stoppedChan chan struct{} |
|
|
|
|
|
|
|
readySignal chan struct{} |
|
|
|
|
|
|
|
waitForConsensusReady func(readySignal chan struct{}, stopChan chan struct{}, stoppedChan chan struct{}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// NewService returns new block service.
|
|
|
|
// NewService returns new block service.
|
|
|
|
func NewService() *Service { |
|
|
|
func NewService(readySignal chan struct{}, waitForConsensusReady func(readySignal chan struct{}, stopChan chan struct{}, stoppedChan chan struct{})) *Service { |
|
|
|
return &Service{} |
|
|
|
return &Service{readySignal: readySignal, waitForConsensusReady: waitForConsensusReady} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// StartService starts new block service.
|
|
|
|
// StartService starts new block service.
|
|
|
@ -30,23 +32,7 @@ func (s *Service) Init() { |
|
|
|
|
|
|
|
|
|
|
|
// Run runs new block.
|
|
|
|
// Run runs new block.
|
|
|
|
func (s *Service) Run(stopChan chan struct{}, stoppedChan chan struct{}) { |
|
|
|
func (s *Service) Run(stopChan chan struct{}, stoppedChan chan struct{}) { |
|
|
|
go func() { |
|
|
|
s.waitForConsensusReady(s.readySignal, s.stopChan, s.stoppedChan) |
|
|
|
defer close(stoppedChan) |
|
|
|
|
|
|
|
for { |
|
|
|
|
|
|
|
select { |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
utils.GetLogInstance().Info("Running new block") |
|
|
|
|
|
|
|
// TODO: Write some logic here.
|
|
|
|
|
|
|
|
s.DoService() |
|
|
|
|
|
|
|
case <-stopChan: |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// DoService does new block.
|
|
|
|
|
|
|
|
func (s *Service) DoService() { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// StopService stops new block service.
|
|
|
|
// StopService stops new block service.
|
|
|
|