github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/core/container/ccintf/ccintf.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  package ccintf
    18  
    19  //This package defines the interfaces that support runtime and
    20  //communication between chaincode and peer (chaincode support).
    21  //Currently inproccontroller uses it. dockercontroller does not.
    22  
    23  import (
    24  	"encoding/hex"
    25  
    26  	"github.com/hyperledger/fabric/common/util"
    27  	pb "github.com/hyperledger/fabric/protos/peer"
    28  	"golang.org/x/net/context"
    29  )
    30  
    31  // ChaincodeStream interface for stream between Peer and chaincode instance.
    32  type ChaincodeStream interface {
    33  	Send(*pb.ChaincodeMessage) error
    34  	Recv() (*pb.ChaincodeMessage, error)
    35  }
    36  
    37  // CCSupport must be implemented by the chaincode support side in peer
    38  // (such as chaincode_support)
    39  type CCSupport interface {
    40  	HandleChaincodeStream(context.Context, ChaincodeStream) error
    41  }
    42  
    43  // GetCCHandlerKey is used to pass CCSupport via context
    44  func GetCCHandlerKey() string {
    45  	return "CCHANDLER"
    46  }
    47  
    48  //CCID encapsulates chaincode ID
    49  type CCID struct {
    50  	ChaincodeSpec *pb.ChaincodeSpec
    51  	NetworkID     string
    52  	PeerID        string
    53  	ChainID       string
    54  	Version       string
    55  }
    56  
    57  //GetName returns canonical chaincode name based on chain name
    58  func (ccid *CCID) GetName() string {
    59  	if ccid.ChaincodeSpec == nil {
    60  		panic("nil chaincode spec")
    61  	}
    62  
    63  	name := ccid.ChaincodeSpec.ChaincodeId.Name
    64  	if ccid.Version != "" {
    65  		name = name + "-" + ccid.Version
    66  	}
    67  
    68  	//this better be chainless system chaincode!
    69  	if ccid.ChainID != "" {
    70  		hash := util.ComputeSHA256([]byte(ccid.ChainID))
    71  		hexstr := hex.EncodeToString(hash[:])
    72  		name = name + "-" + hexstr
    73  	}
    74  
    75  	return name
    76  }