github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/events/producer/register_internal_events.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  		 http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  //All changes for handling internal events should be in this file
    18  //Step 1 - add the event type name to the const
    19  //Step 2 - add a case statement to getMessageType
    20  //Step 3 - add an AddEventType call to addInternalEventTypes
    21  
    22  package producer
    23  
    24  import (
    25  	pb "github.com/hyperledger/fabric/protos/peer"
    26  )
    27  
    28  //----Event Types -----
    29  /*const (
    30  	RegisterType  = "register"
    31  	RejectionType = "rejection"
    32  	BlockType     = "block"
    33  )*/
    34  
    35  func getMessageType(e *pb.Event) pb.EventType {
    36  	switch e.Event.(type) {
    37  	case *pb.Event_Register:
    38  		return pb.EventType_REGISTER
    39  	case *pb.Event_Block:
    40  		return pb.EventType_BLOCK
    41  	case *pb.Event_ChaincodeEvent:
    42  		return pb.EventType_CHAINCODE
    43  	case *pb.Event_Rejection:
    44  		return pb.EventType_REJECTION
    45  	default:
    46  		return -1
    47  	}
    48  }
    49  
    50  //should be called at init time to register supported internal events
    51  func addInternalEventTypes() {
    52  	AddEventType(pb.EventType_BLOCK)
    53  	AddEventType(pb.EventType_CHAINCODE)
    54  	AddEventType(pb.EventType_REJECTION)
    55  	AddEventType(pb.EventType_REGISTER)
    56  }