-
Notifications
You must be signed in to change notification settings - Fork 0
/
consensus.go
38 lines (31 loc) · 950 Bytes
/
consensus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright Turing Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package consensus 系统基础共识包
package consensus
import (
"github.com/turingchain2020/turingchain/queue"
"github.com/turingchain2020/turingchain/types"
)
//Create 创建共识
type Create func(cfg *types.Consensus, sub []byte) queue.Module
var regConsensus = make(map[string]Create)
//QueryData 检索数据
var QueryData = types.NewQueryData("Query_")
//Reg ...
func Reg(name string, create Create) {
if create == nil {
panic("Consensus: Register driver is nil")
}
if _, dup := regConsensus[name]; dup {
panic("Consensus: Register called twice for driver " + name)
}
regConsensus[name] = create
}
//Load 加载
func Load(name string) (create Create, err error) {
if driver, ok := regConsensus[name]; ok {
return driver, nil
}
return nil, types.ErrNotFound
}