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

33 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.
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.
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.
func (s *Service) StopService() {
utils.GetLogInstance().Info("Stopping random generation service.")
s.stopChan <- struct{}{}
<-s.stoppedChan
utils.GetLogInstance().Info("Random generation stopped.")
}