{"modulePath":"github.com/wanghui708/fabric","version":"v2.0.1+incompatible","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package chaincode\n\n## Constants\n\n```go\nconst DevModeUserRunsChaincode string = \"dev\"\n```\nDevModeUserRunsChaincode enables chaincode execution in a development environment\n\n```go\nconst (\n\t// InitializedKeyName is the reserved key in a chaincode's namespace which\n\t// records the ID of the chaincode which initialized the namespace.\n\t// In this way, we can enforce Init exactly once semantics, whenever\n\t// the backing chaincode bytes change (but not be required to re-initialize\n\t// the chaincode say, when endorsement policy changes).\n\tInitializedKeyName = \"\\x00\" + string(utf8.MaxRune) + \"initialized\"\n)\n```\n\n## Functions\n\n```go\nfunc IsDevMode() bool\n```\nIsDevMode returns true if the peer was configured with development-mode enabled.\n\n```go\nfunc NewTxKey(channelID, txID string) string\n```\n\n```go\nfunc ParseName(ccName string) *sysccprovider.ChaincodeInstance\n```\nParseName parses a chaincode name into a ChaincodeInstance. The name should be of the form \"chaincode-name:version/channel-name\" with optional elements.\n\n## Types\n\n```go\ntype ACLProvider interface {\n\tCheckACL(resName string, channelID string, idinfo interface{}) error\n}\n```\nAn ACLProvider performs access control checks when invoking chaincode.\n\n```go\ntype ActiveTransactions struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewActiveTransactions() *ActiveTransactions\n```\n\n```go\nfunc (a *ActiveTransactions) Add(channelID, txID string) bool\n```\n\n```go\nfunc (a *ActiveTransactions) Remove(channelID, txID string)\n```\n\n```go\ntype ApplicationConfigRetriever interface {\n\t// GetApplicationConfig returns the channelconfig.Application for the channel\n\t// and whether the Application config exists\n\tGetApplicationConfig(cid string) (channelconfig.Application, bool)\n}\n```\nApplicationConfigRetriever to retrieve the application configuration for a channel\n\n```go\ntype CertGenerator interface {\n\t// Generate returns a certificate and private key and associates\n\t// the hash of the certificates with the given chaincode name\n\tGenerate(ccName string) (*accesscontrol.CertAndPrivKeyPair, error)\n}\n```\nCertGenerator generates client certificates for chaincode.\n\n```go\ntype ChaincodeSupport struct {\n\tACLProvider            ACLProvider\n\tAppConfig              ApplicationConfigRetriever\n\tBuiltinSCCs            scc.BuiltinSCCs\n\tDeployedCCInfoProvider ledger.DeployedChaincodeInfoProvider\n\tExecuteTimeout         time.Duration\n\tInstallTimeout         time.Duration\n\tHandlerMetrics         *HandlerMetrics\n\tHandlerRegistry        *HandlerRegistry\n\tKeepalive              time.Duration\n\tLauncher               Launcher\n\tLifecycle              Lifecycle\n\tPeer                   *peer.Peer\n\tRuntime                Runtime\n\tTotalQueryLimit        int\n\tUserRunsCC             bool\n}\n```\nChaincodeSupport responsible for providing interfacing with chaincodes from the Peer.\n\n```go\nfunc (cs *ChaincodeSupport) CheckInvocation(txParams *ccprovider.TransactionParams, chaincodeName string, input *pb.ChaincodeInput) (ccid string, cctype pb.ChaincodeMessage_Type, err error)\n```\nCheckInvocation inspects the parameters of an invocation and determines if, how, and to where a that invocation should be routed. First, we ensure that the target namespace is defined on the channel and invokable on this peer, according to the lifecycle implementation. Then, if the chaincode definition requires it, this function enforces 'init exactly once' semantics. Finally, it returns the chaincode ID to route to and the message type of the request (normal transation, or init).\n\n```go\nfunc (cs *ChaincodeSupport) Execute(txParams *ccprovider.TransactionParams, chaincodeName string, input *pb.ChaincodeInput) (*pb.Response, *pb.ChaincodeEvent, error)\n```\nExecute invokes chaincode and returns the original response.\n\n```go\nfunc (cs *ChaincodeSupport) ExecuteLegacyInit(txParams *ccprovider.TransactionParams, ccName, ccVersion string, input *pb.ChaincodeInput) (*pb.Response, *pb.ChaincodeEvent, error)\n```\nExecuteLegacyInit is a temporary method which should be removed once the old style lifecycle is entirely deprecated.  Ideally one release after the introduction of the new lifecycle. It does not attempt to start the chaincode based on the information from lifecycle, but instead accepts the container information directly in the form of a ChaincodeDeploymentSpec.\n\n```go\nfunc (cs *ChaincodeSupport) HandleChaincodeStream(stream ccintf.ChaincodeStream) error\n```\nHandleChaincodeStream implements ccintf.HandleChaincodeStream for all vms to call with appropriate stream\n\n```go\nfunc (cs *ChaincodeSupport) Invoke(txParams *ccprovider.TransactionParams, chaincodeName string, input *pb.ChaincodeInput) (*pb.ChaincodeMessage, error)\n```\nInvoke will invoke chaincode and return the message containing the response. The chaincode will be launched if it is not already running.\n\n```go\nfunc (cs *ChaincodeSupport) Launch(ccid string) (*Handler, error)\n```\nLaunch starts executing chaincode if it is not already running. This method blocks until the peer side handler gets into ready state or encounters a fatal error. If the chaincode is already running, it simply returns.\n\n```go\nfunc (cs *ChaincodeSupport) LaunchInProc(ccid string) \u003c-chan struct{}\n```\nLaunchInProc is a stopgap solution to be called by the inproccontroller to allow system chaincodes to register\n\n```go\nfunc (cs *ChaincodeSupport) Register(stream pb.ChaincodeSupport_RegisterServer) error\n```\nRegister the bidi stream entry point called by chaincode to register with the Peer.\n\n```go\ntype CollectionACLCache map[string]*readWritePermission\n```\nCollectionACLCache encapsulates a cache that stores read write permission on a collection\n\n```go\ntype Config struct {\n\tTotalQueryLimit int\n\tTLSEnabled      bool\n\tKeepalive       time.Duration\n\tExecuteTimeout  time.Duration\n\tInstallTimeout  time.Duration\n\tStartupTimeout  time.Duration\n\tLogFormat       string\n\tLogLevel        string\n\tShimLogLevel    string\n\tSCCWhitelist    map[string]bool\n}\n```\n\n```go\nfunc GlobalConfig() *Config\n```\n\n```go\ntype ConnectionHandler interface {\n\tStream(ccid string, ccinfo *ccintf.ChaincodeServerInfo, sHandler extcc.StreamHandler) error\n}\n```\nConnectionHandler handles the \\`Chaincode\\` client connection\n\n```go\ntype ContainerRouter interface {\n\tBuild(ccid string) error\n\tChaincodeServerInfo(ccid string) (*ccintf.ChaincodeServerInfo, error)\n\tStart(ccid string, peerConnection *ccintf.PeerConnection) error\n\tStop(ccid string) error\n\tWait(ccid string) (int, error)\n}\n```\nContainerRouter is a poor abstraction used for building, and running chaincode processes. This management probably does not belong in this package, chaincode process lifecycle should be driven by what chaincodes are defined, what chaincodes are instantiated, and not driven by invocations.  But, the legacy lifecycle makes this very challenging.  Once the legacy lifecycle is removed (or perhaps before), this interface should probably go away entirely.\n\n```go\ntype ContainerRuntime struct {\n\tContainerRouter ContainerRouter\n\tBuildRegistry   *container.BuildRegistry\n}\n```\nContainerRuntime is responsible for managing containerized chaincode.\n\n```go\nfunc (c *ContainerRuntime) Build(ccid string) (*ccintf.ChaincodeServerInfo, error)\n```\nBuild builds the chaincode if necessary and returns ChaincodeServerInfo if the chaincode is a server\n\n```go\nfunc (c *ContainerRuntime) Start(ccid string, ccinfo *ccintf.PeerConnection) error\n```\nStart launches chaincode in a runtime environment.\n\n```go\nfunc (c *ContainerRuntime) Stop(ccid string) error\n```\nStop terminates chaincode and its container runtime environment.\n\n```go\nfunc (c *ContainerRuntime) Wait(ccid string) (int, error)\n```\nWait waits for the container runtime to terminate.\n\n```go\ntype ContextRegistry interface {\n\tCreate(txParams *ccprovider.TransactionParams) (*TransactionContext, error)\n\tGet(chainID, txID string) *TransactionContext\n\tDelete(chainID, txID string)\n\tClose()\n}\n```\nA ContextRegistry is responsible for managing transaction contexts.\n\n```go\ntype Handler struct {\n\t// Keepalive specifies the interval at which keep-alive messages are sent.\n\tKeepalive time.Duration\n\t// TotalQueryLimit specifies the maximum number of results to return for\n\t// chaincode queries.\n\tTotalQueryLimit int\n\t// Invoker is used to invoke chaincode.\n\tInvoker Invoker\n\t// Registry is used to track active handlers.\n\tRegistry Registry\n\t// ACLProvider is used to check if a chaincode invocation should be allowed.\n\tACLProvider ACLProvider\n\t// TXContexts is a collection of TransactionContext instances\n\t// that are accessed by channel name and transaction ID.\n\tTXContexts ContextRegistry\n\t// activeTransactions holds active transaction identifiers.\n\tActiveTransactions TransactionRegistry\n\t// BuiltinSCCs can be used to determine if a name is associated with a system chaincode\n\tBuiltinSCCs scc.BuiltinSCCs\n\t// QueryResponseBuilder is used to build query responses\n\tQueryResponseBuilder QueryResponseBuilder\n\t// LedgerGetter is used to get the ledger associated with a channel\n\tLedgerGetter LedgerGetter\n\t// DeployedCCInfoProvider is used to initialize the Collection Store\n\tDeployedCCInfoProvider ledger.DeployedChaincodeInfoProvider\n\t// UUIDGenerator is used to generate UUIDs\n\tUUIDGenerator UUIDGenerator\n\t// AppConfig is used to retrieve the application config for a channel\n\tAppConfig ApplicationConfigRetriever\n\t// Metrics holds chaincode handler metrics\n\tMetrics *HandlerMetrics\n\t// contains filtered or unexported fields\n}\n```\nHandler implements the peer side of the chaincode stream.\n\n```go\nfunc (h *Handler) Close()\n```\n\n```go\nfunc (h *Handler) Execute(txParams *ccprovider.TransactionParams, namespace string, msg *pb.ChaincodeMessage, timeout time.Duration) (*pb.ChaincodeMessage, error)\n```\n\n```go\nfunc (h *Handler) HandleDelState(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)\n```\n\n```go\nfunc (h *Handler) HandleGetHistoryForKey(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)\n```\nHandles query to ledger history db\n\n```go\nfunc (h *Handler) HandleGetPrivateDataHash(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)\n```\n\n```go\nfunc (h *Handler) HandleGetQueryResult(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)\n```\nHandles query to ledger to execute query state\n\n```go\nfunc (h *Handler) HandleGetState(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)\n```\nHandles query to ledger to get state\n\n```go\nfunc (h *Handler) HandleGetStateByRange(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)\n```\nHandles query to ledger to rage query state\n\n```go\nfunc (h *Handler) HandleGetStateMetadata(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)\n```\nHandles query to ledger to get state metadata\n\n```go\nfunc (h *Handler) HandleInvokeChaincode(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)\n```\nHandles requests that modify ledger state\n\n```go\nfunc (h *Handler) HandlePutState(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)\n```\n\n```go\nfunc (h *Handler) HandlePutStateMetadata(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)\n```\n\n```go\nfunc (h *Handler) HandleQueryStateClose(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)\n```\nHandles the closing of a state iterator\n\n```go\nfunc (h *Handler) HandleQueryStateNext(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)\n```\nHandles query to ledger for query state next\n\n```go\nfunc (h *Handler) HandleRegister(msg *pb.ChaincodeMessage)\n```\nhandleRegister is invoked when chaincode tries to register.\n\n```go\nfunc (h *Handler) HandleTransaction(msg *pb.ChaincodeMessage, delegate handleFunc)\n```\nHandleTransaction is a middleware function that obtains and verifies a transaction context prior to forwarding the message to the provided delegate. Response messages returned by the delegate are sent to the chat stream. Any errors returned by the delegate are packaged as chaincode error messages.\n\n```go\nfunc (h *Handler) Notify(msg *pb.ChaincodeMessage)\n```\n\n```go\nfunc (h *Handler) ProcessStream(stream ccintf.ChaincodeStream) error\n```\n\n```go\nfunc (h *Handler) State() State\n```\n\n```go\ntype HandlerMetrics struct {\n\tShimRequestsReceived  metrics.Counter\n\tShimRequestsCompleted metrics.Counter\n\tShimRequestDuration   metrics.Histogram\n\tExecuteTimeouts       metrics.Counter\n}\n```\n\n```go\nfunc NewHandlerMetrics(p metrics.Provider) *HandlerMetrics\n```\n\n```go\ntype HandlerRegistry struct {\n\t// contains filtered or unexported fields\n}\n```\nHandlerRegistry maintains chaincode Handler instances.\n\n```go\nfunc NewHandlerRegistry(allowUnsolicitedRegistration bool) *HandlerRegistry\n```\nNewHandlerRegistry constructs a HandlerRegistry.\n\n```go\nfunc (r *HandlerRegistry) Deregister(ccid string) error\n```\nDeregister clears references to state associated specified chaincode. As part of the cleanup, it closes the handler so it can cleanup any state. If the registry does not contain the provided handler, an error is returned.\n\n```go\nfunc (r *HandlerRegistry) Failed(ccid string, err error)\n```\nFailed indicates that registration of a launched chaincode has failed.\n\n```go\nfunc (r *HandlerRegistry) Handler(ccid string) *Handler\n```\nHandler retrieves the handler for a chaincode instance.\n\n```go\nfunc (r *HandlerRegistry) Launching(ccid string) (*LaunchState, bool)\n```\nLaunching indicates that chaincode is being launched. The LaunchState that is returned provides mechanisms to determine when the operation has completed and whether or not it failed. The bool indicates whether or not the chaincode has already been started.\n\n```go\nfunc (r *HandlerRegistry) Ready(ccid string)\n```\nReady indicates that the chaincode registration has completed and the READY response has been sent to the chaincode.\n\n```go\nfunc (r *HandlerRegistry) Register(h *Handler) error\n```\nRegister adds a chaincode handler to the registry. An error will be returned if a handler is already registered for the chaincode. An error will also be returned if the chaincode has not already been \"launched\", and unsolicited registration is not allowed.\n\n```go\ntype Invoker interface {\n\tInvoke(txParams *ccprovider.TransactionParams, chaincodeName string, spec *pb.ChaincodeInput) (*pb.ChaincodeMessage, error)\n}\n```\nAn Invoker invokes chaincode.\n\n```go\ntype LaunchMetrics struct {\n\tLaunchDuration metrics.Histogram\n\tLaunchFailures metrics.Counter\n\tLaunchTimeouts metrics.Counter\n}\n```\n\n```go\nfunc NewLaunchMetrics(p metrics.Provider) *LaunchMetrics\n```\n\n```go\ntype LaunchRegistry interface {\n\tLaunching(ccid string) (launchState *LaunchState, started bool)\n\tDeregister(ccid string) error\n}\n```\nLaunchRegistry tracks launching chaincode instances.\n\n```go\ntype LaunchState struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewLaunchState() *LaunchState\n```\n\n```go\nfunc (l *LaunchState) Done() \u003c-chan struct{}\n```\n\n```go\nfunc (l *LaunchState) Err() error\n```\n\n```go\nfunc (l *LaunchState) Notify(err error)\n```\n\n```go\ntype Launcher interface {\n\tLaunch(ccid string, streamHandler extcc.StreamHandler) error\n\tStop(ccid string) error\n}\n```\nLauncher is used to launch chaincode runtimes.\n\n```go\ntype LedgerGetter interface {\n\tGetLedger(cid string) ledger.PeerLedger\n}\n```\nLedgerGetter is used to get ledgers for chaincode.\n\n```go\ntype Lifecycle interface {\n\t// ChaincodeEndorsementInfo looks up the chaincode info in the given channel.  It is the responsibility\n\t// of the implementation to add appropriate read dependencies for the information returned.\n\tChaincodeEndorsementInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (*lifecycle.ChaincodeEndorsementInfo, error)\n}\n```\nLifecycle provides a way to retrieve chaincode definitions and the packages necessary to run them\n\n```go\ntype MessageHandler interface {\n\tHandle(*pb.ChaincodeMessage, *TransactionContext) (*pb.ChaincodeMessage, error)\n}\n```\n\n```go\ntype PendingQueryResult struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (p *PendingQueryResult) Add(queryResult commonledger.QueryResult) error\n```\n\n```go\nfunc (p *PendingQueryResult) Cut() []*pb.QueryResultBytes\n```\n\n```go\nfunc (p *PendingQueryResult) Size() int\n```\n\n```go\ntype QueryResponseBuilder interface {\n\tBuildQueryResponse(txContext *TransactionContext, iter commonledger.ResultsIterator,\n\t\titerID string, isPaginated bool, totalReturnLimit int32) (*pb.QueryResponse, error)\n}\n```\nQueryResponseBuilder is responsible for building QueryResponse messages for query transactions initiated by chaincode.\n\n```go\ntype QueryResponseGenerator struct {\n\tMaxResultLimit int\n}\n```\n\n```go\nfunc (q *QueryResponseGenerator) BuildQueryResponse(txContext *TransactionContext, iter commonledger.ResultsIterator,\n\titerID string, isPaginated bool, totalReturnLimit int32) (*pb.QueryResponse, error)\n```\nBuildQueryResponse takes an iterator and fetch state to construct QueryResponse\n\n```go\ntype Registry interface {\n\tRegister(*Handler) error\n\tReady(string)\n\tFailed(string, error)\n\tDeregister(string) error\n}\n```\nA Registry is responsible for tracking handlers.\n\n```go\ntype Runtime interface {\n\tBuild(ccid string) (*ccintf.ChaincodeServerInfo, error)\n\tStart(ccid string, ccinfo *ccintf.PeerConnection) error\n\tStop(ccid string) error\n\tWait(ccid string) (int, error)\n}\n```\nRuntime is used to manage chaincode runtime instances.\n\n```go\ntype RuntimeLauncher struct {\n\tRuntime           Runtime\n\tRegistry          LaunchRegistry\n\tStartupTimeout    time.Duration\n\tMetrics           *LaunchMetrics\n\tPeerAddress       string\n\tCACert            []byte\n\tCertGenerator     CertGenerator\n\tConnectionHandler ConnectionHandler\n}\n```\nRuntimeLauncher is responsible for launching chaincode runtimes.\n\n```go\nfunc (r *RuntimeLauncher) ChaincodeClientInfo(ccid string) (*ccintf.PeerConnection, error)\n```\n\n```go\nfunc (r *RuntimeLauncher) Launch(ccid string, streamHandler extcc.StreamHandler) error\n```\n\n```go\nfunc (r *RuntimeLauncher) Stop(ccid string) error\n```\n\n```go\ntype State int\n```\n\n```go\nconst (\n\tCreated State = iota\n\tEstablished\n\tReady\n)\n```\n\n```go\nfunc (s State) String() string\n```\n\n```go\ntype TransactionContext struct {\n\tChannelID            string\n\tNamespaceID          string\n\tSignedProp           *pb.SignedProposal\n\tProposal             *pb.Proposal\n\tResponseNotifier     chan *pb.ChaincodeMessage\n\tTXSimulator          ledger.TxSimulator\n\tHistoryQueryExecutor ledger.HistoryQueryExecutor\n\tCollectionStore      privdata.CollectionStore\n\tIsInitTransaction    bool\n\n\t// cache used to save the result of collection acl\n\t// as a transactionContext is created for every chaincode\n\t// invoke (even in case of chaincode-calling-chaincode,\n\t// we do not need to store the namespace in the map and\n\t// collection alone is sufficient.\n\tCollectionACLCache CollectionACLCache\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (t *TransactionContext) CleanupQueryContext(queryID string)\n```\n\n```go\nfunc (t *TransactionContext) CleanupQueryContextWithBookmark(queryID string) string\n```\n\n```go\nfunc (t *TransactionContext) CloseQueryIterators()\n```\n\n```go\nfunc (t *TransactionContext) GetPendingQueryResult(queryID string) *PendingQueryResult\n```\n\n```go\nfunc (t *TransactionContext) GetQueryIterator(queryID string) commonledger.ResultsIterator\n```\n\n```go\nfunc (t *TransactionContext) GetTotalReturnCount(queryID string) *int32\n```\n\n```go\nfunc (t *TransactionContext) InitializeCollectionACLCache()\n```\n\n```go\nfunc (t *TransactionContext) InitializeQueryContext(queryID string, iter commonledger.ResultsIterator)\n```\n\n```go\ntype TransactionContexts struct {\n\t// contains filtered or unexported fields\n}\n```\nTransactionContexts maintains active transaction contexts for a Handler.\n\n```go\nfunc NewTransactionContexts() *TransactionContexts\n```\nNewTransactionContexts creates a registry for active transaction contexts.\n\n```go\nfunc (c *TransactionContexts) Close()\n```\nClose closes all query iterators assocated with the context.\n\n```go\nfunc (c *TransactionContexts) Create(txParams *ccprovider.TransactionParams) (*TransactionContext, error)\n```\nCreate creates a new TransactionContext for the specified channel and transaction ID. An error is returned when a transaction context has already been created for the specified channel and transaction ID.\n\n```go\nfunc (c *TransactionContexts) Delete(channelID, txID string)\n```\nDelete removes the transaction context associated with the specified channel and transaction ID.\n\n```go\nfunc (c *TransactionContexts) Get(channelID, txID string) *TransactionContext\n```\nGet retrieves the transaction context associated with the channel and transaction ID.\n\n```go\ntype TransactionRegistry interface {\n\tAdd(channelID, txID string) bool\n\tRemove(channelID, txID string)\n}\n```\nTransactionRegistry tracks active transactions for each channel.\n\n```go\ntype TxQueryExecutorGetter struct {\n\tHandlerRegistry *HandlerRegistry\n\tCCID            string\n}\n```\n\n```go\nfunc (g *TxQueryExecutorGetter) TxQueryExecutor(chainID, txID string) ledger.SimpleQueryExecutor\n```\n\n```go\ntype UUIDGenerator interface {\n\tNew() string\n}\n```\nUUIDGenerator is responsible for creating unique query identifiers.\n\n```go\ntype UUIDGeneratorFunc func() string\n```\n\n```go\nfunc (u UUIDGeneratorFunc) New() string\n```\n\n","path":"github.com/wanghui708/fabric/core/chaincode","name":"chaincode","synopsis":"","isRedistributable":true}
