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/randomness/service.go

34 lines
901 B

package randomness
import (
"github.com/harmony-one/harmony/drand"
"github.com/harmony-one/harmony/internal/utils"
)
// Service is the randomness generation service.
6 years ago
type Service struct {
stopChan chan struct{}
stoppedChan chan struct{}
DRand *drand.DRand
}
// New returns randomness generation service.
func New(dRand *drand.DRand) *Service {
return &Service{DRand: dRand}
}
// StartService starts randomness generation service.
6 years ago
func (s *Service) StartService() {
s.stopChan = make(chan struct{})
s.stoppedChan = make(chan struct{})
s.DRand.WaitForEpochBlock(s.DRand.ConfirmedBlockChannel, s.stopChan, s.stoppedChan)
}
// StopService stops randomness generation service.
6 years ago
func (s *Service) StopService() {
utils.GetLogInstance().Info("Stopping random generation service.")
6 years ago
s.stopChan <- struct{}{}
<-s.stoppedChan
6 years ago
utils.GetLogInstance().Info("Random generation stopped.")
}