{"modulePath":"https-1xa.pages.dev/hyperledger/fabric","version":"v1.4.12","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package shim\n\nPackage shim provides APIs for the chaincode to access its state variables, transaction context and call other chaincodes.\n\nPackage shim provides APIs for the chaincode to access its state variables, transaction context and call other chaincodes.\n\n## Constants\n\n```go\nconst (\n\tSTATE_QUERY_RESULT resultType = iota + 1\n\tHISTORY_QUERY_RESULT\n)\n```\n\n```go\nconst (\n\tLogDebug    = LoggingLevel(logging.DEBUG)\n\tLogInfo     = LoggingLevel(logging.INFO)\n\tLogNotice   = LoggingLevel(logging.NOTICE)\n\tLogWarning  = LoggingLevel(logging.WARNING)\n\tLogError    = LoggingLevel(logging.ERROR)\n\tLogCritical = LoggingLevel(logging.CRITICAL)\n)\n```\nThese constants comprise the LoggingLevel enumeration\n\n```go\nconst (\n\t// OK constant - status code less than 400, endorser will endorse it.\n\t// OK means init or invoke successfully.\n\tOK = 200\n\n\t// ERRORTHRESHOLD constant - status code greater than or equal to 400 will be considered an error and rejected by endorser.\n\tERRORTHRESHOLD = 400\n\n\t// ERROR constant - default error value\n\tERROR = 500\n)\n```\n\n## Functions\n\n```go\nfunc Error(msg string) pb.Response\n```\n\n```go\nfunc IsEnabledForLogLevel(logLevel string) bool\n```\nIsEnabledForLogLevel checks to see if the chaincodeLogger is enabled for a specific logging level used primarily for testing\n\n```go\nfunc SetLoggingLevel(level LoggingLevel)\n```\nSetLoggingLevel allows a Go language chaincode to set the logging level of its shim.\n\n```go\nfunc SetupChaincodeLogging()\n```\nSetupChaincodeLogging sets the chaincode logging format and the level to the values of CORE\\_CHAINCODE\\_LOGGING\\_FORMAT, CORE\\_CHAINCODE\\_LOGGING\\_LEVEL and CORE\\_CHAINCODE\\_LOGGING\\_SHIM set from core.yaml by chaincode\\_support.go\n\n```go\nfunc Start(cc Chaincode) error\n```\nchaincodes.\n\n```go\nfunc StartInProc(env []string, args []string, cc Chaincode, recv \u003c-chan *pb.ChaincodeMessage, send chan\u003c- *pb.ChaincodeMessage) error\n```\nStartInProc is an entry point for system chaincodes bootstrap. It is not an API for chaincodes.\n\n```go\nfunc Success(payload []byte) pb.Response\n```\n\n## Types\n\n```go\ntype Chaincode interface {\n\t// Init is called during Instantiate transaction after the chaincode container\n\t// has been established for the first time, allowing the chaincode to\n\t// initialize its internal data\n\tInit(stub ChaincodeStubInterface) pb.Response\n\n\t// Invoke is called to update or query the ledger in a proposal transaction.\n\t// Updated state variables are not committed to the ledger until the\n\t// transaction is committed.\n\tInvoke(stub ChaincodeStubInterface) pb.Response\n}\n```\nChaincode interface must be implemented by all chaincodes. The fabric runs the transactions by calling these functions as specified.\n\n```go\ntype ChaincodeLogger struct {\n\t// contains filtered or unexported fields\n}\n```\nChaincodeLogger is an abstraction of a logging object for use by chaincodes. These objects are created by the NewLogger API.\n\n```go\nfunc NewLogger(name string) *ChaincodeLogger\n```\nNewLogger allows a Go language chaincode to create one or more logging objects whose logs will be formatted consistently with, and temporally interleaved with the logs created by the shim interface. The logs created by this object can be distinguished from shim logs by the name provided, which will appear in the logs.\n\n```go\nfunc (c *ChaincodeLogger) Critical(args ...interface{})\n```\nCritical logs always appear; They can not be disabled.\n\n```go\nfunc (c *ChaincodeLogger) Criticalf(format string, args ...interface{})\n```\nCriticalf logs always appear; They can not be disabled.\n\n```go\nfunc (c *ChaincodeLogger) Debug(args ...interface{})\n```\nDebug logs will only appear if the ChaincodeLogger LoggingLevel is set to LogDebug.\n\n```go\nfunc (c *ChaincodeLogger) Debugf(format string, args ...interface{})\n```\nDebugf logs will only appear if the ChaincodeLogger LoggingLevel is set to LogDebug.\n\n```go\nfunc (c *ChaincodeLogger) Error(args ...interface{})\n```\nError logs will appear if the ChaincodeLogger LoggingLevel is set to LogError, LogWarning, LogNotice, LogInfo or LogDebug.\n\n```go\nfunc (c *ChaincodeLogger) Errorf(format string, args ...interface{})\n```\nErrorf logs will appear if the ChaincodeLogger LoggingLevel is set to LogError, LogWarning, LogNotice, LogInfo or LogDebug.\n\n```go\nfunc (c *ChaincodeLogger) Info(args ...interface{})\n```\nInfo logs will appear if the ChaincodeLogger LoggingLevel is set to LogInfo or LogDebug.\n\n```go\nfunc (c *ChaincodeLogger) Infof(format string, args ...interface{})\n```\nInfof logs will appear if the ChaincodeLogger LoggingLevel is set to LogInfo or LogDebug.\n\n```go\nfunc (c *ChaincodeLogger) IsEnabledFor(level LoggingLevel) bool\n```\nIsEnabledFor returns true if the logger is enabled to creates logs at the given logging level.\n\n```go\nfunc (c *ChaincodeLogger) Notice(args ...interface{})\n```\nNotice logs will appear if the ChaincodeLogger LoggingLevel is set to LogNotice, LogInfo or LogDebug.\n\n```go\nfunc (c *ChaincodeLogger) Noticef(format string, args ...interface{})\n```\nNoticef logs will appear if the ChaincodeLogger LoggingLevel is set to LogNotice, LogInfo or LogDebug.\n\n```go\nfunc (c *ChaincodeLogger) SetLevel(level LoggingLevel)\n```\nSetLevel sets the logging level for a chaincode logger. Note that currently the levels are actually controlled by the name given when the logger is created, so loggers should be given unique names other than \"shim\".\n\n```go\nfunc (c *ChaincodeLogger) Warning(args ...interface{})\n```\nWarning logs will appear if the ChaincodeLogger LoggingLevel is set to LogWarning, LogNotice, LogInfo or LogDebug.\n\n```go\nfunc (c *ChaincodeLogger) Warningf(format string, args ...interface{})\n```\nWarningf logs will appear if the ChaincodeLogger LoggingLevel is set to LogWarning, LogNotice, LogInfo or LogDebug.\n\n```go\ntype ChaincodeStub struct {\n\tTxID      string\n\tChannelId string\n\t// contains filtered or unexported fields\n}\n```\nChaincodeStub is an object passed to chaincode for shim side handling of APIs.\n\n```go\nfunc (stub *ChaincodeStub) CreateCompositeKey(objectType string, attributes []string) (string, error)\n```\nCreateCompositeKey documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) DelPrivateData(collection string, key string) error\n```\nDelPrivateData documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) DelState(key string) error\n```\nDelState documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetArgs() [][]byte\n```\nGetArgs documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetArgsSlice() ([]byte, error)\n```\nGetArgsSlice documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetBinding() ([]byte, error)\n```\nGetBinding documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetChannelID() string\n```\nGetChannelID returns the channel for the proposal\n\n```go\nfunc (stub *ChaincodeStub) GetCreator() ([]byte, error)\n```\nGetCreator documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetDecorations() map[string][]byte\n```\n\n```go\nfunc (stub *ChaincodeStub) GetFunctionAndParameters() (function string, params []string)\n```\nGetFunctionAndParameters documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetHistoryForKey(key string) (HistoryQueryIteratorInterface, error)\n```\nGetHistoryForKey documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetPrivateData(collection string, key string) ([]byte, error)\n```\nGetPrivateData documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetPrivateDataByPartialCompositeKey(collection, objectType string, attributes []string) (StateQueryIteratorInterface, error)\n```\nGetPrivateDataByPartialCompositeKey documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetPrivateDataByRange(collection, startKey, endKey string) (StateQueryIteratorInterface, error)\n```\nGetPrivateDataByRange documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetPrivateDataHash(collection string, key string) ([]byte, error)\n```\nGetPrivateDataHash documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetPrivateDataQueryResult(collection, query string) (StateQueryIteratorInterface, error)\n```\nGetPrivateDataQueryResult documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetPrivateDataValidationParameter(collection, key string) ([]byte, error)\n```\nGetPrivateDataValidationParameter documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetQueryResult(query string) (StateQueryIteratorInterface, error)\n```\nGetQueryResult documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetQueryResultWithPagination(query string, pageSize int32,\n\tbookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)\n```\n\n```go\nfunc (stub *ChaincodeStub) GetSignedProposal() (*pb.SignedProposal, error)\n```\nGetSignedProposal documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetState(key string) ([]byte, error)\n```\nGetState documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetStateByPartialCompositeKey(objectType string, attributes []string) (StateQueryIteratorInterface, error)\n```\nGetStateByPartialCompositeKey function can be invoked by a chaincode to query the state based on a given partial composite key. This function returns an iterator which can be used to iterate over all composite keys whose prefix matches the given partial composite key. This function should be used only for a partial composite key. For a full composite key, an iter with empty response would be returned.\n\n```go\nfunc (stub *ChaincodeStub) GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string,\n\tpageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)\n```\n\n```go\nfunc (stub *ChaincodeStub) GetStateByRange(startKey, endKey string) (StateQueryIteratorInterface, error)\n```\nGetStateByRange documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetStateByRangeWithPagination(startKey, endKey string, pageSize int32,\n\tbookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)\n```\n\n```go\nfunc (stub *ChaincodeStub) GetStateValidationParameter(key string) ([]byte, error)\n```\nGetStateValidationParameter documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetStringArgs() []string\n```\nGetStringArgs documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetTransient() (map[string][]byte, error)\n```\nGetTransient documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) GetTxID() string\n```\nGetTxID returns the transaction ID for the proposal\n\n```go\nfunc (stub *ChaincodeStub) GetTxTimestamp() (*timestamp.Timestamp, error)\n```\nGetTxTimestamp documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response\n```\nInvokeChaincode documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) PutPrivateData(collection string, key string, value []byte) error\n```\nPutPrivateData documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) PutState(key string, value []byte) error\n```\nPutState documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) SetEvent(name string, payload []byte) error\n```\nSetEvent documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) SetPrivateDataValidationParameter(collection, key string, ep []byte) error\n```\nSetPrivateDataValidationParameter documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) SetStateValidationParameter(key string, ep []byte) error\n```\nSetStateValidationParameter documentation can be found in interfaces.go\n\n```go\nfunc (stub *ChaincodeStub) SplitCompositeKey(compositeKey string) (string, []string, error)\n```\nSplitCompositeKey documentation can be found in interfaces.go\n\n```go\ntype ChaincodeStubInterface interface {\n\t// GetArgs returns the arguments intended for the chaincode Init and Invoke\n\t// as an array of byte arrays.\n\tGetArgs() [][]byte\n\n\t// GetStringArgs returns the arguments intended for the chaincode Init and\n\t// Invoke as a string array. Only use GetStringArgs if the client passes\n\t// arguments intended to be used as strings.\n\tGetStringArgs() []string\n\n\t// GetFunctionAndParameters returns the first argument as the function\n\t// name and the rest of the arguments as parameters in a string array.\n\t// Only use GetFunctionAndParameters if the client passes arguments intended\n\t// to be used as strings.\n\tGetFunctionAndParameters() (string, []string)\n\n\t// GetArgsSlice returns the arguments intended for the chaincode Init and\n\t// Invoke as a byte array\n\tGetArgsSlice() ([]byte, error)\n\n\t// GetTxID returns the tx_id of the transaction proposal, which is unique per\n\t// transaction and per client. See ChannelHeader in protos/common/common.proto\n\t// for further details.\n\tGetTxID() string\n\n\t// GetChannelID returns the channel the proposal is sent to for chaincode to process.\n\t// This would be the channel_id of the transaction proposal (see ChannelHeader\n\t// in protos/common/common.proto) except where the chaincode is calling another on\n\t// a different channel\n\tGetChannelID() string\n\n\t// InvokeChaincode locally calls the specified chaincode `Invoke` using the\n\t// same transaction context; that is, chaincode calling chaincode doesn't\n\t// create a new transaction message.\n\t// If the called chaincode is on the same channel, it simply adds the called\n\t// chaincode read set and write set to the calling transaction.\n\t// If the called chaincode is on a different channel,\n\t// only the Response is returned to the calling chaincode; any PutState calls\n\t// from the called chaincode will not have any effect on the ledger; that is,\n\t// the called chaincode on a different channel will not have its read set\n\t// and write set applied to the transaction. Only the calling chaincode's\n\t// read set and write set will be applied to the transaction. Effectively\n\t// the called chaincode on a different channel is a `Query`, which does not\n\t// participate in state validation checks in subsequent commit phase.\n\t// If `channel` is empty, the caller's channel is assumed.\n\tInvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response\n\n\t// GetState returns the value of the specified `key` from the\n\t// ledger. Note that GetState doesn't read data from the writeset, which\n\t// has not been committed to the ledger. In other words, GetState doesn't\n\t// consider data modified by PutState that has not been committed.\n\t// If the key does not exist in the state database, (nil, nil) is returned.\n\tGetState(key string) ([]byte, error)\n\n\t// PutState puts the specified `key` and `value` into the transaction's\n\t// writeset as a data-write proposal. PutState doesn't effect the ledger\n\t// until the transaction is validated and successfully committed.\n\t// Simple keys must not be an empty string and must not start with a\n\t// null character (0x00) in order to avoid range query collisions with\n\t// composite keys, which internally get prefixed with 0x00 as composite\n\t// key namespace. In addition, if using CouchDB, keys can only contain\n\t// valid UTF-8 strings and cannot begin with an underscore (\"_\").\n\tPutState(key string, value []byte) error\n\n\t// DelState records the specified `key` to be deleted in the writeset of\n\t// the transaction proposal. The `key` and its value will be deleted from\n\t// the ledger when the transaction is validated and successfully committed.\n\tDelState(key string) error\n\n\t// SetStateValidationParameter sets the key-level endorsement policy for `key`.\n\tSetStateValidationParameter(key string, ep []byte) error\n\n\t// GetStateValidationParameter retrieves the key-level endorsement policy\n\t// for `key`. Note that this will introduce a read dependency on `key` in\n\t// the transaction's readset.\n\tGetStateValidationParameter(key string) ([]byte, error)\n\n\t// GetStateByRange returns a range iterator over a set of keys in the\n\t// ledger. The iterator can be used to iterate over all keys\n\t// between the startKey (inclusive) and endKey (exclusive).\n\t// However, if the number of keys between startKey and endKey is greater than the\n\t// totalQueryLimit (defined in core.yaml), this iterator cannot be used\n\t// to fetch all keys (results will be capped by the totalQueryLimit).\n\t// The keys are returned by the iterator in lexical order. Note\n\t// that startKey and endKey can be empty string, which implies unbounded range\n\t// query on start or end.\n\t// Call Close() on the returned StateQueryIteratorInterface object when done.\n\t// The query is re-executed during validation phase to ensure result set\n\t// has not changed since transaction endorsement (phantom reads detected).\n\tGetStateByRange(startKey, endKey string) (StateQueryIteratorInterface, error)\n\n\t// GetStateByRangeWithPagination returns a range iterator over a set of keys in the\n\t// ledger. The iterator can be used to fetch keys between the startKey (inclusive)\n\t// and endKey (exclusive).\n\t// When an empty string is passed as a value to the bookmark argument, the returned\n\t// iterator can be used to fetch the first `pageSize` keys between the startKey\n\t// (inclusive) and endKey (exclusive).\n\t// When the bookmark is a non-emptry string, the iterator can be used to fetch\n\t// the first `pageSize` keys between the bookmark (inclusive) and endKey (exclusive).\n\t// Note that only the bookmark present in a prior page of query results (ResponseMetadata)\n\t// can be used as a value to the bookmark argument. Otherwise, an empty string must\n\t// be passed as bookmark.\n\t// The keys are returned by the iterator in lexical order. Note\n\t// that startKey and endKey can be empty string, which implies unbounded range\n\t// query on start or end.\n\t// Call Close() on the returned StateQueryIteratorInterface object when done.\n\t// This call is only supported in a read only transaction.\n\tGetStateByRangeWithPagination(startKey, endKey string, pageSize int32,\n\t\tbookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)\n\n\t// GetStateByPartialCompositeKey queries the state in the ledger based on\n\t// a given partial composite key. This function returns an iterator\n\t// which can be used to iterate over all composite keys whose prefix matches\n\t// the given partial composite key. However, if the number of matching composite\n\t// keys is greater than the totalQueryLimit (defined in core.yaml), this iterator\n\t// cannot be used to fetch all matching keys (results will be limited by the totalQueryLimit).\n\t// The `objectType` and attributes are expected to have only valid utf8 strings and\n\t// should not contain U+0000 (nil byte) and U+10FFFF (biggest and unallocated code point).\n\t// See related functions SplitCompositeKey and CreateCompositeKey.\n\t// Call Close() on the returned StateQueryIteratorInterface object when done.\n\t// The query is re-executed during validation phase to ensure result set\n\t// has not changed since transaction endorsement (phantom reads detected).\n\tGetStateByPartialCompositeKey(objectType string, keys []string) (StateQueryIteratorInterface, error)\n\n\t// GetStateByPartialCompositeKeyWithPagination queries the state in the ledger based on\n\t// a given partial composite key. This function returns an iterator\n\t// which can be used to iterate over the composite keys whose\n\t// prefix matches the given partial composite key.\n\t// When an empty string is passed as a value to the bookmark argument, the returned\n\t// iterator can be used to fetch the first `pageSize` composite keys whose prefix\n\t// matches the given partial composite key.\n\t// When the bookmark is a non-emptry string, the iterator can be used to fetch\n\t// the first `pageSize` keys between the bookmark (inclusive) and the last matching\n\t// composite key.\n\t// Note that only the bookmark present in a prior page of query result (ResponseMetadata)\n\t// can be used as a value to the bookmark argument. Otherwise, an empty string must\n\t// be passed as bookmark.\n\t// The `objectType` and attributes are expected to have only valid utf8 strings\n\t// and should not contain U+0000 (nil byte) and U+10FFFF (biggest and unallocated\n\t// code point). See related functions SplitCompositeKey and CreateCompositeKey.\n\t// Call Close() on the returned StateQueryIteratorInterface object when done.\n\t// This call is only supported in a read only transaction.\n\tGetStateByPartialCompositeKeyWithPagination(objectType string, keys []string,\n\t\tpageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)\n\n\t// CreateCompositeKey combines the given `attributes` to form a composite\n\t// key. The objectType and attributes are expected to have only valid utf8\n\t// strings and should not contain U+0000 (nil byte) and U+10FFFF\n\t// (biggest and unallocated code point).\n\t// The resulting composite key can be used as the key in PutState().\n\tCreateCompositeKey(objectType string, attributes []string) (string, error)\n\n\t// SplitCompositeKey splits the specified key into attributes on which the\n\t// composite key was formed. Composite keys found during range queries\n\t// or partial composite key queries can therefore be split into their\n\t// composite parts.\n\tSplitCompositeKey(compositeKey string) (string, []string, error)\n\n\t// GetQueryResult performs a \"rich\" query against a state database. It is\n\t// only supported for state databases that support rich query,\n\t// e.g.CouchDB. The query string is in the native syntax\n\t// of the underlying state database. An iterator is returned\n\t// which can be used to iterate over all keys in the query result set.\n\t// However, if the number of keys in the query result set is greater than the\n\t// totalQueryLimit (defined in core.yaml), this iterator cannot be used\n\t// to fetch all keys in the query result set (results will be limited by\n\t// the totalQueryLimit).\n\t// The query is NOT re-executed during validation phase, phantom reads are\n\t// not detected. That is, other committed transactions may have added,\n\t// updated, or removed keys that impact the result set, and this would not\n\t// be detected at validation/commit time.  Applications susceptible to this\n\t// should therefore not use GetQueryResult as part of transactions that update\n\t// ledger, and should limit use to read-only chaincode operations.\n\tGetQueryResult(query string) (StateQueryIteratorInterface, error)\n\n\t// GetQueryResultWithPagination performs a \"rich\" query against a state database.\n\t// It is only supported for state databases that support rich query,\n\t// e.g., CouchDB. The query string is in the native syntax\n\t// of the underlying state database. An iterator is returned\n\t// which can be used to iterate over keys in the query result set.\n\t// When an empty string is passed as a value to the bookmark argument, the returned\n\t// iterator can be used to fetch the first `pageSize` of query results.\n\t// When the bookmark is a non-emptry string, the iterator can be used to fetch\n\t// the first `pageSize` keys between the bookmark and the last key in the query result.\n\t// Note that only the bookmark present in a prior page of query results (ResponseMetadata)\n\t// can be used as a value to the bookmark argument. Otherwise, an empty string\n\t// must be passed as bookmark.\n\t// This call is only supported in a read only transaction.\n\tGetQueryResultWithPagination(query string, pageSize int32,\n\t\tbookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)\n\n\t// GetHistoryForKey returns a history of key values across time.\n\t// For each historic key update, the historic value and associated\n\t// transaction id and timestamp are returned. The timestamp is the\n\t// timestamp provided by the client in the proposal header.\n\t// GetHistoryForKey requires peer configuration\n\t// core.ledger.history.enableHistoryDatabase to be true.\n\t// The query is NOT re-executed during validation phase, phantom reads are\n\t// not detected. That is, other committed transactions may have updated\n\t// the key concurrently, impacting the result set, and this would not be\n\t// detected at validation/commit time. Applications susceptible to this\n\t// should therefore not use GetHistoryForKey as part of transactions that\n\t// update ledger, and should limit use to read-only chaincode operations.\n\tGetHistoryForKey(key string) (HistoryQueryIteratorInterface, error)\n\n\t// GetPrivateData returns the value of the specified `key` from the specified\n\t// `collection`. Note that GetPrivateData doesn't read data from the\n\t// private writeset, which has not been committed to the `collection`. In\n\t// other words, GetPrivateData doesn't consider data modified by PutPrivateData\n\t// that has not been committed.\n\tGetPrivateData(collection, key string) ([]byte, error)\n\n\t// GetPrivateDataHash returns the hash of the value of the specified `key` from the specified\n\t// `collection`\n\tGetPrivateDataHash(collection, key string) ([]byte, error)\n\n\t// PutPrivateData puts the specified `key` and `value` into the transaction's\n\t// private writeset. Note that only hash of the private writeset goes into the\n\t// transaction proposal response (which is sent to the client who issued the\n\t// transaction) and the actual private writeset gets temporarily stored in a\n\t// transient store. PutPrivateData doesn't effect the `collection` until the\n\t// transaction is validated and successfully committed. Simple keys must not\n\t// be an empty string and must not start with a null character (0x00) in order\n\t// to avoid range query collisions with composite keys, which internally get\n\t// prefixed with 0x00 as composite key namespace. In addition, if using\n\t// CouchDB, keys can only contain valid UTF-8 strings and cannot begin with an\n\t// an underscore (\"_\").\n\tPutPrivateData(collection string, key string, value []byte) error\n\n\t// DelState records the specified `key` to be deleted in the private writeset of\n\t// the transaction. Note that only hash of the private writeset goes into the\n\t// transaction proposal response (which is sent to the client who issued the\n\t// transaction) and the actual private writeset gets temporarily stored in a\n\t// transient store. The `key` and its value will be deleted from the collection\n\t// when the transaction is validated and successfully committed.\n\tDelPrivateData(collection, key string) error\n\n\t// SetPrivateDataValidationParameter sets the key-level endorsement policy\n\t// for the private data specified by `key`.\n\tSetPrivateDataValidationParameter(collection, key string, ep []byte) error\n\n\t// GetPrivateDataValidationParameter retrieves the key-level endorsement\n\t// policy for the private data specified by `key`. Note that this introduces\n\t// a read dependency on `key` in the transaction's readset.\n\tGetPrivateDataValidationParameter(collection, key string) ([]byte, error)\n\n\t// GetPrivateDataByRange returns a range iterator over a set of keys in a\n\t// given private collection. The iterator can be used to iterate over all keys\n\t// between the startKey (inclusive) and endKey (exclusive).\n\t// The keys are returned by the iterator in lexical order. Note\n\t// that startKey and endKey can be empty string, which implies unbounded range\n\t// query on start or end.\n\t// Call Close() on the returned StateQueryIteratorInterface object when done.\n\t// The query is re-executed during validation phase to ensure result set\n\t// has not changed since transaction endorsement (phantom reads detected).\n\tGetPrivateDataByRange(collection, startKey, endKey string) (StateQueryIteratorInterface, error)\n\n\t// GetPrivateDataByPartialCompositeKey queries the state in a given private\n\t// collection based on a given partial composite key. This function returns\n\t// an iterator which can be used to iterate over all composite keys whose prefix\n\t// matches the given partial composite key. The `objectType` and attributes are\n\t// expected to have only valid utf8 strings and should not contain\n\t// U+0000 (nil byte) and U+10FFFF (biggest and unallocated code point).\n\t// See related functions SplitCompositeKey and CreateCompositeKey.\n\t// Call Close() on the returned StateQueryIteratorInterface object when done.\n\t// The query is re-executed during validation phase to ensure result set\n\t// has not changed since transaction endorsement (phantom reads detected).\n\tGetPrivateDataByPartialCompositeKey(collection, objectType string, keys []string) (StateQueryIteratorInterface, error)\n\n\t// GetPrivateDataQueryResult performs a \"rich\" query against a given private\n\t// collection. It is only supported for state databases that support rich query,\n\t// e.g.CouchDB. The query string is in the native syntax\n\t// of the underlying state database. An iterator is returned\n\t// which can be used to iterate (next) over the query result set.\n\t// The query is NOT re-executed during validation phase, phantom reads are\n\t// not detected. That is, other committed transactions may have added,\n\t// updated, or removed keys that impact the result set, and this would not\n\t// be detected at validation/commit time.  Applications susceptible to this\n\t// should therefore not use GetQueryResult as part of transactions that update\n\t// ledger, and should limit use to read-only chaincode operations.\n\tGetPrivateDataQueryResult(collection, query string) (StateQueryIteratorInterface, error)\n\n\t// GetCreator returns `SignatureHeader.Creator` (e.g. an identity)\n\t// of the `SignedProposal`. This is the identity of the agent (or user)\n\t// submitting the transaction.\n\tGetCreator() ([]byte, error)\n\n\t// GetTransient returns the `ChaincodeProposalPayload.Transient` field.\n\t// It is a map that contains data (e.g. cryptographic material)\n\t// that might be used to implement some form of application-level\n\t// confidentiality. The contents of this field, as prescribed by\n\t// `ChaincodeProposalPayload`, are supposed to always\n\t// be omitted from the transaction and excluded from the ledger.\n\tGetTransient() (map[string][]byte, error)\n\n\t// GetBinding returns the transaction binding, which is used to enforce a\n\t// link between application data (like those stored in the transient field\n\t// above) to the proposal itself. This is useful to avoid possible replay\n\t// attacks.\n\tGetBinding() ([]byte, error)\n\n\t// GetDecorations returns additional data (if applicable) about the proposal\n\t// that originated from the peer. This data is set by the decorators of the\n\t// peer, which append or mutate the chaincode input passed to the chaincode.\n\tGetDecorations() map[string][]byte\n\n\t// GetSignedProposal returns the SignedProposal object, which contains all\n\t// data elements part of a transaction proposal.\n\tGetSignedProposal() (*pb.SignedProposal, error)\n\n\t// GetTxTimestamp returns the timestamp when the transaction was created. This\n\t// is taken from the transaction ChannelHeader, therefore it will indicate the\n\t// client's timestamp and will have the same value across all endorsers.\n\tGetTxTimestamp() (*timestamp.Timestamp, error)\n\n\t// SetEvent allows the chaincode to set an event on the response to the\n\t// proposal to be included as part of a transaction. The event will be\n\t// available within the transaction in the committed block regardless of the\n\t// validity of the transaction.\n\tSetEvent(name string, payload []byte) error\n}\n```\nChaincodeStubInterface is used by deployable chaincode apps to access and modify their ledgers\n\n```go\ntype CommonIterator struct {\n\t// contains filtered or unexported fields\n}\n```\nCommonIterator documentation can be found in interfaces.go\n\n```go\nfunc (iter *CommonIterator) Close() error\n```\nClose documentation can be found in interfaces.go\n\n```go\nfunc (iter *CommonIterator) HasNext() bool\n```\nHasNext documentation can be found in interfaces.go\n\n```go\ntype CommonIteratorInterface interface {\n\t// HasNext returns true if the range query iterator contains additional keys\n\t// and values.\n\tHasNext() bool\n\n\t// Close closes the iterator. This should be called when done\n\t// reading from the iterator to free up resources.\n\tClose() error\n}\n```\nCommonIteratorInterface allows a chaincode to check whether any more result to be fetched from an iterator and close it when done.\n\n```go\ntype Handler struct {\n\t//need lock to protect chaincode from attempting\n\t//concurrent requests to the peer\n\tsync.Mutex\n\n\tTo         string\n\tChatStream PeerChaincodeStream\n\t// contains filtered or unexported fields\n}\n```\nHandler handler implementation for shim side of chaincode.\n\n```go\ntype HistoryQueryIterator struct {\n\t*CommonIterator\n}\n```\nHistoryQueryIterator documentation can be found in interfaces.go\n\n```go\nfunc (iter *HistoryQueryIterator) Next() (*queryresult.KeyModification, error)\n```\n\n```go\ntype HistoryQueryIteratorInterface interface {\n\t// Inherit HasNext() and Close()\n\tCommonIteratorInterface\n\n\t// Next returns the next key and value in the history query iterator.\n\tNext() (*queryresult.KeyModification, error)\n}\n```\nHistoryQueryIteratorInterface allows a chaincode to iterate over a set of key/value pairs returned by a history query.\n\n```go\ntype LoggingLevel logging.Level\n```\nLoggingLevel is an enumerated type of severity levels that control chaincode logging.\n\n```go\nfunc LogLevel(levelString string) (LoggingLevel, error)\n```\nLogLevel converts a case-insensitive string chosen from CRITICAL, ERROR, WARNING, NOTICE, INFO or DEBUG into an element of the LoggingLevel type. In the event of errors the level returned is LogError.\n\n```go\ntype MockQueryIteratorInterface interface {\n\tStateQueryIteratorInterface\n}\n```\nMockQueryIteratorInterface allows a chaincode to iterate over a set of key/value pairs returned by range query. TODO: Once the execute query and history query are implemented in MockStub, we need to update this interface\n\n```go\ntype MockStateRangeQueryIterator struct {\n\tClosed   bool\n\tStub     *MockStub\n\tStartKey string\n\tEndKey   string\n\tCurrent  *list.Element\n}\n```\n\n```go\nfunc NewMockStateRangeQueryIterator(stub *MockStub, startKey string, endKey string) *MockStateRangeQueryIterator\n```\n\n```go\nfunc (iter *MockStateRangeQueryIterator) Close() error\n```\nClose closes the range query iterator. This should be called when done reading from the iterator to free up resources.\n\n```go\nfunc (iter *MockStateRangeQueryIterator) HasNext() bool\n```\nHasNext returns true if the range query iterator contains additional keys and values.\n\n```go\nfunc (iter *MockStateRangeQueryIterator) Next() (*queryresult.KV, error)\n```\nNext returns the next key and value in the range query iterator.\n\n```go\nfunc (iter *MockStateRangeQueryIterator) Print()\n```\n\n```go\ntype MockStub struct {\n\n\t// A nice name that can be used for logging\n\tName string\n\n\t// State keeps name value pairs\n\tState map[string][]byte\n\n\t// Keys stores the list of mapped values in lexical order\n\tKeys *list.List\n\n\t// registered list of other MockStub chaincodes that can be called from this MockStub\n\tInvokables map[string]*MockStub\n\n\t// stores a transaction uuid while being Invoked / Deployed\n\t// TODO if a chaincode uses recursion this may need to be a stack of TxIDs or possibly a reference counting map\n\tTxID string\n\n\tTxTimestamp *timestamp.Timestamp\n\n\t// stores a channel ID of the proposal\n\tChannelID string\n\n\tPvtState map[string]map[string][]byte\n\n\t// stores per-key endorsement policy, first map index is the collection, second map index is the key\n\tEndorsementPolicies map[string]map[string][]byte\n\n\t// channel to store ChaincodeEvents\n\tChaincodeEventsChannel chan *pb.ChaincodeEvent\n\n\tDecorations map[string][]byte\n\t// contains filtered or unexported fields\n}\n```\nMockStub is an implementation of ChaincodeStubInterface for unit testing chaincode. Use this instead of ChaincodeStub in your chaincode's unit test calls to Init or Invoke.\n\n```go\nfunc NewMockStub(name string, cc Chaincode) *MockStub\n```\nConstructor to initialise the internal State map\n\n```go\nfunc (stub *MockStub) CreateCompositeKey(objectType string, attributes []string) (string, error)\n```\nCreateCompositeKey combines the list of attributes to form a composite key.\n\n```go\nfunc (stub *MockStub) DelPrivateData(collection string, key string) error\n```\n\n```go\nfunc (stub *MockStub) DelState(key string) error\n```\nDelState removes the specified \\`key\\` and its value from the ledger.\n\n```go\nfunc (stub *MockStub) GetArgs() [][]byte\n```\n\n```go\nfunc (stub *MockStub) GetArgsSlice() ([]byte, error)\n```\nNot implemented\n\n```go\nfunc (stub *MockStub) GetBinding() ([]byte, error)\n```\nNot implemented\n\n```go\nfunc (stub *MockStub) GetChannelID() string\n```\n\n```go\nfunc (stub *MockStub) GetCreator() ([]byte, error)\n```\nNot implemented\n\n```go\nfunc (stub *MockStub) GetDecorations() map[string][]byte\n```\n\n```go\nfunc (stub *MockStub) GetFunctionAndParameters() (function string, params []string)\n```\n\n```go\nfunc (stub *MockStub) GetHistoryForKey(key string) (HistoryQueryIteratorInterface, error)\n```\nGetHistoryForKey function can be invoked by a chaincode to return a history of key values across time. GetHistoryForKey is intended to be used for read-only queries.\n\n```go\nfunc (stub *MockStub) GetPrivateData(collection string, key string) ([]byte, error)\n```\n\n```go\nfunc (stub *MockStub) GetPrivateDataByPartialCompositeKey(collection, objectType string, attributes []string) (StateQueryIteratorInterface, error)\n```\n\n```go\nfunc (stub *MockStub) GetPrivateDataByRange(collection, startKey, endKey string) (StateQueryIteratorInterface, error)\n```\n\n```go\nfunc (stub *MockStub) GetPrivateDataHash(collection, key string) ([]byte, error)\n```\n\n```go\nfunc (stub *MockStub) GetPrivateDataQueryResult(collection, query string) (StateQueryIteratorInterface, error)\n```\n\n```go\nfunc (stub *MockStub) GetPrivateDataValidationParameter(collection, key string) ([]byte, error)\n```\n\n```go\nfunc (stub *MockStub) GetQueryResult(query string) (StateQueryIteratorInterface, error)\n```\nGetQueryResult function can be invoked by a chaincode to perform a rich query against state database.  Only supported by state database implementations that support rich query.  The query string is in the syntax of the underlying state database. An iterator is returned which can be used to iterate (next) over the query result set\n\n```go\nfunc (stub *MockStub) GetQueryResultWithPagination(query string, pageSize int32,\n\tbookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)\n```\n\n```go\nfunc (stub *MockStub) GetSignedProposal() (*pb.SignedProposal, error)\n```\nNot implemented\n\n```go\nfunc (stub *MockStub) GetState(key string) ([]byte, error)\n```\nGetState retrieves the value for a given key from the ledger\n\n```go\nfunc (stub *MockStub) GetStateByPartialCompositeKey(objectType string, attributes []string) (StateQueryIteratorInterface, error)\n```\nGetStateByPartialCompositeKey function can be invoked by a chaincode to query the state based on a given partial composite key. This function returns an iterator which can be used to iterate over all composite keys whose prefix matches the given partial composite key. This function should be used only for a partial composite key. For a full composite key, an iter with empty response would be returned.\n\n```go\nfunc (stub *MockStub) GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string,\n\tpageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)\n```\n\n```go\nfunc (stub *MockStub) GetStateByRange(startKey, endKey string) (StateQueryIteratorInterface, error)\n```\n\n```go\nfunc (stub *MockStub) GetStateByRangeWithPagination(startKey, endKey string, pageSize int32,\n\tbookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)\n```\n\n```go\nfunc (stub *MockStub) GetStateValidationParameter(key string) ([]byte, error)\n```\n\n```go\nfunc (stub *MockStub) GetStringArgs() []string\n```\n\n```go\nfunc (stub *MockStub) GetTransient() (map[string][]byte, error)\n```\nNot implemented\n\n```go\nfunc (stub *MockStub) GetTxID() string\n```\n\n```go\nfunc (stub *MockStub) GetTxTimestamp() (*timestamp.Timestamp, error)\n```\n\n```go\nfunc (stub *MockStub) InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response\n```\nInvokeChaincode calls a peered chaincode. E.g. stub1.InvokeChaincode(\"stub2Hash\", funcArgs, channel) Before calling this make sure to create another MockStub stub2, call stub2.MockInit(uuid, func, args) and register it with stub1 by calling stub1.MockPeerChaincode(\"stub2Hash\", stub2)\n\n```go\nfunc (stub *MockStub) MockInit(uuid string, args [][]byte) pb.Response\n```\nInitialise this chaincode,  also starts and ends a transaction.\n\n```go\nfunc (stub *MockStub) MockInvoke(uuid string, args [][]byte) pb.Response\n```\nInvoke this chaincode, also starts and ends a transaction.\n\n```go\nfunc (stub *MockStub) MockInvokeWithSignedProposal(uuid string, args [][]byte, sp *pb.SignedProposal) pb.Response\n```\nInvoke this chaincode, also starts and ends a transaction.\n\n```go\nfunc (stub *MockStub) MockPeerChaincode(invokableChaincodeName string, otherStub *MockStub)\n```\nRegister a peer chaincode with this MockStub invokableChaincodeName is the name or hash of the peer otherStub is a MockStub of the peer, already intialised\n\n```go\nfunc (stub *MockStub) MockTransactionEnd(uuid string)\n```\nEnd a mocked transaction, clearing the UUID.\n\n```go\nfunc (stub *MockStub) MockTransactionStart(txid string)\n```\nUsed to indicate to a chaincode that it is part of a transaction. This is important when chaincodes invoke each other. MockStub doesn't support concurrent transactions at present.\n\n```go\nfunc (stub *MockStub) PutPrivateData(collection string, key string, value []byte) error\n```\n\n```go\nfunc (stub *MockStub) PutState(key string, value []byte) error\n```\nPutState writes the specified \\`value\\` and \\`key\\` into the ledger.\n\n```go\nfunc (stub *MockStub) SetEvent(name string, payload []byte) error\n```\n\n```go\nfunc (stub *MockStub) SetPrivateDataValidationParameter(collection, key string, ep []byte) error\n```\n\n```go\nfunc (stub *MockStub) SetStateValidationParameter(key string, ep []byte) error\n```\n\n```go\nfunc (stub *MockStub) SplitCompositeKey(compositeKey string) (string, []string, error)\n```\nSplitCompositeKey splits the composite key into attributes on which the composite key was formed.\n\n```go\ntype PeerChaincodeStream interface {\n\tSend(*pb.ChaincodeMessage) error\n\tRecv() (*pb.ChaincodeMessage, error)\n\tCloseSend() error\n}\n```\nPeerChaincodeStream interface for stream between Peer and chaincode instance.\n\n```go\ntype SendPanicFailure string\n```\nSendPanicFailure\n\n```go\nfunc (e SendPanicFailure) Error() string\n```\n\n```go\ntype StateQueryIterator struct {\n\t*CommonIterator\n}\n```\nStateQueryIterator documentation can be found in interfaces.go\n\n```go\nfunc (iter *StateQueryIterator) Next() (*queryresult.KV, error)\n```\n\n```go\ntype StateQueryIteratorInterface interface {\n\t// Inherit HasNext() and Close()\n\tCommonIteratorInterface\n\n\t// Next returns the next key and value in the range and execute query iterator.\n\tNext() (*queryresult.KV, error)\n}\n```\nStateQueryIteratorInterface allows a chaincode to iterate over a set of key/value pairs returned by range and execute query.\n\n","path":"https-1xa.pages.dev/hyperledger/fabric/core/chaincode/shim","name":"shim","synopsis":"Package shim provides APIs for the chaincode to access its state variables, transaction context and call other chaincodes.","isRedistributable":true}
