libs/common: refactor libs common 3 (#4232)

* libs/common: refactor libs common 3

- move nil.go into types folder and make private
- move service & baseservice out of common into service pkg

ref #4147

Signed-off-by: Marko Baricevic <marbar3778@yahoo.com>

* add changelog entry
This commit is contained in:
Marko
2019-12-11 09:31:25 +01:00
committed by GitHub
parent efc27ab0b9
commit 27b00cf8d1
50 changed files with 163 additions and 150 deletions

View File

@@ -3,7 +3,7 @@ package txindex
import (
"context"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/service"
"github.com/tendermint/tendermint/types"
)
@@ -15,7 +15,7 @@ const (
// IndexerService connects event bus and transaction indexer together in order
// to index transactions coming from event bus.
type IndexerService struct {
cmn.BaseService
service.BaseService
idr TxIndexer
eventBus *types.EventBus
@@ -24,11 +24,11 @@ type IndexerService struct {
// NewIndexerService returns a new service instance.
func NewIndexerService(idr TxIndexer, eventBus *types.EventBus) *IndexerService {
is := &IndexerService{idr: idr, eventBus: eventBus}
is.BaseService = *cmn.NewBaseService(nil, "IndexerService", is)
is.BaseService = *service.NewBaseService(nil, "IndexerService", is)
return is
}
// OnStart implements cmn.Service by subscribing for all transactions
// OnStart implements service.Service by subscribing for all transactions
// and indexing them by events.
func (is *IndexerService) OnStart() error {
// Use SubscribeUnbuffered here to ensure both subscriptions does not get
@@ -74,7 +74,7 @@ func (is *IndexerService) OnStart() error {
return nil
}
// OnStop implements cmn.Service by unsubscribing from all transactions.
// OnStop implements service.Service by unsubscribing from all transactions.
func (is *IndexerService) OnStop() {
if is.eventBus.IsRunning() {
_ = is.eventBus.UnsubscribeAll(context.Background(), subscriber)