Documentation ¶
Overview ¶
Package shim provides APIs for the chaincode to access its state variables, transaction context and call other chaincodes.
Index ¶
- type Chaincode
- type ChaincodeStubInterface
- type MockStateRangeQueryIterator
- type MockStub
- func (stub *MockStub) DelState(key string) error
- func (stub *MockStub) GetArgs() [][]byte
- func (stub *MockStub) GetBinding() ([]byte, error)
- func (stub *MockStub) GetCallerAttribute(attributeName string) ([]byte, error)
- func (stub *MockStub) GetCallerCertificate() ([]byte, error)
- func (stub *MockStub) GetCallingChaincodeName() string
- func (stub *MockStub) GetOriginalChaincodeName() string
- func (stub *MockStub) GetRawStub() interface{}
- func (stub *MockStub) GetState(key string) ([]byte, error)
- func (stub *MockStub) GetStringArgs() []string
- func (stub *MockStub) GetTxID() string
- func (stub *MockStub) GetTxTime() (time.Time, error)
- func (stub *MockStub) InvokeChaincode(chaincodeName string, function string, args [][]byte) ([]byte, error)
- func (stub *MockStub) MockInit(uuid string, function string, args [][]byte) ([]byte, error)
- func (stub *MockStub) MockInvoke(uuid string, function string, args [][]byte) ([]byte, error)
- func (stub *MockStub) MockPeerChaincode(invokableChaincodeName string, otherStub *MockStub)
- func (stub *MockStub) MockQuery(function string, args [][]byte) ([]byte, error)
- func (stub *MockStub) MockTransactionEnd(uuid string, e error)
- func (stub *MockStub) MockTransactionStart(txid string)
- func (stub *MockStub) PutState(key string, value []byte) error
- func (stub *MockStub) QueryChaincode(chaincodeName string, function string, args [][]byte) ([]byte, error)
- func (stub *MockStub) RangeQueryState(startKey, endKey string) (StateRangeQueryIteratorInterface, error)
- func (stub *MockStub) SetEvent(name string, payload []byte) error
- type StateRangeQueryIteratorInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chaincode ¶
type Chaincode interface { // Invoke is called for every transactions. Invoke(stub ChaincodeStubInterface, function string, args [][]byte, readonly bool) ([]byte, error) }
Chaincode interface purposed to be implemented by all chaincodes. The fabric runs the transactions by calling these functions as specified. We use the designation mixed with fabric 0.6 and 1.x (this interface is not so important like it was in the real fabric implement, just to provide a suitable interface in some tools)
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 transaction ID GetTxID() string // returns transaction created timestamp, which is currently // taken from the peer receiving the transaction. Note that this timestamp // may not be the same with the other peers' time. GetTxTime() (time.Time, error) // 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 // RangeQueryState 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 and endKey, inclusive. The order in which keys are // returned by the iterator is random. RangeQueryState(startKey, endKey string) (StateRangeQueryIteratorInterface, error) // GetBinding returns the transaction binding GetBinding() ([]byte, error) // SetEvent saves the event to be sent when a transaction is made part of a block SetEvent(name string, payload []byte) error // obtain the original chaincodestub interface for more implement-spec code GetRawStub() 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() (string, []byte, 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 // store when is called from another chaincode InvokedCCName string // Extended plugin EventHandler func(string, []byte) error // 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, Query or Invoke.
func NewMockStub ¶
Constructor to initialise the internal State map
func (*MockStub) GetCallerAttribute ¶
Not implemented
func (*MockStub) GetCallerCertificate ¶
Not implemented
func (*MockStub) GetCallingChaincodeName ¶
func (*MockStub) GetOriginalChaincodeName ¶
func (*MockStub) GetRawStub ¶
func (stub *MockStub) GetRawStub() interface{}
func (*MockStub) GetStringArgs ¶
func (*MockStub) InvokeChaincode ¶
func (stub *MockStub) InvokeChaincode(chaincodeName string, function string, args [][]byte) ([]byte, error)
Invokes a peered chaincode. E.g. stub1.InvokeChaincode("stub2Hash", funcArgs) 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) 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.
func (*MockStub) QueryChaincode ¶
func (*MockStub) RangeQueryState ¶
func (stub *MockStub) RangeQueryState(startKey, endKey string) (StateRangeQueryIteratorInterface, error)
type StateRangeQueryIteratorInterface ¶
type StateRangeQueryIteratorInterface interface { // HasNext returns true if the range query iterator contains additional keys // and values. HasNext() bool // Next returns the next key and value in the range query iterator. Next() (string, []byte, error) // Close closes the range query iterator. This should be called when done // reading from the iterator to free up resources. Close() error }
StateRangeQueryIteratorInterface allows a chaincode to iterate over a range of key/value pairs in the state.