Documentation
¶
Index ¶
- Constants
- Variables
- func KeyToComposite(stub shim.ChaincodeStubInterface, key Key) (string, error)
- func KeyToString(stub shim.ChaincodeStubInterface, key Key) (string, error)
- func NameAsIs(name string) (string, error)
- func NormalizeEventName(name interface{}) (string, error)
- func StringsIdFromStr(idString string) []string
- func StringsIdToStr(idSlice []string) string
- type Cached
- type CachedQueryIterator
- type Deletable
- type Event
- type EventImpl
- func (e *EventImpl) ArgNameValue(arg interface{}, values []interface{}) (name string, value interface{}, err error)
- func (e *EventImpl) Set(entry interface{}, values ...interface{}) error
- func (e *EventImpl) ToBytesConverter() serialize.ToBytesConverter
- func (e *EventImpl) UseNameTransformer(nt StringTransformer) Event
- func (e *EventImpl) UseToBytesConverter(toBytesConverter serialize.ToBytesConverter) Event
- type GetSettable
- type Gettable
- type HistoryEntry
- type HistoryEntryList
- type Historyable
- type Impl
- func (s *Impl) Clone() State
- func (s *Impl) Delete(entry interface{}) error
- func (s *Impl) DeletePrivate(collection string, entry interface{}) error
- func (s *Impl) Exists(entry interface{}) (bool, error)
- func (s *Impl) ExistsPrivate(collection string, entry interface{}) (bool, error)
- func (s *Impl) Get(entry interface{}, config ...interface{}) (interface{}, error)
- func (s *Impl) GetHistory(entry interface{}, target interface{}) (HistoryEntryList, error)
- func (s *Impl) GetPrivate(collection string, entry interface{}, config ...interface{}) (interface{}, error)
- func (s *Impl) Insert(entry interface{}, values ...interface{}) error
- func (s *Impl) InsertPrivate(collection string, entry interface{}, values ...interface{}) (err error)
- func (s *Impl) Key(key interface{}) (*TransformedKey, error)
- func (s *Impl) Keys(namespace interface{}) ([]string, error)
- func (s *Impl) List(namespace interface{}, target ...interface{}) (interface{}, error)
- func (s *Impl) ListPaginated(namespace interface{}, pageSize int32, bookmark string, target ...interface{}) (interface{}, *pb.QueryResponseMetadata, error)
- func (s *Impl) ListPrivate(collection string, usePrivateDataIterator bool, namespace interface{}, ...) (interface{}, error)
- func (s *Impl) Logger() *zap.Logger
- func (s *Impl) Put(entry interface{}, values ...interface{}) error
- func (s *Impl) PutPrivate(collection string, entry interface{}, values ...interface{}) (err error)
- func (s *Impl) Serializer() serialize.Serializer
- func (s *Impl) UseKeyReverseTransformer(kt KeyTransformer)
- func (s *Impl) UseKeyTransformer(kt KeyTransformer)
- func (s *Impl) UseSerializer(serializer serialize.Serializer)
- type Key
- type KeyFunc
- type KeyTransformer
- type KeyValue
- type Keyer
- type KeyerFunc
- type List
- type Listable
- type ListablePaginated
- type NameValue
- type Namer
- type Privateable
- type Settable
- type State
- type StringTransformer
- type StringsKeyer
- type TransformedKey
- type TxDeleteSet
- type TxWriteSet
- type WithKeyTransformer
- type WithSerializer
Constants ¶
const ListItemsField = `Items`
ListItemsField name of field with items in listTarget proto structure setting
Variables ¶
var ( // ErrUnableToCreateStateKey can occurs while creating composite key for entry ErrUnableToCreateStateKey = errors.New(`unable to create state key`) // ErrUnableToCreateEventName can occurs while creating composite key for entry ErrUnableToCreateEventName = errors.New(`unable to create event name`) // ErrKeyAlreadyExists can occurs when trying to insert entry with existing key ErrKeyAlreadyExists = errors.New(`state key already exists`) // ErrKeyNotFound key not found in chaincode state ErrKeyNotFound = errors.New(`state entry not found`) // ErrAllowOnlyOneValue can occurs when trying to call Insert or Put with more than 2 arguments ErrAllowOnlyOneValue = errors.New(`allow only one value`) // ErrStateEntryNotSupportKeyerInterface can occurs when trying to Insert or Put struct // providing key and struct without Keyer interface support ErrStateEntryNotSupportKeyerInterface = errors.New(`state entry not support keyer interface`) ErrEventEntryNotSupportNamerInterface = errors.New(`event entry not support name interface`) // ErrKeyPartsLength can occurs when trying to create key consisting of zero parts ErrKeyPartsLength = errors.New(`key parts length must be greater than zero`) )
var (
ErrEmptyChaincodeResponsePayload = errors.New(`empty chaincode response payload`)
)
Functions ¶
func KeyToComposite ¶
func KeyToComposite(stub shim.ChaincodeStubInterface, key Key) (string, error)
func KeyToString ¶
func KeyToString(stub shim.ChaincodeStubInterface, key Key) (string, error)
func NormalizeEventName ¶
func StringsIdFromStr ¶
StringsIdFromStr helper for restoring []string key
func StringsIdToStr ¶
StringsIdToStr helper for passing []string key
Types ¶
type Cached ¶
type Cached struct { State TxWriteSet TxWriteSet TxDeleteSet TxDeleteSet }
type CachedQueryIterator ¶
type CachedQueryIterator struct { KVs []*queryresult.KV // contains filtered or unexported fields }
func NewCachedQueryIterator ¶
func NewCachedQueryIterator(iterator shim.StateQueryIteratorInterface, prefix string, writeSet TxWriteSet, deleteSet TxDeleteSet) (*CachedQueryIterator, error)
func (*CachedQueryIterator) Close ¶
func (i *CachedQueryIterator) Close() error
Close closes the iterator. This should be called when done reading from the iterator to free up resources.
func (*CachedQueryIterator) HasNext ¶
func (i *CachedQueryIterator) HasNext() bool
HasNext returns true if the range query iterator contains additional keys and values.
func (*CachedQueryIterator) Next ¶
func (i *CachedQueryIterator) Next() (*queryresult.KV, error)
type Deletable ¶
type Deletable interface { // Delete returns result of deleting entry from state // entry can be Key (string or []string) or type implementing Keyer interface Delete(entry interface{}) (err error) }
type Event ¶
type Event interface { Set(entry interface{}, value ...interface{}) error UseToBytesConverter(serialize.ToBytesConverter) Event // ToBytesConverter todo: check neediness ToBytesConverter() serialize.ToBytesConverter UseNameTransformer(StringTransformer) Event }
Event interface for working with events in chaincode
type EventImpl ¶
type EventImpl struct {
// contains filtered or unexported fields
}
func NewEvent ¶
func NewEvent(stub shim.ChaincodeStubInterface) *EventImpl
NewEvent creates wrapper on shim.ChaincodeStubInterface for working with events
func (*EventImpl) ArgNameValue ¶
func (*EventImpl) ToBytesConverter ¶
func (e *EventImpl) ToBytesConverter() serialize.ToBytesConverter
func (*EventImpl) UseNameTransformer ¶
func (e *EventImpl) UseNameTransformer(nt StringTransformer) Event
func (*EventImpl) UseToBytesConverter ¶
func (e *EventImpl) UseToBytesConverter(toBytesConverter serialize.ToBytesConverter) Event
type GetSettable ¶
type Gettable ¶
type Gettable interface { // Get returns value from state, converted to target type // entry can be Key (string or []string) or type implementing Keyer interface Get(entry interface{}, target ...interface{}) (interface{}, error) // Exists returns entry existence in state // entry can be Key (string or []string) or type implementing Keyer interface Exists(entry interface{}) (bool, error) }
type HistoryEntry ¶
type HistoryEntry struct { TxId string `json:"txId"` Timestamp int64 `json:"timestamp"` IsDeleted bool `json:"isDeleted"` Value interface{} `json:"value"` }
HistoryEntry struct containing history information of a single entry
type HistoryEntryList ¶
type HistoryEntryList []HistoryEntry
HistoryEntryList list of history entries
type Historyable ¶
type Historyable interface { // GetHistory returns slice of history records for entry, with values converted to target type // entry can be Key (string or []string) or type implementing Keyer interface GetHistory(entry interface{}, target interface{}) (HistoryEntryList, error) }
type Impl ¶
type Impl struct { // wrappers for state access methods PutState func(string, []byte) error GetState func(string) ([]byte, error) DelState func(string) error GetStateByPartialCompositeKey func(objectType string, keys []string) (shim.StateQueryIteratorInterface, error) GetStateByPartialCompositeKeyWithPagination func(objectType string, keys []string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error) StateKeyTransformer KeyTransformer StateKeyReverseTransformer KeyTransformer // contains filtered or unexported fields }
func NewState ¶
func NewState(stub shim.ChaincodeStubInterface, logger *zap.Logger) *Impl
NewState creates wrapper on shim.ChaincodeStubInterface for working with state
func (*Impl) DeletePrivate ¶
DeletePrivate entry from private state
func (*Impl) ExistsPrivate ¶
ExistsPrivate check entry with key exists in chaincode private state
func (*Impl) GetHistory ¶
func (s *Impl) GetHistory(entry interface{}, target interface{}) (HistoryEntryList, error)
GetHistory by key from state, trying to convert to target interface
func (*Impl) GetPrivate ¶
func (s *Impl) GetPrivate(collection string, entry interface{}, config ...interface{}) (interface{}, error)
GetPrivate data by key from private state, trying to convert to target interface
func (*Impl) InsertPrivate ¶
func (s *Impl) InsertPrivate(collection string, entry interface{}, values ...interface{}) (err error)
InsertPrivate value into chaincode private state, returns error if key already exists
func (*Impl) Key ¶
func (s *Impl) Key(key interface{}) (*TransformedKey, error)
func (*Impl) List ¶
List data from state using objectType prefix in composite key, trying to convert to target interface. Keys - additional components of composite key
func (*Impl) ListPaginated ¶
func (*Impl) ListPrivate ¶
func (s *Impl) ListPrivate(collection string, usePrivateDataIterator bool, namespace interface{}, target ...interface{}) (interface{}, error)
ListPrivate data from private state using objectType prefix in composite key, trying to convert to target interface. Keys - additional components of composite key If usePrivateDataIterator is true, used private state for iterate over objects if false, used public state for iterate over keys and GetPrivateData for each key
func (*Impl) PutPrivate ¶
PutPrivate data value in private state with key, trying to convert data to []byte
func (*Impl) Serializer ¶
func (s *Impl) Serializer() serialize.Serializer
func (*Impl) UseKeyReverseTransformer ¶
func (s *Impl) UseKeyReverseTransformer(kt KeyTransformer)
func (*Impl) UseKeyTransformer ¶
func (s *Impl) UseKeyTransformer(kt KeyTransformer)
func (*Impl) UseSerializer ¶
func (s *Impl) UseSerializer(serializer serialize.Serializer)
type Key ¶
type Key []string
func KeyFromComposite ¶
func KeyFromComposite(stub shim.ChaincodeStubInterface, key string) (Key, error)
func NormalizeKey ¶
func NormalizeKey(stub shim.ChaincodeStubInterface, key interface{}) (Key, error)
type KeyTransformer ¶
KeyTransformer is used before putState operation for convert key
type KeyValue ¶
type KeyValue interface { Keyer serialize.Serializable }
KeyValue interface combines Keyer as ToByter(Serializer) methods - state entry representation
type Keyer ¶
Keyer interface for entity containing logic of its key creation
func StringKeyer ¶
StringKeyer constructor for struct implementing Keyer interface
type List ¶ added in v1.0.2
type List struct {
// contains filtered or unexported fields
}
func (*List) AddElementToList ¶ added in v1.0.2
func (sl *List) AddElementToList(elem interface{})
func (*List) Fill ¶ added in v1.0.2
func (sl *List) Fill( iter shim.StateQueryIteratorInterface, fromBytesConverter serialize.FromBytesConverter) (list interface{}, err error)
Fill state list from iterator
type Listable ¶
type Listable interface { // List returns slice of target type // namespace can be part of key (string or []string) or entity with defined mapping List(namespace interface{}, target ...interface{}) (interface{}, error) }
type ListablePaginated ¶
type ListablePaginated interface { // ListPaginated returns slice of target type with pagination // namespace can be part of key (string or []string) or entity with defined mapping ListPaginated(namespace interface{}, pageSize int32, bookmark string, target ...interface{}) ( interface{}, *pb.QueryResponseMetadata, error) }
type NameValue ¶
type NameValue interface { Namer serialize.ToBytesConverter }
NameValue interface combines Name() as ToByter methods - event representation
type Privateable ¶
type Privateable interface { // GetPrivate returns value from private state, converted to target type // entry can be Key (string or []string) or type implementing Keyer interface GetPrivate(collection string, entry interface{}, target ...interface{}) (interface{}, error) // PutPrivate returns result of putting entry to private state // entry can be Key (string or []string) or type implementing Keyer interface // if entry is implements Keyer interface, and it's struct or type implementing // ToByter interface value can be omitted PutPrivate(collection string, entry interface{}, value ...interface{}) error // InsertPrivate returns result of inserting entry to private state // If same key exists in state error wil be returned // entry can be Key (string or []string) or type implementing Keyer interface // if entry is implements Keyer interface, and it's struct or type implementing // ToByter interface value can be omitted InsertPrivate(collection string, entry interface{}, value ...interface{}) error // ListPrivate returns slice of target type from private state // namespace can be part of key (string or []string) or entity with defined mapping // If usePrivateDataIterator is true, used private state for iterate over objects // if false, used public state for iterate over keys and GetPrivateData for each key ListPrivate(collection string, usePrivateDataIterator bool, namespace interface{}, target ...interface{}) (interface{}, error) // DeletePrivate returns result of deleting entry from private state // entry can be Key (string or []string) or type implementing Keyer interface DeletePrivate(collection string, entry interface{}) error // ExistsPrivate returns entry existence in private state // entry can be Key (string or []string) or type implementing Keyer interface ExistsPrivate(collection string, entry interface{}) (bool, error) }
type Settable ¶
type Settable interface { // Put returns result of putting entry to state // entry can be Key (string or []string) or type implementing Keyer interface // if entry is implements Keyer interface, and it's struct or type implementing // ToByter interface value can be omitted Put(entry interface{}, value ...interface{}) error // Insert returns result of inserting entry to state // If same key exists in state error wil be returned // entry can be Key (string or []string) or type implementing Keyer interface // if entry is implements Keyer interface, and it's struct or type implementing // ToByter interface value can be omitted Insert(entry interface{}, value ...interface{}) error }
type State ¶
type State interface { Gettable Settable Listable ListablePaginated Deletable Historyable Privateable WithSerializer WithKeyTransformer // Keys returns slice of keys // namespace can be part of key (string or []string) or entity with defined mapping Keys(namespace interface{}) ([]string, error) Logger() *zap.Logger // Clone state for next changing transformers, state access methods etc Clone() State }
State interface for chain code CRUD operations
type StringTransformer ¶
StringTransformer is used before setEvent operation for convert name
type StringsKeyer ¶
StringsKeyer interface for entity containing logic of its key creation - backward compatibility
type TransformedKey ¶
TransformedKey stores origin and transformed state key
type TxDeleteSet ¶
type TxDeleteSet map[string]interface{}
type TxWriteSet ¶
type WithKeyTransformer ¶
type WithKeyTransformer interface { UseKeyTransformer(KeyTransformer) UseKeyReverseTransformer(KeyTransformer) }
type WithSerializer ¶
type WithSerializer interface { UseSerializer(serializer serialize.Serializer) Serializer() serialize.Serializer }