stub

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package stub mocked_atomyze provides APIs for the chaincode to access its state variables, transaction context and call other chaincodes.

Index

Constants

View Source
const ErrFuncNotImplemented = "function %s is not implemented"

ErrFuncNotImplemented is returned when a function is not implemented

Variables

This section is empty.

Functions

This section is empty.

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

type StateRangeQueryWithPaginationIterator struct {
	Closed   bool
	Stub     *Stub
	Elements []string
}

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

Close closes the range query iterator. This should be called when done reading from the iterator to free up resources.

func (*StateRangeQueryWithPaginationIterator) HasNext

HasNext returns true if the range query iterator contains additional keys and values.

func (*StateRangeQueryWithPaginationIterator) Next

Next returns the next key and value in the range query iterator.

type Stub

type Stub struct {
	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

func NewMockStub(name string, cc shim.Chaincode) *Stub

NewMockStub - Constructor to initialize the internal State map

func (*Stub) CreateCompositeKey

func (stub *Stub) CreateCompositeKey(objectType string, attributes []string) (string, error)

CreateCompositeKey combines the list of attributes to form a composite key.

func (*Stub) DelPrivateData

func (stub *Stub) DelPrivateData(_, _ string) error

DelPrivateData removes the specified `key` and its value from the specified `collection`

func (*Stub) DelState

func (stub *Stub) DelState(key string) error

DelState removes the specified `key` and its value from the Ledger.

func (*Stub) GetArgs

func (stub *Stub) GetArgs() [][]byte

GetArgs returns the arguments for the chaincode invocation request.

func (*Stub) GetArgsSlice

func (stub *Stub) GetArgsSlice() ([]byte, error)

GetArgsSlice returns args slice. Not implemented

func (*Stub) GetBinding

func (stub *Stub) GetBinding() ([]byte, error)

GetBinding returns binding. Not implemented

func (*Stub) GetChannelID

func (stub *Stub) GetChannelID() string

GetChannelID returns the channel ID for the proposal for the current chaincode invocation request.

func (*Stub) GetCreator

func (stub *Stub) GetCreator() ([]byte, error)

GetCreator returns creator.

func (*Stub) GetDecorations

func (stub *Stub) GetDecorations() map[string][]byte

GetDecorations returns the transaction decorations.

func (*Stub) GetFunctionAndParameters

func (stub *Stub) GetFunctionAndParameters() (function string, params []string)

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

func (stub *Stub) GetPrivateData(collection string, key string) ([]byte, error)

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

func (stub *Stub) GetPrivateDataHash(_, _ string) ([]byte, error)

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

func (stub *Stub) GetPrivateDataValidationParameter(collection, key string) ([]byte, error)

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) GetState

func (stub *Stub) GetState(key string) ([]byte, error)

GetState retrieves the value for a given key from the Ledger

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

func (stub *Stub) GetStateValidationParameter(key string) ([]byte, error)

GetStateValidationParameter gets the state validation parameter for the given key

func (*Stub) GetStringArgs

func (stub *Stub) GetStringArgs() []string

GetStringArgs returns the arguments for the chaincode invocation request as strings.

func (*Stub) GetTransient

func (stub *Stub) GetTransient() (map[string][]byte, error)

GetTransient returns transient. Not implemented

func (*Stub) GetTxID

func (stub *Stub) GetTxID() string

GetTxID returns the transaction ID for the current chaincode invocation request.

func (*Stub) GetTxTimestamp

func (stub *Stub) GetTxTimestamp() (*timestamp.Timestamp, error)

GetTxTimestamp returns timestamp.

func (*Stub) InvokeChaincode

func (stub *Stub) 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 Stub stub2, call stub2.MockInit(uuid, func, args) and register it with stub1 by calling stub1.MockPeerChaincode("stub2Hash", stub2)

func (*Stub) MockInit

func (stub *Stub) MockInit(uuid string, args [][]byte) pb.Response

MockInit initializes this chaincode, also starts and ends a transaction.

func (*Stub) MockInvoke

func (stub *Stub) MockInvoke(uuid string, args [][]byte) pb.Response

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

func (stub *Stub) MockPeerChaincode(invokableChaincodeName string, otherStub *Stub)

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

func (stub *Stub) MockTransactionEnd(_ string)

MockTransactionEnd ends a mocked transaction, clearing the UUID.

func (*Stub) MockTransactionStart

func (stub *Stub) MockTransactionStart(txID string)

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

func (stub *Stub) PurgePrivateData(_, _ string) error

PurgePrivateData records the specified keys in the private data collection

func (*Stub) PutBalanceToState

func (stub *Stub) PutBalanceToState(key string, balance *big.Int) error

PutBalanceToState writes the specified `value` and `key` into the Ledger.

func (*Stub) PutPrivateData

func (stub *Stub) PutPrivateData(collection string, key string, value []byte) error

PutPrivateData puts the specified `key` and `value` into the transaction's

func (*Stub) PutState

func (stub *Stub) PutState(key string, value []byte) error

PutState writes the specified `value` and `key` into the Ledger.

func (*Stub) SetCreator

func (stub *Stub) SetCreator(creator []byte)

SetCreator sets creator

func (*Stub) SetCreatorCert

func (stub *Stub) SetCreatorCert(creatorMSP string, creatorCert []byte) error

SetCreatorCert sets creator cert

func (*Stub) SetEvent

func (stub *Stub) SetEvent(name string, payload []byte) error

SetEvent allows the chaincode to set an event

func (*Stub) SetPrivateDataValidationParameter

func (stub *Stub) SetPrivateDataValidationParameter(collection, key string, ep []byte) error

SetPrivateDataValidationParameter sets the private data validation parameter for the given collection and key

func (*Stub) SetStateValidationParameter

func (stub *Stub) SetStateValidationParameter(key string, ep []byte) error

SetStateValidationParameter sets the state validation parameter for the given key

func (*Stub) SplitCompositeKey

func (stub *Stub) SplitCompositeKey(compositeKey string) (string, []string, error)

SplitCompositeKey splits the composite key into attributes on which the composite key was formed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL