fix comments, typos, add TODO.

pull/480/head
Minh Doan 6 years ago committed by Minh Doan
parent df1ce42ba1
commit 5ef17c9bae
  1. 24
      api/service/staking/service.go
  2. 2
      node/node.go

@ -18,14 +18,15 @@ import (
"github.com/harmony-one/harmony/p2p"
)
// State is the state of staking service.
type State byte
// Constants for State
const (
NOT_STAKED_YET State = iota
STAKED
REJECTED
APPROVED
TRANSFORMED
NotStatedYet State = iota
Staked
Rejected
Approved
)
// Service is the staking service.
@ -43,15 +44,16 @@ type Service struct {
}
// New returns staking service.
func New(accountKey *ecdsa.PrivateKey, stakingAmount int64, peerChan <-chan p2p.Peer, messageChan <-chan *message.Message) *Service {
func New(host p2p.Host, accountKey *ecdsa.PrivateKey, stakingAmount int64, peerChan <-chan p2p.Peer, messageChan <-chan *message.Message) *Service {
return &Service{
host: host,
stopChan: make(chan struct{}),
stoppedChan: make(chan struct{}),
peerChan: peerChan,
accountKey: accountKey,
stakingAmount: stakingAmount,
messageChan: messageChan,
state: NOT_STAKED_YET,
state: NotStatedYet,
}
}
@ -89,7 +91,7 @@ func (s *Service) DoService(peer p2p.Peer) {
utils.GetLogInstance().Info("Staking with Peer")
stakingMessage := s.createStakingMessage(peer)
s.state = STAKED
s.state = Staked
if data, err := pb.Marshal(stakingMessage); err == nil {
// Send a staking transaction to beacon chain.
if err = s.host.SendMessageToGroups([]p2p.GroupID{p2p.GroupIDBeacon}, data); err != nil {
@ -108,10 +110,10 @@ func (s *Service) DoService(peer p2p.Peer) {
case msg := <-s.messageChan:
if isStateResultMessage(msg) {
if s.stakeApproved(msg) {
s.state = APPROVED
s.state = Approved
// TODO(minhdoan): Should send a signal to another service.
} else {
s.state = REJECTED
s.state = Rejected
// TODO(minhdoan): what's next?
return
}
@ -123,10 +125,12 @@ func (s *Service) DoService(peer p2p.Peer) {
}
}
// TODO(minhdoan): Will implement this logic when introducing the result message from beacon chain.
func isStateResultMessage(msg *message.Message) bool {
return true
}
// TODO(minhdoan): Will implement this logic when introducing the result message from beacon chain.
func (s *Service) stakeApproved(msg *message.Message) bool {
return true
}

@ -683,7 +683,7 @@ func (node *Node) setupForNewNode() {
nodeConfig, chanPeer := node.initNodeConfiguration()
// Register staking service.
node.serviceManager.RegisterService(service_manager.Staking, staking.New(node.AccountKey, 0, stakingPeer, nil))
node.serviceManager.RegisterService(service_manager.Staking, staking.New(node.host, node.AccountKey, 0, stakingPeer, nil))
// Register peer discovery service. "0" is the beacon shard ID
node.serviceManager.RegisterService(service_manager.PeerDiscovery, discovery.New(node.host, nodeConfig, chanPeer))
// Register networkinfo service. "0" is the beacon shard ID

Loading…
Cancel
Save