Documentation ¶
Overview ¶
Package stub mocked provides APIs for the chaincode to access its state variables, transaction context and call other chaincodes.
Index ¶
- Constants
- func BuildCreator(creatorMSP string, creatorCert []byte) ([]byte, error)
- type StateRangeQueryIterator
- type StateRangeQueryWithPaginationIterator
- type Stub
- func (stub *Stub) AddAccountingRecord(token string, from *types.Address, to *types.Address, amount *big.Int, ...)
- func (stub *Stub) CreateCompositeKey(objectType string, attributes []string) (string, error)
- func (stub *Stub) DelPrivateData(_, _ string) error
- func (stub *Stub) DelState(key string) error
- func (stub *Stub) GetArgs() [][]byte
- func (stub *Stub) GetArgsSlice() ([]byte, error)
- func (stub *Stub) GetBinding() ([]byte, error)
- func (stub *Stub) GetChannelID() string
- func (stub *Stub) GetCreator() ([]byte, error)
- func (stub *Stub) GetDecorations() map[string][]byte
- func (stub *Stub) GetFunctionAndParameters() (function string, params []string)
- func (stub *Stub) GetHistoryForKey(_ string) (shim.HistoryQueryIteratorInterface, error)
- func (stub *Stub) GetPrivateData(collection string, key string) ([]byte, error)
- func (stub *Stub) GetPrivateDataByPartialCompositeKey(_, _ string, _ []string) (shim.StateQueryIteratorInterface, error)
- func (stub *Stub) GetPrivateDataByRange(_, _, _ string) (shim.StateQueryIteratorInterface, error)
- func (stub *Stub) GetPrivateDataHash(_, _ string) ([]byte, error)
- func (stub *Stub) GetPrivateDataQueryResult(_, _ string) (shim.StateQueryIteratorInterface, error)
- func (stub *Stub) GetPrivateDataValidationParameter(collection, key string) ([]byte, error)
- func (stub *Stub) GetQueryResult(_ string) (shim.StateQueryIteratorInterface, error)
- func (stub *Stub) GetQueryResultWithPagination(_ string, _ int32, _ string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
- func (stub *Stub) GetSignedProposal() (*pb.SignedProposal, error)
- func (stub *Stub) GetState(key string) ([]byte, error)
- func (stub *Stub) GetStateByPartialCompositeKey(objectType string, attributes []string) (shim.StateQueryIteratorInterface, error)
- func (stub *Stub) GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
- func (stub *Stub) GetStateByRange(startKey, endKey string) (shim.StateQueryIteratorInterface, error)
- func (stub *Stub) GetStateByRangeWithPagination(startKey, endKey string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
- func (stub *Stub) GetStateValidationParameter(key string) ([]byte, error)
- func (stub *Stub) GetStringArgs() []string
- func (stub *Stub) GetTransient() (map[string][]byte, error)
- func (stub *Stub) GetTxID() string
- func (stub *Stub) GetTxTimestamp() (*timestamp.Timestamp, error)
- func (stub *Stub) InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response
- func (stub *Stub) MockInit(uuid string, args [][]byte) pb.Response
- func (stub *Stub) MockInvoke(uuid string, args [][]byte) pb.Response
- func (stub *Stub) MockInvokeWithSignedProposal(uuid string, args [][]byte, sp *pb.SignedProposal) pb.Response
- func (stub *Stub) MockPeerChaincode(invokableChaincodeName string, otherStub *Stub)
- func (stub *Stub) MockPeerChaincodeWithChannel(invokableChaincodeName string, otherStub *Stub, channel string)
- func (stub *Stub) MockTransactionEnd(_ string)
- func (stub *Stub) MockTransactionStart(txID string)
- func (stub *Stub) PurgePrivateData(_, _ string) error
- func (stub *Stub) PutBalanceToState(key string, balance *big.Int) error
- func (stub *Stub) PutPrivateData(collection string, key string, value []byte) error
- func (stub *Stub) PutState(key string, value []byte) error
- func (stub *Stub) SetAdminCreatorCert(msp string) error
- func (stub *Stub) SetCreator(creator []byte)
- func (stub *Stub) SetCreatorCert(creatorMSP string, creatorCert []byte) error
- func (stub *Stub) SetDefaultCreatorCert(msp string) error
- func (stub *Stub) SetEvent(name string, payload []byte) error
- func (stub *Stub) SetPrivateDataValidationParameter(collection, key string, ep []byte) error
- func (stub *Stub) SetStateValidationParameter(key string, ep []byte) error
- func (stub *Stub) SplitCompositeKey(compositeKey string) (string, []string, error)
Constants ¶
const ErrFuncNotImplemented = "function %s is not implemented"
ErrFuncNotImplemented is returned when a function is not implemented
Variables ¶
This section is empty.
Functions ¶
Types ¶
type StateRangeQueryIterator ¶
type StateRangeQueryIterator struct { Closed bool Stub *Stub StartKey string EndKey string Current *list.Element }
StateRangeQueryIterator is an interface that is used to iterate over a set of keys
func NewMockStateRangeQueryIterator ¶
func NewMockStateRangeQueryIterator(stub *Stub, startKey string, endKey string) *StateRangeQueryIterator
NewMockStateRangeQueryIterator - Constructor for a StateRangeQueryIterator
func (*StateRangeQueryIterator) Close ¶
func (iter *StateRangeQueryIterator) Close() error
Close closes the range query iterator. This should be called when done reading from the iterator to free up resources.
func (*StateRangeQueryIterator) HasNext ¶
func (iter *StateRangeQueryIterator) HasNext() bool
HasNext returns true if the range query iterator contains additional keys and values.
func (*StateRangeQueryIterator) Next ¶
func (iter *StateRangeQueryIterator) Next() (*queryresult.KV, error)
Next returns the next key and value in the range query iterator.
func (*StateRangeQueryIterator) Print ¶
func (iter *StateRangeQueryIterator) Print()
Print prints the StateRangeQueryIterator
type StateRangeQueryWithPaginationIterator ¶
StateRangeQueryWithPaginationIterator is an interface that is used to iterate over a set of keys
func NewMockStateRangeQueryWithPaginationIterator ¶
func NewMockStateRangeQueryWithPaginationIterator(stub *Stub, elements []string) *StateRangeQueryWithPaginationIterator
NewMockStateRangeQueryWithPaginationIterator - Constructor for a StateRangeQueryWithPaginationIterator
func (*StateRangeQueryWithPaginationIterator) Close ¶
func (iter *StateRangeQueryWithPaginationIterator) Close() error
Close closes the range query iterator. This should be called when done reading from the iterator to free up resources.
func (*StateRangeQueryWithPaginationIterator) HasNext ¶
func (iter *StateRangeQueryWithPaginationIterator) HasNext() bool
HasNext returns true if the range query iterator contains additional keys and values.
func (*StateRangeQueryWithPaginationIterator) Next ¶
func (iter *StateRangeQueryWithPaginationIterator) Next() (*queryresult.KV, error)
Next returns the next key and value in the range query iterator.
type Stub ¶
type Stub struct { Args [][]byte // arguments the stub was called with Name string // A nice name that can be used for logging State map[string][]byte // State keeps name value pairs Keys *list.List // Keys stores the list of mapped values in lexical order registered list of other Stub chaincodes that can be called from this Stub Invokables map[string]*Stub TxID string // stores a transaction uuid while being Invoked / Deployed TxTimestamp *timestamp.Timestamp ChannelID string // stores a channel ID of the proposal PvtState map[string]map[string][]byte EndorsementPolicies map[string]map[string][]byte // stores per-key endorsement policy, first map index is the collection, second map index is the key ChaincodeEventsChannel chan *pb.ChaincodeEvent // channel to store ChaincodeEvents Decorations map[string][]byte // contains filtered or unexported fields }
Stub 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 ¶
NewMockStub - Constructor to config the internal State map
func (*Stub) AddAccountingRecord ¶ added in v0.0.3
func (*Stub) CreateCompositeKey ¶
CreateCompositeKey combines the list of attributes to form a composite key.
func (*Stub) DelPrivateData ¶
DelPrivateData removes the specified `key` and its value from the specified `collection`
func (*Stub) GetArgsSlice ¶
GetArgsSlice returns Args slice. Not implemented
func (*Stub) GetBinding ¶
GetBinding returns binding. Not implemented
func (*Stub) GetChannelID ¶
GetChannelID returns the channel ID for the proposal for the current chaincode invocation request.
func (*Stub) GetCreator ¶
GetCreator returns creator.
func (*Stub) GetDecorations ¶
GetDecorations returns the transaction decorations.
func (*Stub) GetFunctionAndParameters ¶
GetFunctionAndParameters returns the first argument as the function name and the rest of the arguments as parameters in a string array.
func (*Stub) GetHistoryForKey ¶
func (stub *Stub) GetHistoryForKey(_ string) (shim.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 (*Stub) GetPrivateData ¶
GetPrivateData returns the value of the specified `key` from the specified `collection`.
func (*Stub) GetPrivateDataByPartialCompositeKey ¶
func (stub *Stub) GetPrivateDataByPartialCompositeKey(_, _ string, _ []string) (shim.StateQueryIteratorInterface, error)
GetPrivateDataByPartialCompositeKey returns an iterator over a set of keys
func (*Stub) GetPrivateDataByRange ¶
func (stub *Stub) GetPrivateDataByRange(_, _, _ string) (shim.StateQueryIteratorInterface, error)
GetPrivateDataByRange returns a range iterator over a set of keys in the
func (*Stub) GetPrivateDataHash ¶
GetPrivateDataHash returns the hash of the specified `key` from the specified `collection`.
func (*Stub) GetPrivateDataQueryResult ¶
func (stub *Stub) GetPrivateDataQueryResult(_, _ string) (shim.StateQueryIteratorInterface, error)
GetPrivateDataQueryResult performs a "rich" query against a given private
func (*Stub) GetPrivateDataValidationParameter ¶
GetPrivateDataValidationParameter gets the private data validation parameter for the given collection and key
func (*Stub) GetQueryResult ¶
func (stub *Stub) GetQueryResult(_ string) (shim.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 (*Stub) GetQueryResultWithPagination ¶
func (stub *Stub) GetQueryResultWithPagination( _ string, _ int32, _ string, ) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
GetQueryResultWithPagination performs a "rich" query against a given state database.
func (*Stub) GetSignedProposal ¶
func (stub *Stub) GetSignedProposal() (*pb.SignedProposal, error)
GetSignedProposal returns proposal. Not implemented
func (*Stub) GetStateByPartialCompositeKey ¶
func (stub *Stub) GetStateByPartialCompositeKey(objectType string, attributes []string) (shim.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 (*Stub) GetStateByPartialCompositeKeyWithPagination ¶
func (stub *Stub) GetStateByPartialCompositeKeyWithPagination( objectType string, keys []string, pageSize int32, bookmark string, ) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
GetStateByPartialCompositeKeyWithPagination returns a range iterator over a set of keys in the Ledger.
func (*Stub) GetStateByRange ¶
func (stub *Stub) GetStateByRange(startKey, endKey string) (shim.StateQueryIteratorInterface, error)
GetStateByRange returns a range iterator over a set of keys in the Ledger.
func (*Stub) GetStateByRangeWithPagination ¶
func (stub *Stub) GetStateByRangeWithPagination( startKey, endKey string, pageSize int32, bookmark string, ) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)
GetStateByRangeWithPagination returns a range iterator over a set of keys in the Ledger.
func (*Stub) GetStateValidationParameter ¶
GetStateValidationParameter gets the state validation parameter for the given key
func (*Stub) GetStringArgs ¶
GetStringArgs returns the arguments for the chaincode invocation request as strings.
func (*Stub) GetTransient ¶
GetTransient returns transient. Not implemented
func (*Stub) GetTxID ¶
GetTxID returns the transaction ID for the current chaincode invocation request.
func (*Stub) GetTxTimestamp ¶
GetTxTimestamp returns timestamp.
func (*Stub) InvokeChaincode ¶
InvokeChaincode calls a peered chaincode. E.g. stub1.InvokeChaincode("stub2Hash", funcArgs, channel) Before calling this make sure to create another Stub stub2, call stub2.MockInit(uuid, func, Args) and register it with stub1 by calling stub1.MockPeerChaincode("stub2Hash", stub2)
func (*Stub) MockInvoke ¶
MockInvoke invokes this chaincode, also starts and ends a transaction.
func (*Stub) MockInvokeWithSignedProposal ¶
func (stub *Stub) MockInvokeWithSignedProposal(uuid string, args [][]byte, sp *pb.SignedProposal) pb.Response
MockInvokeWithSignedProposal invokes this chaincode, also starts and ends a transaction.
func (*Stub) MockPeerChaincode ¶
MockPeerChaincode registers a peer chaincode with this Stub invokeableChaincodeName is the name or hash of the peer otherStub is a Stub of the peer, already intialised
func (*Stub) MockPeerChaincodeWithChannel ¶
func (stub *Stub) MockPeerChaincodeWithChannel(invokableChaincodeName string, otherStub *Stub, channel string)
MockPeerChaincodeWithChannel registers a peer chaincode with this Stub
func (*Stub) MockTransactionEnd ¶
MockTransactionEnd ends a mocked transaction, clearing the UUID.
func (*Stub) MockTransactionStart ¶
MockTransactionStart is used to indicate to a chaincode that it is part of a transaction. This is important when chaincodes invoke each other. Stub doesn't support concurrent transactions at present.
func (*Stub) PurgePrivateData ¶
PurgePrivateData records the specified keys in the private data collection
func (*Stub) PutBalanceToState ¶
PutBalanceToState writes the specified `value` and `key` into the Ledger.
func (*Stub) PutPrivateData ¶
PutPrivateData puts the specified `key` and `value` into the transaction's
func (*Stub) SetAdminCreatorCert ¶
SetAdminCreatorCert sets admin certificate as creator certificate.
func (*Stub) SetCreatorCert ¶
SetCreatorCert sets creator cert
func (*Stub) SetDefaultCreatorCert ¶
SetDefaultCreatorCert sets default (not admin) certificate as creator certificate.
func (*Stub) SetPrivateDataValidationParameter ¶
SetPrivateDataValidationParameter sets the private data validation parameter for the given collection and key
func (*Stub) SetStateValidationParameter ¶
SetStateValidationParameter sets the state validation parameter for the given key