Documentation ¶
Overview ¶
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
Package shim provides APIs for the chaincode to access its state variables, transaction context and call other chaincodes.
Package shim provides APIs for the chaincode to access its state variables, transaction context and call other chaincodes.
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
Index ¶
- Constants
- func Error(msg string) pb.Response
- func IsEnabledForLogLevel(logLevel string) bool
- func SetLoggingLevel(level LoggingLevel)
- func SetupChaincodeLogging()
- func Start(cc Chaincode) error
- func StartInProc(env []string, args []string, cc Chaincode, recv <-chan *pb.ChaincodeMessage, ...) error
- func Success(payload []byte) pb.Response
- type Chaincode
- type ChaincodeLogger
- func (c *ChaincodeLogger) Critical(args ...interface{})
- func (c *ChaincodeLogger) Criticalf(format string, args ...interface{})
- func (c *ChaincodeLogger) Debug(args ...interface{})
- func (c *ChaincodeLogger) Debugf(format string, args ...interface{})
- func (c *ChaincodeLogger) Error(args ...interface{})
- func (c *ChaincodeLogger) Errorf(format string, args ...interface{})
- func (c *ChaincodeLogger) Info(args ...interface{})
- func (c *ChaincodeLogger) Infof(format string, args ...interface{})
- func (c *ChaincodeLogger) IsEnabledFor(level LoggingLevel) bool
- func (c *ChaincodeLogger) Notice(args ...interface{})
- func (c *ChaincodeLogger) Noticef(format string, args ...interface{})
- func (c *ChaincodeLogger) SetLevel(level LoggingLevel)
- func (c *ChaincodeLogger) Warning(args ...interface{})
- func (c *ChaincodeLogger) Warningf(format string, args ...interface{})
- type ChaincodeStub
- func (s *ChaincodeStub) CreateCompositeKey(objectType string, attributes []string) (string, error)
- func (s *ChaincodeStub) DelPrivateData(collection string, key string) error
- func (s *ChaincodeStub) DelState(key string) error
- func (s *ChaincodeStub) GetArgs() [][]byte
- func (s *ChaincodeStub) GetArgsSlice() ([]byte, error)
- func (s *ChaincodeStub) GetBinding() ([]byte, error)
- func (s *ChaincodeStub) GetChannelID() string
- func (s *ChaincodeStub) GetCreator() ([]byte, error)
- func (s *ChaincodeStub) GetDecorations() map[string][]byte
- func (s *ChaincodeStub) GetFunctionAndParameters() (function string, params []string)
- func (s *ChaincodeStub) GetHistoryForKey(key string) (HistoryQueryIteratorInterface, error)
- func (s *ChaincodeStub) GetPrivateData(collection string, key string) ([]byte, error)
- func (s *ChaincodeStub) GetPrivateDataByPartialCompositeKey(collection, objectType string, attributes []string) (StateQueryIteratorInterface, error)
- func (s *ChaincodeStub) GetPrivateDataByRange(collection, startKey, endKey string) (StateQueryIteratorInterface, error)
- func (s *ChaincodeStub) GetPrivateDataHash(collection string, key string) ([]byte, error)
- func (s *ChaincodeStub) GetPrivateDataQueryResult(collection, query string) (StateQueryIteratorInterface, error)
- func (s *ChaincodeStub) GetPrivateDataValidationParameter(collection, key string) ([]byte, error)
- func (s *ChaincodeStub) GetQueryResult(query string) (StateQueryIteratorInterface, error)
- func (s *ChaincodeStub) GetQueryResultWithPagination(query string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
- func (s *ChaincodeStub) GetSignedProposal() (*pb.SignedProposal, error)
- func (s *ChaincodeStub) GetState(key string) ([]byte, error)
- func (s *ChaincodeStub) GetStateByPartialCompositeKey(objectType string, attributes []string) (StateQueryIteratorInterface, error)
- func (s *ChaincodeStub) GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
- func (s *ChaincodeStub) GetStateByRange(startKey, endKey string) (StateQueryIteratorInterface, error)
- func (s *ChaincodeStub) GetStateByRangeWithPagination(startKey, endKey string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
- func (s *ChaincodeStub) GetStateValidationParameter(key string) ([]byte, error)
- func (s *ChaincodeStub) GetStringArgs() []string
- func (s *ChaincodeStub) GetTransient() (map[string][]byte, error)
- func (s *ChaincodeStub) GetTxID() string
- func (s *ChaincodeStub) GetTxTimestamp() (*timestamp.Timestamp, error)
- func (s *ChaincodeStub) InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response
- func (s *ChaincodeStub) PutPrivateData(collection string, key string, value []byte) error
- func (s *ChaincodeStub) PutState(key string, value []byte) error
- func (s *ChaincodeStub) SetEvent(name string, payload []byte) error
- func (s *ChaincodeStub) SetPrivateDataValidationParameter(collection, key string, ep []byte) error
- func (s *ChaincodeStub) SetStateValidationParameter(key string, ep []byte) error
- func (s *ChaincodeStub) SplitCompositeKey(compositeKey string) (string, []string, error)
- type ChaincodeStubInterface
- type CommonIterator
- type CommonIteratorInterface
- type Handler
- type HistoryQueryIterator
- type HistoryQueryIteratorInterface
- type LoggingLevel
- type MockQueryIteratorInterface
- type MockStateRangeQueryIterator
- type MockStub
- func (stub *MockStub) CreateCompositeKey(objectType string, attributes []string) (string, error)
- func (stub *MockStub) DelPrivateData(collection string, key string) error
- func (stub *MockStub) DelState(key string) error
- func (stub *MockStub) GetArgs() [][]byte
- func (stub *MockStub) GetArgsSlice() ([]byte, error)
- func (stub *MockStub) GetBinding() ([]byte, error)
- func (stub *MockStub) GetChannelID() string
- func (stub *MockStub) GetCreator() ([]byte, error)
- func (stub *MockStub) GetDecorations() map[string][]byte
- func (stub *MockStub) GetFunctionAndParameters() (function string, params []string)
- func (stub *MockStub) GetHistoryForKey(key string) (HistoryQueryIteratorInterface, error)
- func (stub *MockStub) GetPrivateData(collection string, key string) ([]byte, error)
- func (stub *MockStub) GetPrivateDataByPartialCompositeKey(collection, objectType string, attributes []string) (StateQueryIteratorInterface, error)
- func (stub *MockStub) GetPrivateDataByRange(collection, startKey, endKey string) (StateQueryIteratorInterface, error)
- func (stub *MockStub) GetPrivateDataHash(collection, key string) ([]byte, error)
- func (stub *MockStub) GetPrivateDataQueryResult(collection, query string) (StateQueryIteratorInterface, error)
- func (stub *MockStub) GetPrivateDataValidationParameter(collection, key string) ([]byte, error)
- func (stub *MockStub) GetQueryResult(query string) (StateQueryIteratorInterface, error)
- func (stub *MockStub) GetQueryResultWithPagination(query string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
- func (stub *MockStub) GetSignedProposal() (*pb.SignedProposal, error)
- func (stub *MockStub) GetState(key string) ([]byte, error)
- func (stub *MockStub) GetStateByPartialCompositeKey(objectType string, attributes []string) (StateQueryIteratorInterface, error)
- func (stub *MockStub) GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
- func (stub *MockStub) GetStateByRange(startKey, endKey string) (StateQueryIteratorInterface, error)
- func (stub *MockStub) GetStateByRangeWithPagination(startKey, endKey string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
- func (stub *MockStub) GetStateValidationParameter(key string) ([]byte, error)
- func (stub *MockStub) GetStringArgs() []string
- func (stub *MockStub) GetTransient() (map[string][]byte, error)
- func (stub *MockStub) GetTxID() string
- func (stub *MockStub) GetTxTimestamp() (*timestamp.Timestamp, error)
- func (stub *MockStub) InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response
- func (stub *MockStub) MockInit(uuid string, args [][]byte) pb.Response
- func (stub *MockStub) MockInvoke(uuid string, args [][]byte) pb.Response
- func (stub *MockStub) MockInvokeWithSignedProposal(uuid string, args [][]byte, sp *pb.SignedProposal) pb.Response
- func (stub *MockStub) MockPeerChaincode(invokableChaincodeName string, otherStub *MockStub, channel string)
- func (stub *MockStub) MockTransactionEnd(uuid string)
- func (stub *MockStub) MockTransactionStart(txid string)
- func (stub *MockStub) PutPrivateData(collection string, key string, value []byte) error
- func (stub *MockStub) PutState(key string, value []byte) error
- func (stub *MockStub) SetEvent(name string, payload []byte) error
- func (stub *MockStub) SetPrivateDataValidationParameter(collection, key string, ep []byte) error
- func (stub *MockStub) SetStateValidationParameter(key string, ep []byte) error
- func (stub *MockStub) SplitCompositeKey(compositeKey string) (string, []string, error)
- type PeerChaincodeStream
- type SendPanicFailure
- type StateQueryIterator
- type StateQueryIteratorInterface
Constants ¶
const ( LogDebug = LoggingLevel(logging.DEBUG) LogInfo = LoggingLevel(logging.INFO) LogNotice = LoggingLevel(logging.NOTICE) LogWarning = LoggingLevel(logging.WARNING) LogError = LoggingLevel(logging.ERROR) LogCritical = LoggingLevel(logging.CRITICAL) )
These constants comprise the LoggingLevel enumeration
const ( // OK constant - status code less than 400, endorser will endorse it. // OK means init or invoke successfully. OK = 200 // ERRORTHRESHOLD constant - status code greater than or equal to 400 will be considered an error and rejected by endorser. ERRORTHRESHOLD = 400 // ERROR constant - default error value ERROR = 500 )
const ( STATE_QUERY_RESULT resultType = iota + 1 HISTORY_QUERY_RESULT )
Variables ¶
This section is empty.
Functions ¶
func IsEnabledForLogLevel ¶
IsEnabledForLogLevel checks to see if the chaincodeLogger is enabled for a specific logging level used primarily for testing
func SetLoggingLevel ¶
func SetLoggingLevel(level LoggingLevel)
SetLoggingLevel allows a Go language chaincode to set the logging level of its shim.
func SetupChaincodeLogging ¶
func SetupChaincodeLogging()
SetupChaincodeLogging 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
func StartInProc ¶
func StartInProc(env []string, args []string, cc Chaincode, recv <-chan *pb.ChaincodeMessage, send chan<- *pb.ChaincodeMessage) error
StartInProc is an entry point for system chaincodes bootstrap. It is not an API for chaincodes.
Types ¶
type Chaincode ¶
type Chaincode interface { // Init is called during Instantiate transaction after the chaincode container // has been established for the first time, allowing the chaincode to // initialize its internal data Init(stub ChaincodeStubInterface) pb.Response // Invoke is called to update or query the ledger in a proposal transaction. // Updated state variables are not committed to the ledger until the // transaction is committed. Invoke(stub ChaincodeStubInterface) pb.Response }
Chaincode interface must be implemented by all chaincodes. The fabric runs the transactions by calling these functions as specified.
type ChaincodeLogger ¶
type ChaincodeLogger struct {
// contains filtered or unexported fields
}
ChaincodeLogger is an abstraction of a logging object for use by chaincodes. These objects are created by the NewLogger API.
func NewLogger ¶
func NewLogger(name string) *ChaincodeLogger
NewLogger 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.
func (*ChaincodeLogger) Critical ¶
func (c *ChaincodeLogger) Critical(args ...interface{})
Critical logs always appear; They can not be disabled.
func (*ChaincodeLogger) Criticalf ¶
func (c *ChaincodeLogger) Criticalf(format string, args ...interface{})
Criticalf logs always appear; They can not be disabled.
func (*ChaincodeLogger) Debug ¶
func (c *ChaincodeLogger) Debug(args ...interface{})
Debug logs will only appear if the ChaincodeLogger LoggingLevel is set to LogDebug.
func (*ChaincodeLogger) Debugf ¶
func (c *ChaincodeLogger) Debugf(format string, args ...interface{})
Debugf logs will only appear if the ChaincodeLogger LoggingLevel is set to LogDebug.
func (*ChaincodeLogger) Error ¶
func (c *ChaincodeLogger) Error(args ...interface{})
Error logs will appear if the ChaincodeLogger LoggingLevel is set to LogError, LogWarning, LogNotice, LogInfo or LogDebug.
func (*ChaincodeLogger) Errorf ¶
func (c *ChaincodeLogger) Errorf(format string, args ...interface{})
Errorf logs will appear if the ChaincodeLogger LoggingLevel is set to LogError, LogWarning, LogNotice, LogInfo or LogDebug.
func (*ChaincodeLogger) Info ¶
func (c *ChaincodeLogger) Info(args ...interface{})
Info logs will appear if the ChaincodeLogger LoggingLevel is set to LogInfo or LogDebug.
func (*ChaincodeLogger) Infof ¶
func (c *ChaincodeLogger) Infof(format string, args ...interface{})
Infof logs will appear if the ChaincodeLogger LoggingLevel is set to LogInfo or LogDebug.
func (*ChaincodeLogger) IsEnabledFor ¶
func (c *ChaincodeLogger) IsEnabledFor(level LoggingLevel) bool
IsEnabledFor returns true if the logger is enabled to creates logs at the given logging level.
func (*ChaincodeLogger) Notice ¶
func (c *ChaincodeLogger) Notice(args ...interface{})
Notice logs will appear if the ChaincodeLogger LoggingLevel is set to LogNotice, LogInfo or LogDebug.
func (*ChaincodeLogger) Noticef ¶
func (c *ChaincodeLogger) Noticef(format string, args ...interface{})
Noticef logs will appear if the ChaincodeLogger LoggingLevel is set to LogNotice, LogInfo or LogDebug.
func (*ChaincodeLogger) SetLevel ¶
func (c *ChaincodeLogger) SetLevel(level LoggingLevel)
SetLevel 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".
func (*ChaincodeLogger) Warning ¶
func (c *ChaincodeLogger) Warning(args ...interface{})
Warning logs will appear if the ChaincodeLogger LoggingLevel is set to LogWarning, LogNotice, LogInfo or LogDebug.
func (*ChaincodeLogger) Warningf ¶
func (c *ChaincodeLogger) Warningf(format string, args ...interface{})
Warningf logs will appear if the ChaincodeLogger LoggingLevel is set to LogWarning, LogNotice, LogInfo or LogDebug.
type ChaincodeStub ¶
type ChaincodeStub struct { TxID string ChannelId string // contains filtered or unexported fields }
ChaincodeStub is an object passed to chaincode for shim side handling of APIs.
func (*ChaincodeStub) CreateCompositeKey ¶
func (s *ChaincodeStub) CreateCompositeKey(objectType string, attributes []string) (string, error)
CreateCompositeKey documentation can be found in interfaces.go
func (*ChaincodeStub) DelPrivateData ¶ added in v1.2.0
func (s *ChaincodeStub) DelPrivateData(collection string, key string) error
DelPrivateData documentation can be found in interfaces.go
func (*ChaincodeStub) DelState ¶
func (s *ChaincodeStub) DelState(key string) error
DelState documentation can be found in interfaces.go
func (*ChaincodeStub) GetArgs ¶
func (s *ChaincodeStub) GetArgs() [][]byte
GetArgs documentation can be found in interfaces.go
func (*ChaincodeStub) GetArgsSlice ¶
func (s *ChaincodeStub) GetArgsSlice() ([]byte, error)
GetArgsSlice documentation can be found in interfaces.go
func (*ChaincodeStub) GetBinding ¶
func (s *ChaincodeStub) GetBinding() ([]byte, error)
GetBinding documentation can be found in interfaces.go
func (*ChaincodeStub) GetChannelID ¶ added in v1.1.0
func (s *ChaincodeStub) GetChannelID() string
GetChannelID returns the channel for the proposal
func (*ChaincodeStub) GetCreator ¶
func (s *ChaincodeStub) GetCreator() ([]byte, error)
GetCreator documentation can be found in interfaces.go
func (*ChaincodeStub) GetDecorations ¶ added in v1.1.0
func (s *ChaincodeStub) GetDecorations() map[string][]byte
func (*ChaincodeStub) GetFunctionAndParameters ¶
func (s *ChaincodeStub) GetFunctionAndParameters() (function string, params []string)
GetFunctionAndParameters documentation can be found in interfaces.go
func (*ChaincodeStub) GetHistoryForKey ¶
func (s *ChaincodeStub) GetHistoryForKey(key string) (HistoryQueryIteratorInterface, error)
GetHistoryForKey documentation can be found in interfaces.go
func (*ChaincodeStub) GetPrivateData ¶ added in v1.2.0
func (s *ChaincodeStub) GetPrivateData(collection string, key string) ([]byte, error)
GetPrivateData documentation can be found in interfaces.go
func (*ChaincodeStub) GetPrivateDataByPartialCompositeKey ¶ added in v1.2.0
func (s *ChaincodeStub) GetPrivateDataByPartialCompositeKey(collection, objectType string, attributes []string) (StateQueryIteratorInterface, error)
GetPrivateDataByPartialCompositeKey documentation can be found in interfaces.go
func (*ChaincodeStub) GetPrivateDataByRange ¶ added in v1.2.0
func (s *ChaincodeStub) GetPrivateDataByRange(collection, startKey, endKey string) (StateQueryIteratorInterface, error)
GetPrivateDataByRange documentation can be found in interfaces.go
func (*ChaincodeStub) GetPrivateDataHash ¶
func (s *ChaincodeStub) GetPrivateDataHash(collection string, key string) ([]byte, error)
GetPrivateDataHash documentation can be found in interfaces.go
func (*ChaincodeStub) GetPrivateDataQueryResult ¶ added in v1.2.0
func (s *ChaincodeStub) GetPrivateDataQueryResult(collection, query string) (StateQueryIteratorInterface, error)
GetPrivateDataQueryResult documentation can be found in interfaces.go
func (*ChaincodeStub) GetPrivateDataValidationParameter ¶ added in v1.3.0
func (s *ChaincodeStub) GetPrivateDataValidationParameter(collection, key string) ([]byte, error)
GetPrivateDataValidationParameter documentation can be found in interfaces.go
func (*ChaincodeStub) GetQueryResult ¶
func (s *ChaincodeStub) GetQueryResult(query string) (StateQueryIteratorInterface, error)
GetQueryResult documentation can be found in interfaces.go
func (*ChaincodeStub) GetQueryResultWithPagination ¶ added in v1.3.0
func (s *ChaincodeStub) GetQueryResultWithPagination(query string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
func (*ChaincodeStub) GetSignedProposal ¶
func (s *ChaincodeStub) GetSignedProposal() (*pb.SignedProposal, error)
GetSignedProposal documentation can be found in interfaces.go
func (*ChaincodeStub) GetState ¶
func (s *ChaincodeStub) GetState(key string) ([]byte, error)
GetState documentation can be found in interfaces.go
func (*ChaincodeStub) GetStateByPartialCompositeKey ¶
func (s *ChaincodeStub) GetStateByPartialCompositeKey(objectType string, attributes []string) (StateQueryIteratorInterface, error)
GetStateByPartialCompositeKey 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.
func (*ChaincodeStub) GetStateByPartialCompositeKeyWithPagination ¶ added in v1.3.0
func (s *ChaincodeStub) GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
func (*ChaincodeStub) GetStateByRange ¶
func (s *ChaincodeStub) GetStateByRange(startKey, endKey string) (StateQueryIteratorInterface, error)
GetStateByRange documentation can be found in interfaces.go
func (*ChaincodeStub) GetStateByRangeWithPagination ¶ added in v1.3.0
func (s *ChaincodeStub) GetStateByRangeWithPagination(startKey, endKey string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
func (*ChaincodeStub) GetStateValidationParameter ¶ added in v1.3.0
func (s *ChaincodeStub) GetStateValidationParameter(key string) ([]byte, error)
GetStateValidationParameter documentation can be found in interfaces.go
func (*ChaincodeStub) GetStringArgs ¶
func (s *ChaincodeStub) GetStringArgs() []string
GetStringArgs documentation can be found in interfaces.go
func (*ChaincodeStub) GetTransient ¶
func (s *ChaincodeStub) GetTransient() (map[string][]byte, error)
GetTransient documentation can be found in interfaces.go
func (*ChaincodeStub) GetTxID ¶
func (s *ChaincodeStub) GetTxID() string
GetTxID returns the transaction ID for the proposal
func (*ChaincodeStub) GetTxTimestamp ¶
func (s *ChaincodeStub) GetTxTimestamp() (*timestamp.Timestamp, error)
GetTxTimestamp documentation can be found in interfaces.go
func (*ChaincodeStub) InvokeChaincode ¶
func (s *ChaincodeStub) InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response
InvokeChaincode documentation can be found in interfaces.go
func (*ChaincodeStub) PutPrivateData ¶ added in v1.2.0
func (s *ChaincodeStub) PutPrivateData(collection string, key string, value []byte) error
PutPrivateData documentation can be found in interfaces.go
func (*ChaincodeStub) PutState ¶
func (s *ChaincodeStub) PutState(key string, value []byte) error
PutState documentation can be found in interfaces.go
func (*ChaincodeStub) SetEvent ¶
func (s *ChaincodeStub) SetEvent(name string, payload []byte) error
SetEvent documentation can be found in interfaces.go
func (*ChaincodeStub) SetPrivateDataValidationParameter ¶ added in v1.3.0
func (s *ChaincodeStub) SetPrivateDataValidationParameter(collection, key string, ep []byte) error
SetPrivateDataValidationParameter documentation can be found in interfaces.go
func (*ChaincodeStub) SetStateValidationParameter ¶ added in v1.3.0
func (s *ChaincodeStub) SetStateValidationParameter(key string, ep []byte) error
SetStateValidationParameter documentation can be found in interfaces.go
func (*ChaincodeStub) SplitCompositeKey ¶
func (s *ChaincodeStub) SplitCompositeKey(compositeKey string) (string, []string, error)
SplitCompositeKey documentation can be found in interfaces.go
type ChaincodeStubInterface ¶
type ChaincodeStubInterface interface { // GetArgs returns the arguments intended for the chaincode Init and Invoke // as an array of byte arrays. GetArgs() [][]byte // GetStringArgs returns the arguments intended for the chaincode Init and // Invoke as a string array. Only use GetStringArgs if the client passes // arguments intended to be used as strings. GetStringArgs() []string // GetFunctionAndParameters returns the first argument as the function // name and the rest of the arguments as parameters in a string array. // Only use GetFunctionAndParameters if the client passes arguments intended // to be used as strings. GetFunctionAndParameters() (string, []string) // GetArgsSlice returns the arguments intended for the chaincode Init and // Invoke as a byte array GetArgsSlice() ([]byte, error) // GetTxID returns the tx_id of the transaction proposal, which is unique per // transaction and per client. See ChannelHeader in protos/common/common.proto // for further details. GetTxID() string // GetChannelID returns the channel the proposal is sent to for chaincode to process. // This would be the channel_id of the transaction proposal (see ChannelHeader // in protos/common/common.proto) except where the chaincode is calling another on // a different channel GetChannelID() string // InvokeChaincode locally calls the specified chaincode `Invoke` using the // same transaction context; that is, chaincode calling chaincode doesn't // create a new transaction message. // If the called chaincode is on the same channel, it simply adds the called // chaincode read set and write set to the calling transaction. // If the called chaincode is on a different channel, // only the Response is returned to the calling chaincode; any PutState calls // from the called chaincode will not have any effect on the ledger; that is, // the called chaincode on a different channel will not have its read set // and write set applied to the transaction. Only the calling chaincode's // read set and write set will be applied to the transaction. Effectively // the called chaincode on a different channel is a `Query`, which does not // participate in state validation checks in subsequent commit phase. // If `channel` is empty, the caller's channel is assumed. InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response // GetState returns the value of the specified `key` from the // ledger. Note that GetState doesn't read data from the writeset, which // has not been committed to the ledger. In other words, GetState doesn't // consider data modified by PutState that has not been committed. // If the key does not exist in the state database, (nil, nil) is returned. GetState(key string) ([]byte, error) // PutState puts the specified `key` and `value` into the transaction's // writeset as a data-write proposal. PutState doesn't effect the ledger // until the transaction is validated and successfully committed. // Simple keys must not be an empty string and must not start with null // character (0x00), in order to avoid range query collisions with // composite keys, which internally get prefixed with 0x00 as composite // key namespace. PutState(key string, value []byte) error // DelState records the specified `key` to be deleted in the writeset of // the transaction proposal. The `key` and its value will be deleted from // the ledger when the transaction is validated and successfully committed. DelState(key string) error // SetStateValidationParameter sets the key-level endorsement policy for `key`. SetStateValidationParameter(key string, ep []byte) error // GetStateValidationParameter retrieves the key-level endorsement policy // for `key`. Note that this will introduce a read dependency on `key` in // the transaction's readset. GetStateValidationParameter(key string) ([]byte, error) // GetStateByRange returns a range iterator over a set of keys in the // ledger. The iterator can be used to iterate over all keys // between the startKey (inclusive) and endKey (exclusive). // However, if the number of keys between startKey and endKey is greater than the // totalQueryLimit (defined in core.yaml), this iterator cannot be used // to fetch all keys (results will be capped by the totalQueryLimit). // The keys are returned by the iterator in lexical order. Note // that startKey and endKey can be empty string, which implies unbounded range // query on start or end. // Call Close() on the returned StateQueryIteratorInterface object when done. // The query is re-executed during validation phase to ensure result set // has not changed since transaction endorsement (phantom reads detected). GetStateByRange(startKey, endKey string) (StateQueryIteratorInterface, error) // GetStateByRangeWithPagination returns a range iterator over a set of keys in the // ledger. The iterator can be used to fetch keys between the startKey (inclusive) // and endKey (exclusive). // When an empty string is passed as a value to the bookmark argument, the returned // iterator can be used to fetch the first `pageSize` keys between the startKey // (inclusive) and endKey (exclusive). // When the bookmark is a non-emptry string, the iterator can be used to fetch // the first `pageSize` keys between the bookmark (inclusive) and endKey (exclusive). // Note that only the bookmark present in a prior page of query results (ResponseMetadata) // can be used as a value to the bookmark argument. Otherwise, an empty string must // be passed as bookmark. // The keys are returned by the iterator in lexical order. Note // that startKey and endKey can be empty string, which implies unbounded range // query on start or end. // Call Close() on the returned StateQueryIteratorInterface object when done. // This call is only supported in a read only transaction. GetStateByRangeWithPagination(startKey, endKey string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error) // GetStateByPartialCompositeKey queries the state in the ledger 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. However, if the number of matching composite // keys is greater than the totalQueryLimit (defined in core.yaml), this iterator // cannot be used to fetch all matching keys (results will be limited by the totalQueryLimit). // The `objectType` and attributes are expected to have only valid utf8 strings and // should not contain U+0000 (nil byte) and U+10FFFF (biggest and unallocated code point). // See related functions SplitCompositeKey and CreateCompositeKey. // Call Close() on the returned StateQueryIteratorInterface object when done. // The query is re-executed during validation phase to ensure result set // has not changed since transaction endorsement (phantom reads detected). GetStateByPartialCompositeKey(objectType string, keys []string) (StateQueryIteratorInterface, error) // GetStateByPartialCompositeKeyWithPagination queries the state in the ledger based on // a given partial composite key. This function returns an iterator // which can be used to iterate over the composite keys whose // prefix matches the given partial composite key. // When an empty string is passed as a value to the bookmark argument, the returned // iterator can be used to fetch the first `pageSize` composite keys whose prefix // matches the given partial composite key. // When the bookmark is a non-emptry string, the iterator can be used to fetch // the first `pageSize` keys between the bookmark (inclusive) and the last matching // composite key. // Note that only the bookmark present in a prior page of query result (ResponseMetadata) // can be used as a value to the bookmark argument. Otherwise, an empty string must // be passed as bookmark. // The `objectType` and attributes are expected to have only valid utf8 strings // and should not contain U+0000 (nil byte) and U+10FFFF (biggest and unallocated // code point). See related functions SplitCompositeKey and CreateCompositeKey. // Call Close() on the returned StateQueryIteratorInterface object when done. // This call is only supported in a read only transaction. GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error) // CreateCompositeKey combines the given `attributes` to form a composite // key. The objectType and attributes are expected to have only valid utf8 // strings and should not contain U+0000 (nil byte) and U+10FFFF // (biggest and unallocated code point). // The resulting composite key can be used as the key in PutState(). CreateCompositeKey(objectType string, attributes []string) (string, error) // SplitCompositeKey splits the specified key into attributes on which the // composite key was formed. Composite keys found during range queries // or partial composite key queries can therefore be split into their // composite parts. SplitCompositeKey(compositeKey string) (string, []string, error) // GetQueryResult performs a "rich" query against a state database. It is // only supported for state databases that support rich query, // e.g.CouchDB. The query string is in the native syntax // of the underlying state database. An iterator is returned // which can be used to iterate over all keys in the query result set. // However, if the number of keys in the query result set is greater than the // totalQueryLimit (defined in core.yaml), this iterator cannot be used // to fetch all keys in the query result set (results will be limited by // the totalQueryLimit). // The query is NOT re-executed during validation phase, phantom reads are // not detected. That is, other committed transactions may have added, // updated, or removed keys that impact the result set, and this would not // be detected at validation/commit time. Applications susceptible to this // should therefore not use GetQueryResult as part of transactions that update // ledger, and should limit use to read-only chaincode operations. GetQueryResult(query string) (StateQueryIteratorInterface, error) // GetQueryResultWithPagination performs a "rich" query against a state database. // It is only supported for state databases that support rich query, // e.g., CouchDB. The query string is in the native syntax // of the underlying state database. An iterator is returned // which can be used to iterate over keys in the query result set. // When an empty string is passed as a value to the bookmark argument, the returned // iterator can be used to fetch the first `pageSize` of query results. // When the bookmark is a non-emptry string, the iterator can be used to fetch // the first `pageSize` keys between the bookmark and the last key in the query result. // Note that only the bookmark present in a prior page of query results (ResponseMetadata) // can be used as a value to the bookmark argument. Otherwise, an empty string // must be passed as bookmark. // This call is only supported in a read only transaction. GetQueryResultWithPagination(query string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error) // GetHistoryForKey returns a history of key values across time. // For each historic key update, the historic value and associated // transaction id and timestamp are returned. The timestamp is the // timestamp provided by the client in the proposal header. // GetHistoryForKey requires peer configuration // core.ledger.history.enableHistoryDatabase to be true. // The query is NOT re-executed during validation phase, phantom reads are // not detected. That is, other committed transactions may have updated // the key concurrently, impacting the result set, and this would not be // detected at validation/commit time. Applications susceptible to this // should therefore not use GetHistoryForKey as part of transactions that // update ledger, and should limit use to read-only chaincode operations. GetHistoryForKey(key string) (HistoryQueryIteratorInterface, error) // GetPrivateData returns the value of the specified `key` from the specified // `collection`. Note that GetPrivateData doesn't read data from the // private writeset, which has not been committed to the `collection`. In // other words, GetPrivateData doesn't consider data modified by PutPrivateData // that has not been committed. GetPrivateData(collection, key string) ([]byte, error) // GetPrivateDataHash returns the hash of the value of the specified `key` from the specified // `collection` GetPrivateDataHash(collection, key string) ([]byte, error) // PutPrivateData puts the specified `key` and `value` into the transaction's // private writeset. Note that only hash of the private writeset goes into the // transaction proposal response (which is sent to the client who issued the // transaction) and the actual private writeset gets temporarily stored in a // transient store. PutPrivateData doesn't effect the `collection` until the // transaction is validated and successfully committed. Simple keys must not be // an empty string and must not start with null character (0x00), in order to // avoid range query collisions with composite keys, which internally get // prefixed with 0x00 as composite key namespace. PutPrivateData(collection string, key string, value []byte) error // DelPrivateData records the specified `key` to be deleted in the private writeset // of the transaction. Note that only hash of the private writeset goes into the // transaction proposal response (which is sent to the client who issued the // transaction) and the actual private writeset gets temporarily stored in a // transient store. The `key` and its value will be deleted from the collection // when the transaction is validated and successfully committed. DelPrivateData(collection, key string) error // SetPrivateDataValidationParameter sets the key-level endorsement policy // for the private data specified by `key`. SetPrivateDataValidationParameter(collection, key string, ep []byte) error // GetPrivateDataValidationParameter retrieves the key-level endorsement // policy for the private data specified by `key`. Note that this introduces // a read dependency on `key` in the transaction's readset. GetPrivateDataValidationParameter(collection, key string) ([]byte, error) // GetPrivateDataByRange returns a range iterator over a set of keys in a // given private collection. The iterator can be used to iterate over all keys // between the startKey (inclusive) and endKey (exclusive). // The keys are returned by the iterator in lexical order. Note // that startKey and endKey can be empty string, which implies unbounded range // query on start or end. // Call Close() on the returned StateQueryIteratorInterface object when done. // The query is re-executed during validation phase to ensure result set // has not changed since transaction endorsement (phantom reads detected). GetPrivateDataByRange(collection, startKey, endKey string) (StateQueryIteratorInterface, error) // GetPrivateDataByPartialCompositeKey queries the state in a given private // collection 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. The `objectType` and attributes are // expected to have only valid utf8 strings and should not contain // U+0000 (nil byte) and U+10FFFF (biggest and unallocated code point). // See related functions SplitCompositeKey and CreateCompositeKey. // Call Close() on the returned StateQueryIteratorInterface object when done. // The query is re-executed during validation phase to ensure result set // has not changed since transaction endorsement (phantom reads detected). GetPrivateDataByPartialCompositeKey(collection, objectType string, keys []string) (StateQueryIteratorInterface, error) // GetPrivateDataQueryResult performs a "rich" query against a given private // collection. It is only supported for state databases that support rich query, // e.g.CouchDB. The query string is in the native syntax // of the underlying state database. An iterator is returned // which can be used to iterate (next) over the query result set. // The query is NOT re-executed during validation phase, phantom reads are // not detected. That is, other committed transactions may have added, // updated, or removed keys that impact the result set, and this would not // be detected at validation/commit time. Applications susceptible to this // should therefore not use GetPrivateDataQueryResult as part of transactions that update // ledger, and should limit use to read-only chaincode operations. GetPrivateDataQueryResult(collection, query string) (StateQueryIteratorInterface, error) // GetCreator returns `SignatureHeader.Creator` (e.g. an identity) // of the `SignedProposal`. This is the identity of the agent (or user) // submitting the transaction. GetCreator() ([]byte, error) // GetTransient returns the `ChaincodeProposalPayload.Transient` field. // It is a map that contains data (e.g. cryptographic material) // that might be used to implement some form of application-level // confidentiality. The contents of this field, as prescribed by // `ChaincodeProposalPayload`, are supposed to always // be omitted from the transaction and excluded from the ledger. GetTransient() (map[string][]byte, error) // GetBinding returns the transaction binding, which is used to enforce a // link between application data (like those stored in the transient field // above) to the proposal itself. This is useful to avoid possible replay // attacks. GetBinding() ([]byte, error) // GetDecorations returns additional data (if applicable) about the proposal // that originated from the peer. This data is set by the decorators of the // peer, which append or mutate the chaincode input passed to the chaincode. GetDecorations() map[string][]byte // GetSignedProposal returns the SignedProposal object, which contains all // data elements part of a transaction proposal. GetSignedProposal() (*pb.SignedProposal, error) // GetTxTimestamp returns the timestamp when the transaction was created. This // is taken from the transaction ChannelHeader, therefore it will indicate the // client's timestamp and will have the same value across all endorsers. GetTxTimestamp() (*timestamp.Timestamp, error) // SetEvent allows the chaincode to set an event on the response to the // proposal to be included as part of a transaction. The event will be // available within the transaction in the committed block regardless of the // validity of the transaction. SetEvent(name string, payload []byte) error }
ChaincodeStubInterface is used by deployable chaincode apps to access and modify their ledgers
type CommonIterator ¶
type CommonIterator struct {
// contains filtered or unexported fields
}
CommonIterator documentation can be found in interfaces.go
func (*CommonIterator) Close ¶
func (iter *CommonIterator) Close() error
Close documentation can be found in interfaces.go
func (*CommonIterator) HasNext ¶
func (iter *CommonIterator) HasNext() bool
HasNext documentation can be found in interfaces.go
type CommonIteratorInterface ¶
type CommonIteratorInterface interface { // HasNext returns true if the range query iterator contains additional keys // and values. HasNext() bool // Close closes the iterator. This should be called when done // reading from the iterator to free up resources. Close() error }
CommonIteratorInterface allows a chaincode to check whether any more result to be fetched from an iterator and close it when done.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handler implementation for shim side of chaincode.
type HistoryQueryIterator ¶
type HistoryQueryIterator struct {
*CommonIterator
}
HistoryQueryIterator documentation can be found in interfaces.go
func (*HistoryQueryIterator) Next ¶
func (iter *HistoryQueryIterator) Next() (*queryresult.KeyModification, error)
type HistoryQueryIteratorInterface ¶
type HistoryQueryIteratorInterface interface { // Inherit HasNext() and Close() CommonIteratorInterface // Next returns the next key and value in the history query iterator. Next() (*queryresult.KeyModification, error) }
HistoryQueryIteratorInterface allows a chaincode to iterate over a set of key/value pairs returned by a history query.
type LoggingLevel ¶
LoggingLevel is an enumerated type of severity levels that control chaincode logging.
func LogLevel ¶
func LogLevel(levelString string) (LoggingLevel, error)
LogLevel 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.
type MockQueryIteratorInterface ¶
type MockQueryIteratorInterface interface { StateQueryIteratorInterface }
MockQueryIteratorInterface 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
type MockStateRangeQueryIterator ¶
type MockStateRangeQueryIterator struct { Closed bool Stub *MockStub StartKey string EndKey string Current *list.Element }
func NewMockStateRangeQueryIterator ¶
func NewMockStateRangeQueryIterator(stub *MockStub, startKey string, endKey string) *MockStateRangeQueryIterator
func (*MockStateRangeQueryIterator) Close ¶
func (iter *MockStateRangeQueryIterator) Close() error
Close closes the range query iterator. This should be called when done reading from the iterator to free up resources.
func (*MockStateRangeQueryIterator) HasNext ¶
func (iter *MockStateRangeQueryIterator) HasNext() bool
HasNext returns true if the range query iterator contains additional keys and values.
func (*MockStateRangeQueryIterator) Next ¶
func (iter *MockStateRangeQueryIterator) Next() (*queryresult.KV, error)
Next returns the next key and value in the range query iterator.
func (*MockStateRangeQueryIterator) Print ¶
func (iter *MockStateRangeQueryIterator) Print()
type MockStub ¶
type MockStub struct { // A nice name that can be used for logging Name string // State keeps name value pairs State map[string][]byte // Keys stores the list of mapped values in lexical order Keys *list.List // registered list of other MockStub chaincodes that can be called from this MockStub Invokables map[string]*MockStub // stores a transaction uuid while being Invoked / Deployed // TODO if a chaincode uses recursion this may need to be a stack of TxIDs or possibly a reference counting map TxID string TxTimestamp *timestamp.Timestamp // stores a channel ID of the proposal ChannelID string PvtState map[string]map[string][]byte // stores per-key endorsement policy, first map index is the collection, second map index is the key EndorsementPolicies map[string]map[string][]byte // channel to store ChaincodeEvents ChaincodeEventsChannel chan *pb.ChaincodeEvent Creator []byte Decorations map[string][]byte // contains filtered or unexported fields }
MockStub 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.
func NewMockStub ¶
Constructor to initialise the internal State map
func (*MockStub) CreateCompositeKey ¶
CreateCompositeKey combines the list of attributes to form a composite key.
func (*MockStub) DelPrivateData ¶ added in v1.1.0
func (*MockStub) GetArgsSlice ¶
Not implemented
func (*MockStub) GetChannelID ¶ added in v1.1.0
func (*MockStub) GetCreator ¶
func (*MockStub) GetDecorations ¶ added in v1.1.0
func (*MockStub) GetFunctionAndParameters ¶
func (*MockStub) GetHistoryForKey ¶
func (stub *MockStub) GetHistoryForKey(key string) (HistoryQueryIteratorInterface, error)
GetHistoryForKey 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.
func (*MockStub) GetPrivateData ¶ added in v1.1.0
func (*MockStub) GetPrivateDataByPartialCompositeKey ¶ added in v1.1.0
func (stub *MockStub) GetPrivateDataByPartialCompositeKey(collection, objectType string, attributes []string) (StateQueryIteratorInterface, error)
func (*MockStub) GetPrivateDataByRange ¶ added in v1.1.0
func (stub *MockStub) GetPrivateDataByRange(collection, startKey, endKey string) (StateQueryIteratorInterface, error)
func (*MockStub) GetPrivateDataHash ¶
func (*MockStub) GetPrivateDataQueryResult ¶ added in v1.1.0
func (stub *MockStub) GetPrivateDataQueryResult(collection, query string) (StateQueryIteratorInterface, error)
func (*MockStub) GetPrivateDataValidationParameter ¶ added in v1.3.0
func (*MockStub) GetQueryResult ¶
func (stub *MockStub) GetQueryResult(query string) (StateQueryIteratorInterface, error)
GetQueryResult 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
func (*MockStub) GetQueryResultWithPagination ¶ added in v1.3.0
func (stub *MockStub) GetQueryResultWithPagination(query string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
func (*MockStub) GetSignedProposal ¶
func (stub *MockStub) GetSignedProposal() (*pb.SignedProposal, error)
Not implemented
func (*MockStub) GetStateByPartialCompositeKey ¶
func (stub *MockStub) GetStateByPartialCompositeKey(objectType string, attributes []string) (StateQueryIteratorInterface, error)
GetStateByPartialCompositeKey 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.
func (*MockStub) GetStateByPartialCompositeKeyWithPagination ¶ added in v1.3.0
func (stub *MockStub) GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
func (*MockStub) GetStateByRange ¶
func (stub *MockStub) GetStateByRange(startKey, endKey string) (StateQueryIteratorInterface, error)
func (*MockStub) GetStateByRangeWithPagination ¶ added in v1.3.0
func (stub *MockStub) GetStateByRangeWithPagination(startKey, endKey string, pageSize int32, bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
func (*MockStub) GetStateValidationParameter ¶ added in v1.3.0
func (*MockStub) GetStringArgs ¶
func (*MockStub) GetTransient ¶
Not implemented
func (*MockStub) GetTxTimestamp ¶
func (*MockStub) InvokeChaincode ¶
func (stub *MockStub) InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response
InvokeChaincode locally calls the specified chaincode `Invoke`. E.g. stub1.InvokeChaincode("othercc", funcArgs, channel) Before calling this make sure to create another MockStub stub2, call shim.NewMockStub("othercc", Chaincode) and register it with stub1 by calling stub1.MockPeerChaincode("othercc", stub2, channel)
func (*MockStub) MockInvoke ¶
Invoke this chaincode, also starts and ends a transaction.
func (*MockStub) MockInvokeWithSignedProposal ¶
func (stub *MockStub) MockInvokeWithSignedProposal(uuid string, args [][]byte, sp *pb.SignedProposal) pb.Response
Invoke this chaincode, also starts and ends a transaction.
func (*MockStub) MockPeerChaincode ¶
func (stub *MockStub) MockPeerChaincode(invokableChaincodeName string, otherStub *MockStub, channel string)
Register another MockStub chaincode with this MockStub. invokableChaincodeName is the name of a chaincode. otherStub is a MockStub of the chaincode, already initialized. channel is the name of a channel on which another MockStub is called.
func (*MockStub) MockTransactionEnd ¶
End a mocked transaction, clearing the UUID.
func (*MockStub) MockTransactionStart ¶
Used 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.
func (*MockStub) PutPrivateData ¶ added in v1.1.0
func (*MockStub) SetPrivateDataValidationParameter ¶ added in v1.3.0
func (*MockStub) SetStateValidationParameter ¶ added in v1.3.0
type PeerChaincodeStream ¶
type PeerChaincodeStream interface { Send(*pb.ChaincodeMessage) error Recv() (*pb.ChaincodeMessage, error) CloseSend() error }
PeerChaincodeStream interface for stream between Peer and chaincode instance.
type SendPanicFailure ¶ added in v1.1.0
type SendPanicFailure string
SendPanicFailure
func (SendPanicFailure) Error ¶ added in v1.1.0
func (e SendPanicFailure) Error() string
type StateQueryIterator ¶
type StateQueryIterator struct {
*CommonIterator
}
StateQueryIterator documentation can be found in interfaces.go
func (*StateQueryIterator) Next ¶
func (iter *StateQueryIterator) Next() (*queryresult.KV, error)
type StateQueryIteratorInterface ¶
type StateQueryIteratorInterface interface { // Inherit HasNext() and Close() CommonIteratorInterface // Next returns the next key and value in the range and execute query iterator. Next() (*queryresult.KV, error) }
StateQueryIteratorInterface allows a chaincode to iterate over a set of key/value pairs returned by range and execute query.