istate

package module
v0.0.0-...-9d55158 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2020 License: Apache-2.0 Imports: 12 Imported by: 2

README

Notice

Ownership of the repo has ben transfered. Please use: https://github.com/motoreq/iState

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewiState

func NewiState(object interface{}, opt Options) (iStateInterface Interface, iStateErr Error)

NewiState function is used to create an iState interface for a struct type. Further CRUD operation on the struct type can be performed using the interface returned. It takes an empty struct value, Options as input and returns istate interface.

Types

type Error

type Error interface {
	Error() string
	GetCode() int
}

Error is the interface of this package.

type Interface

type Interface interface {
	// CreateState function is used to create a new state in the state db
	// It must be called via the Interface returned by NewiState function
	// It takes chaincode stub and the actual structure value as input params
	// Note: This function does not do state validations such as, checking whether state exists or not
	// before performing the operation
	CreateState(shim.ChaincodeStubInterface, interface{}) Error
	// ReadState function is used to read a state from state db
	// It must be called via the Interface returned by NewiState function
	// It takes chaincode stub and value of primary key as input params
	// It returns the actual structure value as an interface{}. The returned value can
	// be type asserted to the actual struct type before using
	// Note: This function does not do state validations such as, checking whether state exists or not
	// before performing the operation
	ReadState(shim.ChaincodeStubInterface, interface{}) (interface{}, Error)
	// UpdateState function is used to update a state from statedb
	// It must be called via the Interface returned by NewiState function
	// It takes chaincode stub and the actual structure value as input params
	// Note: This function does not do state validations such as, checking whether state exists or not
	// before performing the operation
	UpdateState(shim.ChaincodeStubInterface, interface{}) Error
	// DeleteState function is used to delete a state from state db
	// It must be called via the Interface returned by NewiState function
	// It takes chaincode stub and value of primary key as input params
	// Note: This function does not do state validations such as, checking whether state exists or not
	// before performing the operation
	DeleteState(shim.ChaincodeStubInterface, interface{}) Error
	// Query function is used to perform Rich Queries over a state type in state db
	// It must be called via the Interface returned by NewiState function
	// It takes stub, query string and isInvoke (bool) flag as input params
	// isInvoke is set true, if this func is called in an invoke transaction
	// It returns slice of actual structure values as an interface{}. The returned value can
	// be type asserted to the actual slice of struct type before using
	// Learn more about the Rich query language formats in README.md
	Query(shim.ChaincodeStubInterface, string, bool) (interface{}, Error)
}

type Options

type Options struct {
	CacheSize             int
	DefaultCompactionSize int
}

Options is an input parameter for NewiState function. CacheSize determines the max no. of records allowed in memory. DefaultCompactionSize determines how many index records to compact at one go. Since Compaction process takes lot of time, it is useful to set a batchsize and Compaction can be run multiple times, where each time, n records gets compacted.

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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