Documentation ¶
Overview ¶
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.
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 (stub *ChaincodeStub) CreateCompositeKey(objectType string, attributes []string) (string, error)
- func (stub *ChaincodeStub) DelState(key string) error
- func (stub *ChaincodeStub) GetArgs() [][]byte
- func (stub *ChaincodeStub) GetArgsSlice() ([]byte, error)
- func (stub *ChaincodeStub) GetBinding() ([]byte, error)
- func (stub *ChaincodeStub) GetCreator() ([]byte, error)
- func (stub *ChaincodeStub) GetFunctionAndParameters() (function string, params []string)
- func (stub *ChaincodeStub) GetHistoryForKey(key string) (HistoryQueryIteratorInterface, error)
- func (stub *ChaincodeStub) GetQueryResult(query string) (StateQueryIteratorInterface, error)
- func (stub *ChaincodeStub) GetSignedProposal() (*pb.SignedProposal, error)
- func (stub *ChaincodeStub) GetState(key string) ([]byte, error)
- func (stub *ChaincodeStub) GetStateByPartialCompositeKey(objectType string, attributes []string) (StateQueryIteratorInterface, error)
- func (stub *ChaincodeStub) GetStateByRange(startKey, endKey string) (StateQueryIteratorInterface, error)
- func (stub *ChaincodeStub) GetStringArgs() []string
- func (stub *ChaincodeStub) GetTransient() (map[string][]byte, error)
- func (stub *ChaincodeStub) GetTxID() string
- func (stub *ChaincodeStub) GetTxTimestamp() (*timestamp.Timestamp, error)
- func (stub *ChaincodeStub) InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response
- func (stub *ChaincodeStub) PutState(key string, value []byte) error
- func (stub *ChaincodeStub) SetEvent(name string, payload []byte) error
- func (stub *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) DelState(key string) error
- func (stub *MockStub) GetArgs() [][]byte
- func (stub *MockStub) GetArgsSlice() ([]byte, error)
- func (stub *MockStub) GetBinding() ([]byte, error)
- func (stub *MockStub) GetCreator() ([]byte, error)
- func (stub *MockStub) GetFunctionAndParameters() (function string, params []string)
- func (stub *MockStub) GetHistoryForKey(key string) (HistoryQueryIteratorInterface, error)
- func (stub *MockStub) GetQueryResult(query string) (StateQueryIteratorInterface, 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) GetStateByRange(startKey, endKey string) (StateQueryIteratorInterface, 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)
- func (stub *MockStub) MockTransactionEnd(uuid string)
- func (stub *MockStub) MockTransactionStart(txid string)
- func (stub *MockStub) PutState(key string, value []byte) error
- func (stub *MockStub) SetEvent(name string, payload []byte) error
- func (stub *MockStub) SplitCompositeKey(compositeKey string) (string, []string, error)
- type PeerChaincodeStream
- type StateQueryIterator
- type StateQueryIteratorInterface
Constants ¶
const ( STATE_QUERY_RESULT resultType = iota + 1 HISTORY_QUERY_RESULT )
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 ( // If status code less than 500, endorser will endorse it. // OK means init or invoke successfully. OK = 200 // Code that greater than or equal to 500 will be considered an error and rejected by endorser. ERROR = 500 )
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_LOGFORMAT and CORE_CHAINCODE_LOGLEVEL 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 Deploy transaction after the container has been // established, allowing the chaincode to initialize its internal data Init(stub ChaincodeStubInterface) pb.Response // Invoke is called for every Invoke transactions. The chaincode may change // its state variables 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 // contains filtered or unexported fields }
ChaincodeStub is an object passed to chaincode for shim side handling of APIs.
func (*ChaincodeStub) CreateCompositeKey ¶
func (stub *ChaincodeStub) CreateCompositeKey(objectType string, attributes []string) (string, error)
CreateCompositeKey combines the given attributes to form a composite key.
func (*ChaincodeStub) DelState ¶
func (stub *ChaincodeStub) DelState(key string) error
DelState removes the specified `key` and its value from the ledger.
func (*ChaincodeStub) GetArgs ¶
func (stub *ChaincodeStub) GetArgs() [][]byte
GetArgs returns the argument list
func (*ChaincodeStub) GetArgsSlice ¶
func (stub *ChaincodeStub) GetArgsSlice() ([]byte, error)
GetArgsSlice returns the arguments to the stub call as a byte array
func (*ChaincodeStub) GetBinding ¶
func (stub *ChaincodeStub) GetBinding() ([]byte, error)
GetBinding returns the transaction binding
func (*ChaincodeStub) GetCreator ¶
func (stub *ChaincodeStub) GetCreator() ([]byte, error)
GetCreator returns SignatureHeader.Creator of the signedProposal this Stub refers to.
func (*ChaincodeStub) GetFunctionAndParameters ¶
func (stub *ChaincodeStub) GetFunctionAndParameters() (function string, params []string)
GetFunctionAndParameters returns the first arg as the function and the rest as argument string array
func (*ChaincodeStub) GetHistoryForKey ¶
func (stub *ChaincodeStub) 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 (*ChaincodeStub) GetQueryResult ¶
func (stub *ChaincodeStub) 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 (*ChaincodeStub) GetSignedProposal ¶
func (stub *ChaincodeStub) GetSignedProposal() (*pb.SignedProposal, error)
GetSignedProposal return the signed signedProposal this stub refers to.
func (*ChaincodeStub) GetState ¶
func (stub *ChaincodeStub) GetState(key string) ([]byte, error)
GetState returns the byte array value specified by the `key`.
func (*ChaincodeStub) GetStateByPartialCompositeKey ¶
func (stub *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) GetStateByRange ¶
func (stub *ChaincodeStub) GetStateByRange(startKey, endKey string) (StateQueryIteratorInterface, error)
GetStateByRange function can be invoked by a chaincode to query of a range of keys in the state. Assuming the startKey and endKey are in lexical order, an iterator will be returned that can be used to iterate over all keys between the startKey and endKey. The startKey is inclusive whereas the endKey is 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.
func (*ChaincodeStub) GetStringArgs ¶
func (stub *ChaincodeStub) GetStringArgs() []string
GetStringArgs returns the arguments as array of strings
func (*ChaincodeStub) GetTransient ¶
func (stub *ChaincodeStub) GetTransient() (map[string][]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.
func (*ChaincodeStub) GetTxID ¶
func (stub *ChaincodeStub) GetTxID() string
GetTxID returns the transaction ID
func (*ChaincodeStub) GetTxTimestamp ¶
func (stub *ChaincodeStub) GetTxTimestamp() (*timestamp.Timestamp, error)
GetTxTimestamp returns the timestamp when the transaction was created. This is taken from the transaction ChannelHeader, so it will be the same across all endorsers.
func (*ChaincodeStub) InvokeChaincode ¶
func (stub *ChaincodeStub) InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response
InvokeChaincode locally calls the specified chaincode `Invoke` using the same transaction context; that is, chaincode calling chaincode doesn't create a new transaction message.
func (*ChaincodeStub) PutState ¶
func (stub *ChaincodeStub) PutState(key string, value []byte) error
PutState writes the specified `value` and `key` into the ledger. 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.
func (*ChaincodeStub) SetEvent ¶
func (stub *ChaincodeStub) SetEvent(name string, payload []byte) error
SetEvent saves the event to be sent when a transaction is made part of a block
func (*ChaincodeStub) SplitCompositeKey ¶
func (stub *ChaincodeStub) SplitCompositeKey(compositeKey string) (string, []string, error)
SplitCompositeKey splits the key into attributes on which the composite key was formed.
type ChaincodeStubInterface ¶
type ChaincodeStubInterface interface { // Get the arguments to the stub call as a 2D byte array GetArgs() [][]byte // Get the arguments to the stub call as a string array GetStringArgs() []string // Get the function which is the first argument and the rest of the arguments // as parameters GetFunctionAndParameters() (string, []string) // Get the transaction ID GetTxID() 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 a different // channel, only the Response is returned to the caller; any PutState calls // will not have any effect on the ledger of the channel; effectively it is // a `Query`. If `channel` is empty, the caller's channel is assumed. InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response // GetState returns the byte array value specified by the `key`. GetState(key string) ([]byte, error) // PutState writes the specified `value` and `key` into the ledger. PutState(key string, value []byte) error // DelState removes the specified `key` and its value from the ledger. DelState(key string) error // GetStateByRange function can be invoked by a chaincode to query of a range // of keys in the state. Assuming the startKey and endKey are in lexical // an iterator will be returned that can be used to iterate over all keys // between the startKey (inclusive) and endKey (exclusive). The order in which keys are // returned by the iterator is random. GetStateByRange(startKey, endKey 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. 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) GetStateByPartialCompositeKey(objectType string, keys []string) (StateQueryIteratorInterface, error) // Given a list of attributes, CreateCompositeKey function combines these 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) CreateCompositeKey(objectType string, attributes []string) (string, error) // Given a composite key, SplitCompositeKey function splits the key into attributes // on which the composite key was formed. SplitCompositeKey(compositeKey string) (string, []string, 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 GetQueryResult(query string) (StateQueryIteratorInterface, 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. GetHistoryForKey(key string) (HistoryQueryIteratorInterface, error) // GetCreator returns SignatureHeader.Creator of the signedProposal // this Stub refers to. 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 GetBinding() ([]byte, error) // GetSignedProposal return the signed signedProposal this stub refers to. GetSignedProposal() (*pb.SignedProposal, error) // GetArgsSlice returns the arguments to the stub call as a byte array GetArgsSlice() ([]byte, error) // GetTxTimestamp returns the timestamp when the transaction was created. This // is taken from the transaction ChannelHeader, so it will be the same across // all endorsers. GetTxTimestamp() (*timestamp.Timestamp, error) // SetEvent saves the event to be sent when a transaction is made part of a block 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 allows a chaincode to iterate over a set of key/value pairs in the state.
func (*CommonIterator) Close ¶
func (iter *CommonIterator) Close() error
Close closes the range query iterator. This should be called when done reading from the iterator to free up resources.
func (*CommonIterator) HasNext ¶
func (iter *CommonIterator) HasNext() bool
HasNext returns true if the range query iterator contains additional keys and values.
type CommonIteratorInterface ¶
type CommonIteratorInterface interface { // HasNext returns true if the range query iterator contains additional keys // and values. HasNext() bool // Close closes the range query 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 iterate and close it when needed.
type Handler ¶
type Handler struct { sync.RWMutex To string ChatStream PeerChaincodeStream FSM *fsm.FSM // contains filtered or unexported fields }
Handler handler implementation for shim side of chaincode.
type HistoryQueryIterator ¶
type HistoryQueryIterator struct {
*CommonIterator
}
GeneralQueryIterator allows a chaincode to iterate the result of history query.
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 ¶
type LoggingLevel logging.Level
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 // 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) GetArgsSlice ¶
Not implemented
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) 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) 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) GetStateByRange ¶
func (stub *MockStub) GetStateByRange(startKey, endKey string) (StateQueryIteratorInterface, error)
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 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)
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 ¶
Register a peer chaincode with this MockStub invokableChaincodeName is the name or hash of the peer otherStub is a MockStub of the peer, already intialised
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.
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 StateQueryIterator ¶
type StateQueryIterator struct {
*CommonIterator
}
GeneralQueryIterator allows a chaincode to iterate the result of range and execute query.
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.