{"modulePath":"https-1xa.pages.dev/hyperledger/fabric","version":"v2.1.1+incompatible","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package lifecycle\n\n## Constants\n\n```go\nconst (\n\t// NamespacesName is the prefix (or namespace) of the DB which will be used to store\n\t// the information about other namespaces (for things like chaincodes) in the DB.\n\t// We want a sub-namespaces within lifecycle in case other information needs to be stored here\n\t// in the future.\n\tNamespacesName = \"namespaces\"\n\n\t// ChaincodeSourcesName is the namespace reserved for storing the information about where\n\t// to find the chaincode (such as as a package on the local filesystem, or in the future,\n\t// at some network resource). This namespace is only populated in the org implicit collection.\n\tChaincodeSourcesName = \"chaincode-sources\"\n\n\t// ChaincodeDefinitionType is the name of the type used to store defined chaincodes\n\tChaincodeDefinitionType = \"ChaincodeDefinition\"\n\n\t// FriendlyChaincodeDefinitionType is the name exposed to the outside world for the chaincode namespace\n\tFriendlyChaincodeDefinitionType = \"Chaincode\"\n\n\t// DefaultEndorsementPolicyRef is the name of the default endorsement policy for this channel\n\tDefaultEndorsementPolicyRef = \"/Channel/Application/Endorsement\"\n)\n```\n\n```go\nconst (\n\t// LifecycleNamespace is the namespace in the statedb where lifecycle\n\t// information is stored\n\tLifecycleNamespace = \"_lifecycle\"\n\n\t// InstallChaincodeFuncName is the chaincode function name used to install\n\t// a chaincode\n\tInstallChaincodeFuncName = \"InstallChaincode\"\n\n\t// QueryInstalledChaincodeFuncName is the chaincode function name used to\n\t// query an installed chaincode\n\tQueryInstalledChaincodeFuncName = \"QueryInstalledChaincode\"\n\n\t// QueryInstalledChaincodesFuncName is the chaincode function name used to\n\t// query all installed chaincodes\n\tQueryInstalledChaincodesFuncName = \"QueryInstalledChaincodes\"\n\n\t// ApproveChaincodeDefinitionForMyOrgFuncName is the chaincode function name\n\t// used to approve a chaincode definition for execution by the user's own org\n\tApproveChaincodeDefinitionForMyOrgFuncName = \"ApproveChaincodeDefinitionForMyOrg\"\n\n\t// CheckCommitReadinessFuncName is the chaincode function name used to check\n\t// a specified chaincode definition is ready to be committed. It returns the\n\t// approval status for a given definition over a given set of orgs\n\tCheckCommitReadinessFuncName = \"CheckCommitReadiness\"\n\n\t// CommitChaincodeDefinitionFuncName is the chaincode function name used to\n\t// 'commit' (previously 'instantiate') a chaincode in a channel.\n\tCommitChaincodeDefinitionFuncName = \"CommitChaincodeDefinition\"\n\n\t// QueryChaincodeDefinitionFuncName is the chaincode function name used to\n\t// query a committed chaincode definition in a channel.\n\tQueryChaincodeDefinitionFuncName = \"QueryChaincodeDefinition\"\n\n\t// QueryChaincodeDefinitionsFuncName is the chaincode function name used to\n\t// query the committed chaincode definitions in a channel.\n\tQueryChaincodeDefinitionsFuncName = \"QueryChaincodeDefinitions\"\n)\n```\n\n```go\nconst (\n\tMetadataInfix = \"metadata\"\n\tFieldsInfix   = \"fields\"\n)\n```\n\n```go\nconst (\n\tLifecycleEndorsementPolicyRef = \"/Channel/Application/LifecycleEndorsement\"\n)\n```\n\n## Variables\n\n```go\nvar (\n\t// NOTE the chaincode name/version regular expressions should stay in sync\n\t// with those defined in core/scc/lscc/lscc.go until LSCC has been removed.\n\tChaincodeNameRegExp    = regexp.MustCompile(\"^[a-zA-Z0-9]+([-_][a-zA-Z0-9]+)*$\")\n\tChaincodeVersionRegExp = regexp.MustCompile(\"^[A-Za-z0-9_.+-]+$\")\n)\n```\n\n```go\nvar (\n\tDefaultEndorsementPolicyBytes = protoutil.MarshalOrPanic(\u0026pb.ApplicationPolicy{\n\t\tType: \u0026pb.ApplicationPolicy_ChannelConfigPolicyReference{\n\t\t\tChannelConfigPolicyReference: DefaultEndorsementPolicyRef,\n\t\t},\n\t})\n)\n```\n\n```go\nvar ImplicitCollectionMatcher = regexp.MustCompile(\"^\" + ImplicitCollectionNameForOrg(\"(.+)\") + \"$\")\n```\n\n```go\nvar (\n\t// This is a channel which was created with a lifecycle endorsement policy\n\tLifecycleDefaultEndorsementPolicyBytes = protoutil.MarshalOrPanic(\u0026cb.ApplicationPolicy{\n\t\tType: \u0026cb.ApplicationPolicy_ChannelConfigPolicyReference{\n\t\t\tChannelConfigPolicyReference: LifecycleEndorsementPolicyRef,\n\t\t},\n\t})\n)\n```\n\n```go\nvar ProtoMessageType = reflect.TypeOf((*proto.Message)(nil)).Elem()\n```\n\n```go\nvar SequenceMatcher = regexp.MustCompile(\"^\" + NamespacesName + \"/fields/([^/]+)/Sequence$\")\n```\n\n## Functions\n\n```go\nfunc FieldKey(namespace, name, field string) string\n```\n\n```go\nfunc ImplicitCollectionNameForOrg(mspid string) string\n```\n\n```go\nfunc MetadataKey(namespace, name string) string\n```\n\n```go\nfunc OrgFromImplicitCollectionName(name string) string\n```\n\n```go\nfunc StateIteratorToMap(itr StateIterator) (map[string][]byte, error)\n```\nStateIteratorToMap takes an iterator, and iterates over the entire thing, encoding the KVs into a map, and then closes it.\n\n## Types\n\n```go\ntype Cache struct {\n\tResources  *Resources\n\tMyOrgMSPID string\n\n\tMetadataHandler MetadataHandler\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewCache(resources *Resources, myOrgMSPID string, metadataManager MetadataHandler, custodian *ChaincodeCustodian, ebMetadata *externalbuilder.MetadataProvider) *Cache\n```\n\n```go\nfunc (c *Cache) ChaincodeInfo(channelID, name string) (*LocalChaincodeInfo, error)\n```\nChaincodeInfo returns the chaincode definition and its install info. An error is returned only if either the channel or the chaincode do not exist.\n\n```go\nfunc (c *Cache) GetInstalledChaincode(packageID string) (*chaincode.InstalledChaincode, error)\n```\nGetInstalledChaincode returns all of the information about a specific installed chaincode.\n\n```go\nfunc (c *Cache) HandleChaincodeInstalled(md *persistence.ChaincodePackageMetadata, packageID string)\n```\nHandleChaincodeInstalled should be invoked whenever a new chaincode is installed\n\n```go\nfunc (c *Cache) HandleStateUpdates(trigger *ledger.StateUpdateTrigger) error\n```\nHandleStateUpdates is required to implement the ledger state listener interface.  It applies any state updates to the cache.\n\n```go\nfunc (c *Cache) Initialize(channelID string, qe ledger.SimpleQueryExecutor) error\n```\nInitialize will populate the set of currently committed chaincode definitions for a channel into the cache.  Note, it this looks like a bit of a DRY violation with respect to 'Update', but, the error handling is quite different and attempting to factor out the common pieces results in a net total of more code.\n\n```go\nfunc (c *Cache) InitializeLocalChaincodes() error\n```\nInitializeLocalChaincodes should be called once after cache creation (timing doesn't matter, though already installed chaincodes will not be invokable until it it completes).  Ideally, this would be part of the constructor, but, we cannot rely on the chaincode store being created before the cache is created.\n\n```go\nfunc (c *Cache) InitializeMetadata(channel string)\n```\n\n```go\nfunc (c *Cache) InterestedInNamespaces() []string\n```\nInterestedInNamespaces is required to implement the ledger state listener interface\n\n```go\nfunc (c *Cache) ListInstalledChaincodes() []*chaincode.InstalledChaincode\n```\nListInstalledChaincodes returns a slice containing all of the information about the installed chaincodes.\n\n```go\nfunc (c *Cache) RegisterListener(channelID string, listener ledger.ChaincodeLifecycleEventListener)\n```\nRegisterListener registers an event listener for receiving an event when a chaincode becomes invokable\n\n```go\nfunc (c *Cache) StateCommitDone(channelName string)\n```\nStateCommitDone is required to implement the ledger state listener interface\n\n```go\ntype CachedChaincodeDefinition struct {\n\tDefinition  *ChaincodeDefinition\n\tApproved    bool\n\tInstallInfo *ChaincodeInstallInfo\n\n\t// Hashes is the list of hashed keys in the implicit collection referring to this definition.\n\t// These hashes are determined by the current sequence number of chaincode definition.  When dirty,\n\t// these hashes will be empty, and when not, they will be populated.\n\tHashes []string\n}\n```\n\n```go\ntype ChaincodeBuilder interface {\n\tBuild(ccid string) error\n}\n```\n\n```go\ntype ChaincodeCustodian struct {\n\t// contains filtered or unexported fields\n}\n```\nChaincodeCustodian is responsible for enqueuing builds and launches of chaincodes as they become available and stops when chaincodes are no longer referenced by an active chaincode definition.\n\n```go\nfunc NewChaincodeCustodian() *ChaincodeCustodian\n```\nNewChaincodeCustodian creates an instance of a chaincode custodian.  It is the instantiator's responsibility to spawn a go routine to service the Work routine along with the appropriate dependencies.\n\n```go\nfunc (cc *ChaincodeCustodian) Close()\n```\n\n```go\nfunc (cc *ChaincodeCustodian) NotifyInstalled(chaincodeID string)\n```\n\n```go\nfunc (cc *ChaincodeCustodian) NotifyInstalledAndRunnable(chaincodeID string)\n```\n\n```go\nfunc (cc *ChaincodeCustodian) NotifyStoppable(chaincodeID string)\n```\n\n```go\nfunc (cc *ChaincodeCustodian) Work(buildRegistry *container.BuildRegistry, builder ChaincodeBuilder, launcher ChaincodeLauncher)\n```\n\n```go\ntype ChaincodeDefinition struct {\n\tSequence        int64\n\tEndorsementInfo *lb.ChaincodeEndorsementInfo\n\tValidationInfo  *lb.ChaincodeValidationInfo\n\tCollections     *pb.CollectionConfigPackage\n}\n```\nChaincodeDefinition contains the chaincode parameters, as well as the sequence number of the definition. Note, it does not embed ChaincodeParameters so as not to complicate the serialization.  It is expected that any instance will have no nil fields once initialized. WARNING: This structure is serialized/deserialized from the DB, re-ordering or adding fields will cause opaque checks to fail.\n\n```go\nfunc (cd *ChaincodeDefinition) Parameters() *ChaincodeParameters\n```\nParameters returns the non-sequence info of the chaincode definition\n\n```go\nfunc (cd *ChaincodeDefinition) String() string\n```\n\n```go\ntype ChaincodeEndorsementInfo struct {\n\t// Version is the version from the definition in this particular channel and namespace context.\n\tVersion string\n\n\t// EnforceInit is set to true for definitions which require the chaincode package to enforce\n\t// 'init exactly once' semantics.\n\tEnforceInit bool\n\n\t// ChaincodeID is the name by which to look up or launch the underlying chaincode.\n\tChaincodeID string\n\n\t// EndorsementPlugin is the name of the plugin to use when endorsing.\n\tEndorsementPlugin string\n}\n```\nChaincodeEndorsementInfo contains the information necessary to handle a chaincode invoke request.\n\n```go\ntype ChaincodeEndorsementInfoSource struct {\n\tResources   *Resources\n\tCache       ChaincodeInfoCache\n\tLegacyImpl  Lifecycle\n\tBuiltinSCCs scc.BuiltinSCCs\n}\n```\n\n```go\nfunc (cei *ChaincodeEndorsementInfoSource) CachedChaincodeInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (*LocalChaincodeInfo, bool, error)\n```\n\n```go\nfunc (cei *ChaincodeEndorsementInfoSource) ChaincodeEndorsementInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (*ChaincodeEndorsementInfo, error)\n```\nChaincodeEndorsementInfo returns the information necessary to handle a chaincode invocation request, as well as a function to enforce security checks on the chaincode (in case the definition is from the legacy lscc).\n\n```go\ntype ChaincodeInfoCache interface {\n\tChaincodeInfo(channelID, chaincodeName string) (definition *LocalChaincodeInfo, err error)\n}\n```\n\n```go\ntype ChaincodeInfoProvider interface {\n\t// ChaincodeInfo returns the chaincode definition and its install info.\n\t// An error is returned only if either the channel or the chaincode do not exist.\n\tChaincodeInfo(channelID, name string) (*LocalChaincodeInfo, error)\n}\n```\nChaincodeInfoProvider provides metadata for a \\_lifecycle-defined chaincode on a specific channel\n\n```go\ntype ChaincodeInstallInfo struct {\n\tPackageID string\n\tType      string\n\tPath      string\n\tLabel     string\n}\n```\n\n```go\ntype ChaincodeLauncher interface {\n\tLaunch(ccid string) error\n\tStop(ccid string) error\n}\n```\n\n```go\ntype ChaincodeLocalPackage struct {\n\tPackageID string\n}\n```\nChaincodeLocalPackage is a type of chaincode-sources which may be serialized into the org's private data collection. WARNING: This structure is serialized/deserialized from the DB, re-ordering or adding fields will cause opaque checks to fail.\n\n```go\ntype ChaincodeParameters struct {\n\tEndorsementInfo *lb.ChaincodeEndorsementInfo\n\tValidationInfo  *lb.ChaincodeValidationInfo\n\tCollections     *pb.CollectionConfigPackage\n}\n```\nChaincodeParameters are the parts of the chaincode definition which are serialized as values in the statedb.  It is expected that any instance will have no nil fields once initialized. WARNING: This structure is serialized/deserialized from the DB, re-ordering or adding fields will cause opaque checks to fail.\n\n```go\nfunc (cp *ChaincodeParameters) Equal(ocp *ChaincodeParameters) error\n```\n\n```go\ntype ChaincodePrivateLedgerShim struct {\n\tStub       shim.ChaincodeStubInterface\n\tCollection string\n}\n```\nChaincodePrivateLedgerShim wraps the chaincode shim to make access to keys in a collection have the same semantics as normal public keys.\n\n```go\nfunc (cls *ChaincodePrivateLedgerShim) CollectionName() string\n```\n\n```go\nfunc (cls *ChaincodePrivateLedgerShim) DelState(key string) error\n```\nDelState deletes the key in the configured collection.\n\n```go\nfunc (cls *ChaincodePrivateLedgerShim) GetState(key string) ([]byte, error)\n```\nGetState returns the value for the key in the configured collection.\n\n```go\nfunc (cls *ChaincodePrivateLedgerShim) GetStateHash(key string) ([]byte, error)\n```\nGetStateHash return the hash of the pre-image for the key in the configured collection.\n\n```go\nfunc (cls *ChaincodePrivateLedgerShim) GetStateRange(prefix string) (map[string][]byte, error)\n```\nGetStateRange performs a range query in the configured collection for all keys beginning with a particular prefix.  This function assumes that keys contain only ascii chars from \\\\x00 to \\\\x7e.\n\n```go\nfunc (cls *ChaincodePrivateLedgerShim) PutState(key string, value []byte) error\n```\nPutState sets the value for the key in the configured collection.\n\n```go\ntype ChaincodePublicLedgerShim struct {\n\tshim.ChaincodeStubInterface\n}\n```\nChaincodePublicLedgerShim decorates the chaincode shim to support the state interfaces required by the serialization code.\n\n```go\nfunc (cls *ChaincodePublicLedgerShim) GetStateRange(prefix string) (map[string][]byte, error)\n```\nGetStateRange performs a range query for keys beginning with a particular prefix, and returns it as a map. This function assumes that keys contain only ascii chars from \\\\x00 to \\\\x7e.\n\n```go\ntype ChaincodeResultIteratorShim struct {\n\tResultsIterator shim.StateQueryIteratorInterface\n}\n```\n\n```go\nfunc (cris *ChaincodeResultIteratorShim) Close() error\n```\n\n```go\nfunc (cris *ChaincodeResultIteratorShim) Next() (*queryresult.KV, error)\n```\n\n```go\ntype ChaincodeStore interface {\n\tSave(label string, ccInstallPkg []byte) (string, error)\n\tListInstalledChaincodes() ([]chaincode.InstalledChaincode, error)\n\tLoad(packageID string) (ccInstallPkg []byte, err error)\n\tDelete(packageID string) error\n}\n```\nChaincodeStore provides a way to persist chaincodes\n\n```go\ntype ChannelCache struct {\n\tChaincodes map[string]*CachedChaincodeDefinition\n\n\t// InterestingHashes is a map of hashed key names to the chaincode name which they affect.\n\t// These are to be used for the state listener, to mark chaincode definitions dirty when\n\t// a write is made into the implicit collection for this org.  Interesting hashes are\n\t// added when marking a definition clean, and deleted when marking it dirty.\n\tInterestingHashes map[string]string\n}\n```\n\n```go\ntype ChannelConfigSource interface {\n\t// GetStableChannelConfig returns the channel config for a given channel id.\n\t// Note, it is a stable bundle, which means it will not be updated, even if\n\t// the channel is, so it should be discarded after use.\n\tGetStableChannelConfig(channelID string) channelconfig.Resources\n}\n```\nChannelConfigSource provides a way to retrieve the channel config for a given channel ID.\n\n```go\ntype ChannelPolicyReferenceProvider interface {\n\t// NewPolicy creates a new policy based on the policy bytes\n\tNewPolicy(channelID, channelConfigPolicyReference string) (policies.Policy, error)\n}\n```\nChannelPolicyReferenceProvider is used to determine if a set of signature is valid and complies with a policy\n\n```go\ntype DummyQueryExecutorShim struct {\n}\n```\nDummyQueryExecutorShim implements the ReadableState interface. It is used to ensure channel-less system chaincode calls don't panic and return and error when an invalid operation is attempted (i.e. an InstallChaincode invocation against a chaincode other than \\_lifecycle)\n\n```go\nfunc (*DummyQueryExecutorShim) GetState(key string) ([]byte, error)\n```\n\n```go\ntype ErrNamespaceNotDefined struct {\n\tNamespace string\n}\n```\nErrNamespaceNotDefined is the error returned when a namespace is not defined. This indicates that the chaincode definition has not been committed.\n\n```go\nfunc (e ErrNamespaceNotDefined) Error() string\n```\n\n```go\ntype EventBroker struct {\n\t// contains filtered or unexported fields\n}\n```\nEventBroker receives events from lifecycle cache and in turn invokes the registered listeners\n\n```go\nfunc NewEventBroker(chaincodeStore ChaincodeStore, pkgParser PackageParser, ebMetadata *externalbuilder.MetadataProvider) *EventBroker\n```\n\n```go\nfunc (b *EventBroker) ApproveOrDefineCommitted(channelID string)\n```\nApproveOrDefineCommitted gets invoked after the commit of state updates that triggered the invocation of \"ProcessApproveOrDefineEvent\" function\n\n```go\nfunc (b *EventBroker) ProcessApproveOrDefineEvent(channelID string, chaincodeName string, cachedChaincode *CachedChaincodeDefinition)\n```\nProcessApproveOrDefineEvent gets invoked by an event that makes approve and define to be true This should be OK even if this function gets invoked on defined and approved events separately because the first check in this function evaluates the final condition. However, the current cache implementation invokes this function when approve and define both become true.\n\n```go\nfunc (b *EventBroker) ProcessInstallEvent(localChaincode *LocalChaincode)\n```\nProcessInstallEvent gets invoked when a chaincode is installed\n\n```go\nfunc (b *EventBroker) RegisterListener(channelID string, listener ledger.ChaincodeLifecycleEventListener)\n```\n\n```go\ntype ExternalFunctions struct {\n\tResources                 *Resources\n\tInstallListener           InstallListener\n\tInstalledChaincodesLister InstalledChaincodesLister\n\tChaincodeBuilder          ChaincodeBuilder\n\tBuildRegistry             *container.BuildRegistry\n\n\tBuildLocks map[string]sync.Mutex\n\t// contains filtered or unexported fields\n}\n```\nExternalFunctions is intended primarily to support the SCC functions. In general, its methods signatures produce writes (which must be commmitted as part of an endorsement flow), or return human readable errors (for instance indicating a chaincode is not found) rather than sentinels. Instead, use the utility functions attached to the lifecycle Resources when needed.\n\n```go\nfunc (ef *ExternalFunctions) ApproveChaincodeDefinitionForOrg(chname, ccname string, cd *ChaincodeDefinition, packageID string, publicState ReadableState, orgState ReadWritableState) error\n```\nApproveChaincodeDefinitionForOrg adds a chaincode definition entry into the passed in Org state.  The definition must be for either the currently defined sequence number or the next sequence number.  If the definition is for the current sequence number, then it must match exactly the current definition or it will be rejected.\n\n```go\nfunc (ef *ExternalFunctions) CheckCommitReadiness(chname, ccname string, cd *ChaincodeDefinition, publicState ReadWritableState, orgStates []OpaqueState) (map[string]bool, error)\n```\nCheckCommitReadiness takes a chaincode definition, checks that its sequence number is the next allowable sequence number and checks which organizations have approved the definition.\n\n```go\nfunc (ef *ExternalFunctions) CommitChaincodeDefinition(chname, ccname string, cd *ChaincodeDefinition, publicState ReadWritableState, orgStates []OpaqueState) (map[string]bool, error)\n```\nCommitChaincodeDefinition takes a chaincode definition, checks that its sequence number is the next allowable sequence number, checks which organizations have approved the definition, and applies the definition to the public world state. It is the responsibility of the caller to check the approvals to determine if the result is valid (typically, this means checking that the peer's own org has approved the definition).\n\n```go\nfunc (ef *ExternalFunctions) DefaultEndorsementPolicyAsBytes(channelID string) ([]byte, error)\n```\nDefaultEndorsementPolicyAsBytes returns a marshalled version of the default chaincode endorsement policy in the supplied channel\n\n```go\nfunc (ef *ExternalFunctions) GetInstalledChaincodePackage(packageID string) ([]byte, error)\n```\nGetInstalledChaincodePackage retrieves the installed chaincode with the given package ID from the peer's chaincode store.\n\n```go\nfunc (ef *ExternalFunctions) InstallChaincode(chaincodeInstallPackage []byte) (*chaincode.InstalledChaincode, error)\n```\nInstallChaincode installs a given chaincode to the peer's chaincode store. It returns the hash to reference the chaincode by or an error on failure.\n\n```go\nfunc (ef *ExternalFunctions) QueryChaincodeDefinition(name string, publicState ReadableState) (*ChaincodeDefinition, error)\n```\nQueryChaincodeDefinition returns the defined chaincode by the given name (if it is committed, and a chaincode) or otherwise returns an error.\n\n```go\nfunc (ef *ExternalFunctions) QueryInstalledChaincode(packageID string) (*chaincode.InstalledChaincode, error)\n```\nQueryInstalledChaincode returns metadata for the chaincode with the supplied package ID.\n\n```go\nfunc (ef *ExternalFunctions) QueryInstalledChaincodes() []*chaincode.InstalledChaincode\n```\nQueryInstalledChaincodes returns a list of installed chaincodes\n\n```go\nfunc (ef *ExternalFunctions) QueryNamespaceDefinitions(publicState RangeableState) (map[string]string, error)\n```\nQueryNamespaceDefinitions lists the publicly defined namespaces in a channel.  Today it should only ever find Datatype encodings of 'ChaincodeDefinition'.\n\n```go\nfunc (ef *ExternalFunctions) QueryOrgApprovals(name string, cd *ChaincodeDefinition, orgStates []OpaqueState) (map[string]bool, error)\n```\nQueryOrgApprovals returns a map containing the orgs whose orgStates were provided and whether or not they have approved a chaincode definition with the specified parameters.\n\n```go\nfunc (ef *ExternalFunctions) SetChaincodeDefinitionDefaults(chname string, cd *ChaincodeDefinition) error\n```\nSetChaincodeDefinitionDefaults fills any empty fields in the supplied ChaincodeDefinition with the supplied channel's defaults\n\n```go\ntype HandleMetadataUpdateFunc func(channel string, metadata chaincode.MetadataSet)\n```\nHandleMetadataUpdateFunc is triggered upon a change in the chaincode lifecycle.\n\n```go\nfunc (handleMetadataUpdate HandleMetadataUpdateFunc) HandleMetadataUpdate(channel string, metadata chaincode.MetadataSet)\n```\nHandleMetadataUpdate runs whenever there is a change to the metadata of a chaincode in the context of a specific channel.\n\n```go\ntype InstallListener interface {\n\tHandleChaincodeInstalled(md *persistence.ChaincodePackageMetadata, packageID string)\n}\n```\n\n```go\ntype InstalledChaincodesLister interface {\n\tListInstalledChaincodes() []*chaincode.InstalledChaincode\n\tGetInstalledChaincode(packageID string) (*chaincode.InstalledChaincode, error)\n}\n```\n\n```go\ntype Invocation struct {\n\tChannelID         string\n\tApplicationConfig channelconfig.Application // Note this may be nil\n\tStub              shim.ChaincodeStubInterface\n\tSCC               *SCC\n}\n```\n\n```go\nfunc (i *Invocation) ApproveChaincodeDefinitionForMyOrg(input *lb.ApproveChaincodeDefinitionForMyOrgArgs) (proto.Message, error)\n```\nApproveChaincodeDefinitionForMyOrg is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.\n\n```go\nfunc (i *Invocation) CheckCommitReadiness(input *lb.CheckCommitReadinessArgs) (proto.Message, error)\n```\nCheckCommitReadiness is a SCC function that may be dispatched to the underlying lifecycle implementation.\n\n```go\nfunc (i *Invocation) CommitChaincodeDefinition(input *lb.CommitChaincodeDefinitionArgs) (proto.Message, error)\n```\nCommitChaincodeDefinition is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.\n\n```go\nfunc (i *Invocation) GetInstalledChaincodePackage(input *lb.GetInstalledChaincodePackageArgs) (proto.Message, error)\n```\nGetInstalledChaincodePackage is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.\n\n```go\nfunc (i *Invocation) InstallChaincode(input *lb.InstallChaincodeArgs) (proto.Message, error)\n```\nInstallChaincode is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.\n\n```go\nfunc (i *Invocation) QueryChaincodeDefinition(input *lb.QueryChaincodeDefinitionArgs) (proto.Message, error)\n```\nQueryChaincodeDefinition is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.\n\n```go\nfunc (i *Invocation) QueryChaincodeDefinitions(input *lb.QueryChaincodeDefinitionsArgs) (proto.Message, error)\n```\nQueryChaincodeDefinitions is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.\n\n```go\nfunc (i *Invocation) QueryInstalledChaincode(input *lb.QueryInstalledChaincodeArgs) (proto.Message, error)\n```\nQueryInstalledChaincode is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.\n\n```go\nfunc (i *Invocation) QueryInstalledChaincodes(input *lb.QueryInstalledChaincodesArgs) (proto.Message, error)\n```\nQueryInstalledChaincodes is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.\n\n```go\ntype LegacyDeployedCCInfoProvider interface {\n\tledger.DeployedChaincodeInfoProvider\n}\n```\n\n```go\ntype LegacyMetadataProvider interface {\n\tMetadata(channel string, cc string, collections ...string) *chaincode.Metadata\n}\n```\nLegacyMetadataProvider provides metadata for a lscc-defined chaincode on a specific channel.\n\n```go\ntype Lifecycle interface {\n\tChaincodeEndorsementInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (*ChaincodeEndorsementInfo, error)\n}\n```\nLifecycle is the interface which the core/chaincode package and core/endorser package requires that lifecycle satisfy.\n\n```go\ntype LocalChaincode struct {\n\tInfo       *ChaincodeInstallInfo\n\tReferences map[string]map[string]*CachedChaincodeDefinition\n}\n```\n\n```go\nfunc (l *LocalChaincode) ToInstalledChaincode() *chaincode.InstalledChaincode\n```\nToInstalledChaincode converts a LocalChaincode to an InstalledChaincode, which is returned by lifecycle queries.\n\n```go\ntype LocalChaincodeInfo struct {\n\tDefinition  *ChaincodeDefinition\n\tApproved    bool\n\tInstallInfo *ChaincodeInstallInfo\n}\n```\n\n```go\ntype Marshaler func(proto.Message) ([]byte, error)\n```\n\n```go\nfunc (m Marshaler) Marshal(msg proto.Message) ([]byte, error)\n```\n\n```go\ntype MetadataHandler interface {\n\tInitializeMetadata(channel string, chaincodes chaincode.MetadataSet)\n\tUpdateMetadata(channel string, chaincodes chaincode.MetadataSet)\n}\n```\nMetadataHandler is the interface through which the cache drives metadata updates for listeners such as gossip and service discovery\n\n```go\ntype MetadataManager struct {\n\tLegacyMetadataSet map[string]chaincode.MetadataSet\n\tMetadataSet       map[string]chaincode.MetadataSet\n\t// contains filtered or unexported fields\n}\n```\nMetadataManager stores metadata about the chaincodes installed/deployed via \\_lifecycle (Metadaset) and lscc (LegacyMetadataSet) and updates any registered listeners upon a change in the metadata.\n\n```go\nfunc NewMetadataManager() *MetadataManager\n```\n\n```go\nfunc (m *MetadataManager) AddListener(listener MetadataUpdateListener)\n```\nAddListener registers the given listener to be triggered upon a lifecycle change\n\n```go\nfunc (m *MetadataManager) HandleMetadataUpdate(channel string, metadata chaincode.MetadataSet)\n```\nHandleMetadataUpdate implements the function of the same name in the cclifecycle.LifecycleChangeListener interface. This function is called by the legacy lifecycle (lscc) to deliver updates so we aggregate them and propagate them to our listeners. This function is also called to initialise data structures right at peer startup time.\n\n```go\nfunc (m *MetadataManager) InitializeMetadata(channel string, metadata chaincode.MetadataSet)\n```\nInitializeMetadata implements the function of the same name in the lifecycle.MetadataManager interface. This function is called by \\_lifecycle to initialize metadata for the given channel.\n\n```go\nfunc (m *MetadataManager) UpdateMetadata(channel string, metadata chaincode.MetadataSet)\n```\nUpdateMetadata implements the function of the same name in the lifecycle.MetadataManager interface. This function is called by \\_lifecycle to deliver updates so we aggregate them and propagate them to our listeners.\n\n```go\ntype MetadataProvider struct {\n\tChaincodeInfoProvider          ChaincodeInfoProvider\n\tLegacyMetadataProvider         LegacyMetadataProvider\n\tChannelPolicyReferenceProvider ChannelPolicyReferenceProvider\n}\n```\n\n```go\nfunc NewMetadataProvider(cip ChaincodeInfoProvider, lmp LegacyMetadataProvider, ccs ChannelConfigSource) *MetadataProvider\n```\nNewMetadataProvider returns a new MetadataProvider instance\n\n```go\nfunc (mp *MetadataProvider) Metadata(channel string, ccName string, collections ...string) *chaincode.Metadata\n```\nMetadata implements the metadata retriever support interface for service discovery\n\n```go\ntype MetadataUpdateListener interface {\n\tHandleMetadataUpdate(channel string, metadata chaincode.MetadataSet)\n}\n```\nMetadataUpdateListener runs whenever there is a change to the metadata of a chaincode in the context of a specific channel.\n\n```go\ntype OpaqueState interface {\n\tGetStateHash(key string) (value []byte, err error)\n\tCollectionName() string\n}\n```\n\n```go\ntype PackageParser interface {\n\tParse(data []byte) (*persistence.ChaincodePackage, error)\n}\n```\n\n```go\ntype PrivateQueryExecutor interface {\n\tGetPrivateDataHash(namespace, collection, key string) (value []byte, err error)\n}\n```\n\n```go\ntype PrivateQueryExecutorShim struct {\n\tNamespace  string\n\tCollection string\n\tState      PrivateQueryExecutor\n}\n```\n\n```go\nfunc (pqes *PrivateQueryExecutorShim) CollectionName() string\n```\n\n```go\nfunc (pqes *PrivateQueryExecutorShim) GetStateHash(key string) ([]byte, error)\n```\n\n```go\ntype QueryExecutorProvider interface {\n\tTxQueryExecutor(channelID, txID string) ledger.SimpleQueryExecutor\n}\n```\nQueryExecutorProvider provides a way to retrieve the query executor assosciated with an invocation\n\n```go\ntype RangeableState interface {\n\tGetStateRange(prefix string) (map[string][]byte, error)\n}\n```\n\n```go\ntype ReadWritableState interface {\n\tReadableState\n\tPutState(key string, value []byte) error\n\tDelState(key string) error\n}\n```\n\n```go\ntype ReadableState interface {\n\tGetState(key string) (value []byte, err error)\n}\n```\n\n```go\ntype Resources struct {\n\tChannelConfigSource ChannelConfigSource\n\tChaincodeStore      ChaincodeStore\n\tPackageParser       PackageParser\n\tSerializer          *Serializer\n}\n```\nResources stores the common functions needed by all components of the lifecycle by the SCC as well as internally.  It also has some utility methods attached to it for querying the lifecycle definitions.\n\n```go\nfunc (r *Resources) ChaincodeDefinitionIfDefined(chaincodeName string, state ReadableState) (bool, *ChaincodeDefinition, error)\n```\nChaincodeDefinitionIfDefined returns whether the chaincode name is defined in the new lifecycle, a shim around the SimpleQueryExecutor to work with the serializer, or an error.  If the namespace is defined, but it is not a chaincode, this is considered an error.\n\n```go\nfunc (r *Resources) LifecycleEndorsementPolicyAsBytes(channelID string) ([]byte, error)\n```\n\n```go\ntype ResultsIteratorShim struct {\n\tResultsIterator commonledger.ResultsIterator\n}\n```\n\n```go\nfunc (ris *ResultsIteratorShim) Close() error\n```\n\n```go\nfunc (ris *ResultsIteratorShim) Next() (*queryresult.KV, error)\n```\n\n```go\ntype SCC struct {\n\tOrgMSPID string\n\n\tACLProvider aclmgmt.ACLProvider\n\n\tChannelConfigSource ChannelConfigSource\n\n\tDeployedCCInfoProvider ledger.DeployedChaincodeInfoProvider\n\tQueryExecutorProvider  QueryExecutorProvider\n\n\t// Functions provides the backing implementation of lifecycle.\n\tFunctions SCCFunctions\n\n\t// Dispatcher handles the rote protobuf boilerplate for unmarshaling/marshaling\n\t// the inputs and outputs of the SCC functions.\n\tDispatcher *dispatcher.Dispatcher\n}\n```\nSCC implements the required methods to satisfy the chaincode interface. It routes the invocation calls to the backing implementations.\n\n```go\nfunc (scc *SCC) Chaincode() shim.Chaincode\n```\nChaincode returns a reference to itself\n\n```go\nfunc (scc *SCC) Init(stub shim.ChaincodeStubInterface) pb.Response\n```\nInit is mostly useless for system chaincodes and always returns success\n\n```go\nfunc (scc *SCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response\n```\nInvoke takes chaincode invocation arguments and routes them to the correct underlying lifecycle operation.  All functions take a single argument of type marshaled lb.\\\u003cFunctionName\u003eArgs and return a marshaled lb.\\\u003cFunctionName\u003eResult\n\n```go\nfunc (scc *SCC) Name() string\n```\nName returns \"\\_lifecycle\"\n\n```go\ntype SCCFunctions interface {\n\t// InstallChaincode persists a chaincode definition to disk\n\tInstallChaincode([]byte) (*chaincode.InstalledChaincode, error)\n\n\t// QueryInstalledChaincode returns metadata for the chaincode with the supplied package ID.\n\tQueryInstalledChaincode(packageID string) (*chaincode.InstalledChaincode, error)\n\n\t// GetInstalledChaincodePackage returns the chaincode package\n\t// installed on the peer as bytes.\n\tGetInstalledChaincodePackage(packageID string) ([]byte, error)\n\n\t// QueryInstalledChaincodes returns the currently installed chaincodes\n\tQueryInstalledChaincodes() []*chaincode.InstalledChaincode\n\n\t// ApproveChaincodeDefinitionForOrg records a chaincode definition into this org's implicit collection.\n\tApproveChaincodeDefinitionForOrg(chname, ccname string, cd *ChaincodeDefinition, packageID string, publicState ReadableState, orgState ReadWritableState) error\n\n\t// CheckCommitReadiness returns a map containing the orgs\n\t// whose orgStates were supplied and whether or not they have approved\n\t// the specified definition.\n\tCheckCommitReadiness(chname, ccname string, cd *ChaincodeDefinition, publicState ReadWritableState, orgStates []OpaqueState) (map[string]bool, error)\n\n\t// CommitChaincodeDefinition records a new chaincode definition into the\n\t// public state and returns a map containing the orgs whose orgStates\n\t// were supplied and whether or not they have approved the definition.\n\tCommitChaincodeDefinition(chname, ccname string, cd *ChaincodeDefinition, publicState ReadWritableState, orgStates []OpaqueState) (map[string]bool, error)\n\n\t// QueryChaincodeDefinition returns a chaincode definition from the public\n\t// state.\n\tQueryChaincodeDefinition(name string, publicState ReadableState) (*ChaincodeDefinition, error)\n\n\t// QueryOrgApprovals returns a map containing the orgs whose orgStates were\n\t// supplied and whether or not they have approved a chaincode definition with\n\t// the specified parameters.\n\tQueryOrgApprovals(name string, cd *ChaincodeDefinition, orgStates []OpaqueState) (map[string]bool, error)\n\n\t// QueryNamespaceDefinitions returns all defined namespaces\n\tQueryNamespaceDefinitions(publicState RangeableState) (map[string]string, error)\n}\n```\nSCCFunctions provides a backing implementation with concrete arguments for each of the SCC functions\n\n```go\ntype Serializer struct {\n\t// Marshaler, when nil uses the standard protobuf impl.\n\t// Can be overridden for test.\n\tMarshaler Marshaler\n}\n```\nSerializer is used to write structures into the db and to read them back out. Although it's unfortunate to write a custom serializer, rather than to use something pre-written, like protobuf or JSON, in order to produce precise readwrite sets which only perform state updates for keys which are actually updated (and not simply set to the same value again) custom serialization is required.\n\n```go\nfunc (s *Serializer) Deserialize(namespace, name string, metadata *lb.StateMetadata, structure interface{}, state ReadableState) error\n```\nDeserialize accepts a struct (of a type previously serialized) and populates it with the values from the db. Note: The struct names for the serialization and deserialization must match exactly.  Unencoded fields are not populated, and the extraneous keys are ignored.  The metadata provided should have been returned by a DeserializeMetadata call for the same namespace and name.\n\n```go\nfunc (s *Serializer) DeserializeAllMetadata(namespace string, state RangeableState) (map[string]*lb.StateMetadata, error)\n```\n\n```go\nfunc (s *Serializer) DeserializeField(namespace, name, field string, state ReadableState) (*lb.StateData, error)\n```\n\n```go\nfunc (s *Serializer) DeserializeFieldAsBytes(namespace, name, field string, state ReadableState) ([]byte, error)\n```\n\n```go\nfunc (s *Serializer) DeserializeFieldAsInt64(namespace, name, field string, state ReadableState) (int64, error)\n```\n\n```go\nfunc (s *Serializer) DeserializeFieldAsProto(namespace, name, field string, state ReadableState, msg proto.Message) error\n```\n\n```go\nfunc (s *Serializer) DeserializeFieldAsString(namespace, name, field string, state ReadableState) (string, error)\n```\n\n```go\nfunc (s *Serializer) DeserializeMetadata(namespace, name string, state ReadableState) (*lb.StateMetadata, bool, error)\n```\n\n```go\nfunc (s *Serializer) IsMetadataSerialized(namespace, name string, structure interface{}, state OpaqueState) (bool, error)\n```\n\n```go\nfunc (s *Serializer) IsSerialized(namespace, name string, structure interface{}, state OpaqueState) (bool, error)\n```\nIsSerialized essentially checks if the hashes of a serialized version of a structure matches the hashes of the pre-image of some struct serialized into the database.\n\n```go\nfunc (s *Serializer) SerializableChecks(structure interface{}) (reflect.Value, []string, error)\n```\nSerializableChecks performs some boilerplate checks to make sure the given structure is serializable.  It returns the reflected version of the value and a slice of all field names, or an error.\n\n```go\nfunc (s *Serializer) Serialize(namespace, name string, structure interface{}, state ReadWritableState) error\n```\nSerialize takes a pointer to a struct, and writes each of its fields as keys into a namespace.  It also writes the struct metadata (if it needs updating) and,  deletes any keys in the namespace which are not found in the struct. Note: If a key already exists for the field, and the value is unchanged, then the key is \\_not\\_ written to.\n\n```go\ntype SimpleQueryExecutorShim struct {\n\tNamespace           string\n\tSimpleQueryExecutor ledger.SimpleQueryExecutor\n}\n```\nSimpleQueryExecutorShim implements the ReadableState and RangeableState interfaces based on an underlying ledger.SimpleQueryExecutor\n\n```go\nfunc (sqes *SimpleQueryExecutorShim) GetState(key string) ([]byte, error)\n```\n\n```go\nfunc (sqes *SimpleQueryExecutorShim) GetStateRange(prefix string) (map[string][]byte, error)\n```\n\n```go\ntype StateIterator interface {\n\tClose() error\n\tNext() (*queryresult.KV, error)\n}\n```\n\n```go\ntype ValidatorCommitter struct {\n\tCoreConfig                   *peer.Config\n\tPrivdataConfig               *privdata.PrivdataConfig\n\tResources                    *Resources\n\tLegacyDeployedCCInfoProvider LegacyDeployedCCInfoProvider\n}\n```\n\n```go\nfunc (vc *ValidatorCommitter) AllCollectionsConfigPkg(channelName, chaincodeName string, qe ledger.SimpleQueryExecutor) (*pb.CollectionConfigPackage, error)\n```\nAllCollectionsConfigPkg implements function in interface ledger.DeployedChaincodeInfoProvider this implementation returns a combined collection config pkg that contains both explicit and implicit collections\n\n```go\nfunc (vc *ValidatorCommitter) ChaincodeImplicitCollections(channelName string) ([]*pb.StaticCollectionConfig, error)\n```\nChaincodeImplicitCollections assumes the chaincode exists in the new lifecycle and returns the implicit collections\n\n```go\nfunc (vc *ValidatorCommitter) ChaincodeInfo(channelName, chaincodeName string, qe ledger.SimpleQueryExecutor) (*ledger.DeployedChaincodeInfo, error)\n```\n\n```go\nfunc (vc *ValidatorCommitter) CollectionInfo(channelName, chaincodeName, collectionName string, qe ledger.SimpleQueryExecutor) (*pb.StaticCollectionConfig, error)\n```\nCollectionInfo implements function in interface ledger.DeployedChaincodeInfoProvider, it returns config for both static and implicit collections.\n\n```go\nfunc (vc *ValidatorCommitter) CollectionValidationInfo(channelID, chaincodeName, collectionName string, state validationState.State) (args []byte, unexpectedErr, validationErr error)\n```\nCollectionValidationInfo returns information about collections to the validation component\n\n```go\nfunc (vc *ValidatorCommitter) GenerateImplicitCollectionForOrg(mspid string) *pb.StaticCollectionConfig\n```\nGenerateImplicitCollectionForOrg generates implicit collection for the org\n\n```go\nfunc (vc *ValidatorCommitter) ImplicitCollectionEndorsementPolicyAsBytes(channelID, orgMSPID string) (policy []byte, unexpectedErr, validationErr error)\n```\n\n```go\nfunc (vc *ValidatorCommitter) ImplicitCollections(channelName, chaincodeName string, qe ledger.SimpleQueryExecutor) ([]*pb.StaticCollectionConfig, error)\n```\nImplicitCollections implements function in interface ledger.DeployedChaincodeInfoProvider.  It returns a slice that contains one proto msg for each of the implicit collections\n\n```go\nfunc (vc *ValidatorCommitter) Namespaces() []string\n```\nNamespaces returns the list of namespaces which are relevant to chaincode lifecycle\n\n```go\nfunc (vc *ValidatorCommitter) UpdatedChaincodes(stateUpdates map[string][]*kvrwset.KVWrite) ([]*ledger.ChaincodeLifecycleInfo, error)\n```\nUpdatedChaincodes returns the chaincodes that are getting updated by the supplied 'stateUpdates'\n\n```go\nfunc (vc *ValidatorCommitter) ValidationInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (plugin string, args []byte, unexpectedErr error, validationErr error)\n```\nValidationInfo returns the name and arguments of the validation plugin for the supplied chaincode. The function returns two types of errors, unexpected errors and validation errors. The reason for this is that this function is called from the validation code, which needs to differentiate the two types of error to halt processing on the channel if the unexpected error is not nil and mark the transaction as invalid if the validation error is not nil.\n\n```go\ntype ValidatorStateShim struct {\n\tValidatorState validatorstate.State\n\tNamespace      string\n}\n```\n\n```go\nfunc (vss *ValidatorStateShim) GetState(key string) ([]byte, error)\n```\n\n","path":"https-1xa.pages.dev/hyperledger/fabric/core/chaincode/lifecycle","name":"lifecycle","synopsis":"","isRedistributable":true}
