"github.com/vapor/config"
engine "github.com/vapor/consensus/consensus"
+ dpos "github.com/vapor/consensus/consensus/dpos"
"github.com/vapor/errors"
"github.com/vapor/protocol/bc"
"github.com/vapor/protocol/bc/types"
store Store
processBlockCh chan *processBlockMsg
- cond sync.Cond
- bestNode *state.BlockNode
- Authoritys map[string]string
- position uint64
- engine engine.Engine
+ cond sync.Cond
+ bestNode *state.BlockNode
+ Engine engine.Engine
}
// NewChain returns a new Chain using store as the underlying storage.
func NewChain(store Store, txPool *TxPool) (*Chain, error) {
+
+ var engine engine.Engine
+ switch config.CommonConfig.Consensus.Type {
+ case "dpos":
+ engine = dpos.GDpos
+ }
+
c := &Chain{
orphanManage: NewOrphanManage(),
txPool: txPool,
store: store,
processBlockCh: make(chan *processBlockMsg, maxProcessBlockChSize),
+ Engine: engine,
}
c.cond.L = new(sync.Mutex)
return c, nil
}
-func (c *Chain) SetAuthoritys(authoritys map[string]string) {
- c.Authoritys = authoritys
-}
-
-func (c *Chain) SetPosition(position uint64) {
- c.position = position
-}
-
-func (c *Chain) SetConsensusEngine(engine engine.Engine) {
- c.engine = engine
-}
-
func (c *Chain) initChainStatus() error {
genesisBlock := config.GenesisBlock()
txStatus := bc.NewTransactionStatus()