github.com/hellobchain/third_party@v0.0.0-20230331131523-deb0478a2e52/hyperledger/fabric/core/common/ccprovider/ccprovider.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  /*
     7  Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
     8  Please review third_party pinning scripts and patches for more details.
     9  */
    10  
    11  package ccprovider
    12  
    13  import (
    14  	"github.com/golang/protobuf/proto"
    15  	pb "github.com/hyperledger/fabric-protos-go/peer"
    16  )
    17  
    18  // CCPackage encapsulates a chaincode package which can be
    19  //    raw ChaincodeDeploymentSpec
    20  //    SignedChaincodeDeploymentSpec
    21  // Attempt to keep the interface at a level with minimal
    22  // interface for possible generalization.
    23  type CCPackage interface {
    24  	//InitFromBuffer initialize the package from bytes
    25  	InitFromBuffer(buf []byte) (*ChaincodeData, error)
    26  
    27  	// PutChaincodeToFS writes the chaincode to the filesystem
    28  	PutChaincodeToFS() error
    29  
    30  	// GetDepSpec gets the ChaincodeDeploymentSpec from the package
    31  	GetDepSpec() *pb.ChaincodeDeploymentSpec
    32  
    33  	// GetDepSpecBytes gets the serialized ChaincodeDeploymentSpec from the package
    34  	GetDepSpecBytes() []byte
    35  
    36  	// ValidateCC validates and returns the chaincode deployment spec corresponding to
    37  	// ChaincodeData. The validation is based on the metadata from ChaincodeData
    38  	// One use of this method is to validate the chaincode before launching
    39  	ValidateCC(ccdata *ChaincodeData) error
    40  
    41  	// GetPackageObject gets the object as a proto.Message
    42  	GetPackageObject() proto.Message
    43  
    44  	// GetChaincodeData gets the ChaincodeData
    45  	GetChaincodeData() *ChaincodeData
    46  
    47  	// GetId gets the fingerprint of the chaincode based on package computation
    48  	GetId() []byte
    49  }
    50  
    51  //-------- ChaincodeData is stored on the LSCC -------
    52  
    53  // ChaincodeData defines the datastructure for chaincodes to be serialized by proto
    54  // Type provides an additional check by directing to use a specific package after instantiation
    55  // Data is Type specific (see CDSPackage and SignedCDSPackage)
    56  type ChaincodeData struct {
    57  	// Name of the chaincode
    58  	Name string `protobuf:"bytes,1,opt,name=name"`
    59  
    60  	// Version of the chaincode
    61  	Version string `protobuf:"bytes,2,opt,name=version"`
    62  
    63  	// Escc for the chaincode instance
    64  	Escc string `protobuf:"bytes,3,opt,name=escc"`
    65  
    66  	// Vscc for the chaincode instance
    67  	Vscc string `protobuf:"bytes,4,opt,name=vscc"`
    68  
    69  	// Policy endorsement policy for the chaincode instance
    70  	Policy []byte `protobuf:"bytes,5,opt,name=policy,proto3"`
    71  
    72  	// Data data specific to the package
    73  	Data []byte `protobuf:"bytes,6,opt,name=data,proto3"`
    74  
    75  	// Id of the chaincode that's the unique fingerprint for the CC This is not
    76  	// currently used anywhere but serves as a good eyecatcher
    77  	Id []byte `protobuf:"bytes,7,opt,name=id,proto3"`
    78  
    79  	// InstantiationPolicy for the chaincode
    80  	InstantiationPolicy []byte `protobuf:"bytes,8,opt,name=instantiation_policy,proto3"`
    81  }
    82  
    83  // implement functions needed from proto.Message for proto's mar/unmarshal functions
    84  
    85  // Reset resets
    86  func (cd *ChaincodeData) Reset() { *cd = ChaincodeData{} }
    87  
    88  // String converts to string
    89  func (cd *ChaincodeData) String() string { return proto.CompactTextString(cd) }
    90  
    91  // ProtoMessage just exists to make proto happy
    92  func (*ChaincodeData) ProtoMessage() {}