state

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2018 License: MIT Imports: 4 Imported by: 6 modules, 10 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnableToCreateKey can occurs while creating composite key for entry
	ErrUnableToCreateKey = errors.New(`unable to create state key`)

	// ErrKeyAlreadyExists can occurs when trying to insert entry with existing key
	ErrKeyAlreadyExists = errors.New(`state key already exists`)

	// ErrrKeyNotFound 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`)

	// ErrKeyNotSupportKeyerInterface can occurs when trying to Insert or Put struct without providing key and struct not support Keyer interface
	ErrKeyNotSupportKeyerInterface = errors.New(`key not support keyer interface`)

	// ErrKeyPartsLength can occurs when trying to create key consisting of zero parts
	ErrKeyPartsLength = errors.New(`key parts length must be greater than zero`)
)
View Source
var (
	ErrEmptyChaincodeResponsePayload = errors.New(`empty chaincode response payload`)
)

Functions

func ConvertFromBytes added in v0.3.0

func ConvertFromBytes(bb []byte, config ...interface{}) (interface{}, error)

func ConvertToBytes added in v0.3.0

func ConvertToBytes(v interface{}, config ...interface{}) ([]byte, error)

func InvokeChaincode

func InvokeChaincode(
	stub shim.ChaincodeStubInterface, chaincodeName string, args []interface{}, channel string, target interface{}) (interface{}, error)

InvokeChaincode locally calls the specified chaincode and converts result into target data type

func KeyError

func KeyError(strKey string) error

KeyError error with key

func KeyFromParts

func KeyFromParts(stub shim.ChaincodeStubInterface, keyParts []string) (string, error)

KeyFromParts creates composite key by string slice

func KeyParts

func KeyParts(key interface{}) ([]string, error)

KeyParts returns string parts of composite key

Types

type FromBytesTransformer added in v0.3.0

type FromBytesTransformer func(bb []byte, config ...interface{}) (interface{}, 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 KeyPartsTransformer added in v0.3.0

type KeyPartsTransformer func(key interface{}) ([]string, error)

type Keyer

type Keyer interface {
	Key() ([]string, error)
}

Keyer interface for entity containing logic of its key creation

func StringKeyer

func StringKeyer(str string, keyer KeyerFunc) Keyer

StringKeyer constructor for struct implementing Keyer interface

type KeyerFunc

type KeyerFunc func(string) ([]string, error)

type State added in v0.3.0

type State interface {
	Get(key interface{}, target ...interface{}) (result interface{}, err error)
	GetInt(key interface{}, defaultValue int) (result int, err error)
	GetHistory(key interface{}, target interface{}) (result HistoryEntryList, err error)
	Exists(key interface{}) (exists bool, err error)
	Put(key interface{}, value ...interface{}) (err error)
	Insert(key interface{}, value ...interface{}) (err error)
	List(objectType interface{}, target ...interface{}) (result []interface{}, err error)
	Delete(key interface{}) (err error)
}

State interface for chain code CRUD operations

type StateImpl added in v0.3.0

type StateImpl struct {
	KeyParts            KeyPartsTransformer
	StateGetTransformer FromBytesTransformer
	StatePutTransformer ToBytesTransformer
	// contains filtered or unexported fields
}

func New added in v0.3.0

New creates wrapper on shim.ChaincodeStubInterface working with state

func (*StateImpl) Delete added in v0.3.0

func (s *StateImpl) Delete(key interface{}) (err error)

Delete entry from state

func (*StateImpl) Exists added in v0.3.0

func (s *StateImpl) Exists(key interface{}) (exists bool, err error)

Exists check entry with key exists in chaincode state

func (*StateImpl) Get added in v0.3.0

func (s *StateImpl) Get(key interface{}, config ...interface{}) (result interface{}, err error)

Get data by key from state, trying to convert to target interface

func (*StateImpl) GetHistory added in v0.3.0

func (s *StateImpl) GetHistory(key interface{}, target interface{}) (result HistoryEntryList, err error)

GetHistory by key from state, trying to convert to target interface

func (*StateImpl) GetInt added in v0.3.0

func (s *StateImpl) GetInt(key interface{}, defaultValue int) (result int, err error)

func (*StateImpl) Insert added in v0.3.0

func (s *StateImpl) Insert(key interface{}, values ...interface{}) (err error)

Insert value into chaincode state, returns error if key already exists

func (*StateImpl) Key added in v0.3.0

func (s *StateImpl) Key(key interface{}) (string, error)

func (*StateImpl) List added in v0.3.0

func (s *StateImpl) List(objectType interface{}, target ...interface{}) (result []interface{}, err error)

List data from state using objectType prefix in composite key, trying to conver to target interface. Keys - additional components of composite key

func (*StateImpl) Put added in v0.3.0

func (s *StateImpl) Put(key interface{}, values ...interface{}) (err error)

Put data value in state with key, trying convert data to []byte

type ToBytesTransformer added in v0.3.0

type ToBytesTransformer func(v interface{}, config ...interface{}) ([]byte, error)

Jump to

Keyboard shortcuts

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