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

64 lines
1.3 KiB

6 years ago
package staking
import (
6 years ago
"github.com/harmony-one/harmony/internal/utils"
6 years ago
"github.com/harmony-one/harmony/p2p"
)
// Service is the role conversion service.
6 years ago
type Service struct {
stopChan chan struct{}
stoppedChan chan struct{}
peerChan chan *p2p.Peer
6 years ago
}
// NewService returns role conversion service.
func NewService(peerChan chan *p2p.Peer) *Service {
return &Service{
stopChan: make(chan struct{}),
stoppedChan: make(chan struct{}),
peerChan: peerChan,
}
}
// StartService starts role conversion service.
6 years ago
func (s *Service) StartService() {
s.Init()
s.Run()
}
// Init initializes role conversion service.
func (s *Service) Init() {
}
// Run runs role conversion.
func (s *Service) Run() {
// Wait until peer info of beacon chain is ready.
peer := <-s.peerChan
go func() {
defer close(s.stoppedChan)
for {
select {
default:
utils.GetLogInstance().Info("Running role conversion")
// TODO: Write some logic here.
s.DoService(peer)
case <-s.stopChan:
return
}
}
}()
6 years ago
}
// DoService does role conversion.
func (s *Service) DoService(peer *p2p.Peer) {
6 years ago
}
// StopService stops role conversion service.
6 years ago
func (s *Service) StopService() {
utils.GetLogInstance().Info("Stopping role conversion service.")
s.stopChan <- struct{}{}
<-s.stoppedChan
utils.GetLogInstance().Info("Role conversion stopped.")
6 years ago
}