github.com/turingchain2020/turingchain@v1.1.21/consensus/consensus.go (about) 1 // Copyright Turing Corp. 2018 All Rights Reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package consensus 共识相关的模块 6 package consensus 7 8 import ( 9 "reflect" 10 11 "github.com/turingchain2020/turingchain/queue" 12 "github.com/turingchain2020/turingchain/system/consensus" 13 "github.com/turingchain2020/turingchain/types" 14 ) 15 16 // New new consensus queue module 17 func New(cfg *types.TuringchainConfig) queue.Module { 18 mcfg := cfg.GetModuleConfig().Consensus 19 sub := cfg.GetSubConfig().Consensus 20 con, err := consensus.Load(mcfg.Name) 21 if err != nil { 22 panic("Unsupported consensus type:" + mcfg.Name + " " + err.Error()) 23 } 24 subcfg, ok := sub[mcfg.Name] 25 if !ok { 26 subcfg = nil 27 } 28 obj := con(mcfg, subcfg) 29 consensus.QueryData.SetThis(mcfg.Name, reflect.ValueOf(obj)) 30 return obj 31 }