本文整理汇总了Golang中github.com/hyperledger/fabric/protos.Interest类的典型用法代码示例。如果您正苦于以下问题:Golang Interest类的具体用法?Golang Interest怎么用?Golang Interest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Interest类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getInterestKey
func getInterestKey(interest pb.Interest) string {
var key string
switch interest.EventType {
case pb.EventType_BLOCK:
key = "/" + strconv.Itoa(int(pb.EventType_BLOCK))
case pb.EventType_REJECTION:
key = "/" + strconv.Itoa(int(pb.EventType_REJECTION))
case pb.EventType_CHAINCODE:
key = "/" + strconv.Itoa(int(pb.EventType_CHAINCODE)) + "/" + interest.GetChaincodeRegInfo().ChaincodeID + "/" + interest.GetChaincodeRegInfo().EventName
default:
producerLogger.Errorf("unknown interest type %s", interest.EventType)
}
return key
}
示例2: del
func (hl *chaincodeHandlerList) del(ie *pb.Interest, h *handler) (bool, error) {
hl.Lock()
defer hl.Unlock()
//chaincode registration info must be non-nil
if ie.GetChaincodeRegInfo() == nil {
return false, fmt.Errorf("chaincode information not provided for de-registering")
}
//chaincode registration info must be for a non-empty chaincode ID (even if the chaincode does not exist)
if ie.GetChaincodeRegInfo().ChaincodeID == "" {
return false, fmt.Errorf("chaincode ID not provided for de-registering")
}
//if there's no event type map, nothing to do
emap, ok := hl.handlers[ie.GetChaincodeRegInfo().ChaincodeID]
if !ok {
return false, fmt.Errorf("chaincode ID not registered")
}
//if there are no handlers for the event type, nothing to do
var handlerMap map[*handler]bool
if handlerMap, _ = emap[ie.GetChaincodeRegInfo().EventName]; handlerMap == nil {
return false, fmt.Errorf("event name %s not registered for chaincode ID %s", ie.GetChaincodeRegInfo().EventName, ie.GetChaincodeRegInfo().ChaincodeID)
} else if _, ok = handlerMap[h]; !ok {
//the handler is not registered for the event type
return false, fmt.Errorf("handler not registered for event name %s for chaincode ID %s", ie.GetChaincodeRegInfo().EventName, ie.GetChaincodeRegInfo().ChaincodeID)
}
//remove the handler from the map
delete(handlerMap, h)
//if the last handler has been removed from handler map for a chaincode's event,
//remove the event map.
//if the last map of events have been removed for the chaincode UUID
//remove the chaincode UUID map
if len(handlerMap) == 0 {
delete(emap, ie.GetChaincodeRegInfo().EventName)
if len(emap) == 0 {
delete(hl.handlers, ie.GetChaincodeRegInfo().ChaincodeID)
}
}
return true, nil
}
示例3: add
func (hl *chaincodeHandlerList) add(ie *pb.Interest, h *handler) (bool, error) {
hl.Lock()
defer hl.Unlock()
//chaincode registration info must be non-nil
if ie.GetChaincodeRegInfo() == nil {
return false, fmt.Errorf("chaincode information not provided for registering")
}
//chaincode registration info must be for a non-empty chaincode ID (even if the chaincode does not exist)
if ie.GetChaincodeRegInfo().ChaincodeID == "" {
return false, fmt.Errorf("chaincode ID not provided for registering")
}
//is there a event type map for the chaincode
emap, ok := hl.handlers[ie.GetChaincodeRegInfo().ChaincodeID]
if !ok {
emap = make(map[string]map[*handler]bool)
hl.handlers[ie.GetChaincodeRegInfo().ChaincodeID] = emap
}
//create handler map if this is the first handler for the type
var handlerMap map[*handler]bool
if handlerMap, _ = emap[ie.GetChaincodeRegInfo().EventName]; handlerMap == nil {
handlerMap = make(map[*handler]bool)
emap[ie.GetChaincodeRegInfo().EventName] = handlerMap
} else if _, ok = handlerMap[h]; ok {
return false, fmt.Errorf("handler exists for event type")
}
//the handler is added to the map
handlerMap[h] = true
return true, nil
}