Files
prysm/beacon-chain/blockchain/service.go
Raul Jordan 4d5d229f0f beacon: Define a Core Blockchain Package and Persisted Structure for Beacon (#278)
Former-commit-id: bbd5b46e7f64f762350d6fb496492207e70d7130 [formerly 43a37f7139b7d1d90f0c27a7406b63bdf390ad96]
Former-commit-id: bb7a2ff0a7619f8de0bd38cd2c9eb0de7c189edb
2018-07-19 11:31:50 -05:00

40 lines
1.1 KiB
Go

package blockchain
import (
"context"
"github.com/prysmaticlabs/geth-sharding/beacon-chain/database"
log "github.com/sirupsen/logrus"
)
// ChainService represents a service that handles the internal
// logic of managing the full PoS beacon chain.
type ChainService struct {
ctx context.Context
cancel context.CancelFunc
beaconDB *database.BeaconDB
chain *BeaconChain
}
// NewChainService instantiates a new service instance that will
// be registered into a running beacon node.
func NewChainService(ctx context.Context, beaconDB *database.BeaconDB) (*ChainService, error) {
ctx, cancel := context.WithCancel(ctx)
return &ChainService{ctx, cancel, beaconDB, nil}, nil
}
// Start a blockchain service's main event loop.
func (c *ChainService) Start() {
log.Infof("Starting blockchain service")
if _, err := NewBeaconChain(c.beaconDB.DB()); err != nil {
log.Errorf("Unable to setup blockchain: %v", err)
}
}
// Stop the blockchain service's main event loop and associated goroutines.
func (c *ChainService) Stop() error {
defer c.cancel()
log.Info("Stopping blockchain service")
return nil
}