github.com/turingchain2020/turingchain@v1.1.21/system/mempool/mempool.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 mempool
     6  
     7  import (
     8  	"github.com/turingchain2020/turingchain/queue"
     9  	"github.com/turingchain2020/turingchain/types"
    10  )
    11  
    12  //Create 创建一个mempool模块
    13  type Create func(cfg *types.Mempool, sub []byte) queue.Module
    14  
    15  var regMempool = make(map[string]Create)
    16  
    17  //Reg 注册一个create
    18  func Reg(name string, create Create) {
    19  	if create == nil {
    20  		panic("Mempool: Register driver is nil")
    21  	}
    22  	if _, dup := regMempool[name]; dup {
    23  		panic("Mempool: Register called twice for driver " + name)
    24  	}
    25  	regMempool[name] = create
    26  }
    27  
    28  //Load 加载一个create
    29  func Load(name string) (create Create, err error) {
    30  	if driver, ok := regMempool[name]; ok {
    31  		return driver, nil
    32  	}
    33  	return nil, types.ErrNotFound
    34  }