github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/core/ledger/cceventmgmt/defs.go (about)

     1  /*
     2  Copyright hechain. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package cceventmgmt
     8  
     9  import (
    10  	"fmt"
    11  
    12  	"github.com/hechain20/hechain/core/ledger"
    13  	"github.com/hyperledger/fabric-protos-go/peer"
    14  )
    15  
    16  // ChaincodeDefinition captures the info about chaincode
    17  type ChaincodeDefinition struct {
    18  	Name              string
    19  	Hash              []byte
    20  	Version           string
    21  	CollectionConfigs *peer.CollectionConfigPackage
    22  }
    23  
    24  func (cdef *ChaincodeDefinition) String() string {
    25  	if cdef != nil {
    26  		return fmt.Sprintf("Name=%s, Version=%s, Hash=%x", cdef.Name, cdef.Version, cdef.Hash)
    27  	}
    28  	return "<nil>"
    29  }
    30  
    31  // ChaincodeLifecycleEventListener interface enables ledger components (mainly, intended for statedb)
    32  // to be able to listen to chaincode lifecycle events. 'dbArtifactsTar' represents db specific artifacts
    33  // (such as index specs) packaged in a tar
    34  type ChaincodeLifecycleEventListener interface {
    35  	// HandleChaincodeDeploy is invoked when chaincode installed + defined becomes true.
    36  	// The expected usage are to creates all the necessary statedb structures (such as indexes) and update
    37  	// service discovery info. This function is invoked immediately before the committing the state changes
    38  	// that contain chaincode definition or when a chaincode install happens
    39  	HandleChaincodeDeploy(chaincodeDefinition *ChaincodeDefinition, dbArtifactsTar []byte) error
    40  	// ChaincodeDeployDone is invoked after the chaincode deployment is finished - `succeeded` indicates
    41  	// whether the deploy finished successfully
    42  	ChaincodeDeployDone(succeeded bool)
    43  }
    44  
    45  // ChaincodeInfoProvider interface enables event mgr to retrieve chaincode info for a given chaincode
    46  type ChaincodeInfoProvider interface {
    47  	// GetDeployedChaincodeInfo retrieves the details about the deployed chaincode.
    48  	// This function is expected to return nil, if the chaincode with the given name is not deployed
    49  	// or the version or hash of the deployed chaincode does not match with the given version and hash
    50  	GetDeployedChaincodeInfo(chainid string, chaincodeDefinition *ChaincodeDefinition) (*ledger.DeployedChaincodeInfo, error)
    51  	// RetrieveChaincodeArtifacts checks if the given chaincode is installed on the peer and if yes,
    52  	// it extracts the state db specific artifacts from the chaincode package tarball
    53  	RetrieveChaincodeArtifacts(chaincodeDefinition *ChaincodeDefinition) (installed bool, dbArtifactsTar []byte, err error)
    54  }