{"modulePath":"github.com/eric-erki/https-hyperledger.org","version":"v0.6.1-preview","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package statemgmt\n\n## Functions\n\n```go\nfunc AssertIteratorContains(t *testing.T, itr RangeScanIterator, expected map[string][]byte)\n```\nAssertIteratorContains - tests wether the iterator (itr) contains expected results (provided in map)\n\n```go\nfunc ConstructCompositeKey(chaincodeID string, key string) []byte\n```\nConstructCompositeKey returns a \\[]byte that uniquely represents a given chaincodeID and key. This assumes that chaincodeID does not contain a 0x00 byte, but the key may TODO:enforce this restriction on chaincodeID or use length prefixing here instead of delimiter\n\n```go\nfunc Copy(src []byte) []byte\n```\nCopy returns a copy of given bytes\n\n```go\nfunc DecodeCompositeKey(compositeKey []byte) (string, string)\n```\nDecodeCompositeKey decodes the compositeKey constructed by ConstructCompositeKey method back to the original chaincodeID and key form\n\n## Types\n\n```go\ntype ChaincodeStateDelta struct {\n\tChaincodeID string\n\tUpdatedKVs  map[string]*UpdatedValue\n}\n```\nChaincodeStateDelta maintains state for a chaincode\n\n```go\ntype HashableState interface {\n\n\t// Initialize this gives a chance to initialize. For instance, state implementation can load some data from DB\n\tInitialize(configs map[string]interface{}) error\n\n\t// Get get the value from DB\n\tGet(chaincodeID string, key string) ([]byte, error)\n\n\t// PrepareWorkingSet passes a stateDelta that captures the changes that needs to be applied to the state\n\tPrepareWorkingSet(stateDelta *StateDelta) error\n\n\t// ComputeCryptoHash state implementation to compute crypto-hash of state\n\t// assuming the stateDelta (passed in PrepareWorkingSet method) is to be applied\n\tComputeCryptoHash() ([]byte, error)\n\n\t// AddChangesForPersistence state implementation to add all the key-value pair that it needs\n\t// to persist for committing the  stateDelta (passed in PrepareWorkingSet method) to DB.\n\t// In addition to the information in the StateDelta, the implementation may also want to\n\t// persist intermediate results for faster crypto-hash computation\n\tAddChangesForPersistence(writeBatch *gorocksdb.WriteBatch) error\n\n\t// ClearWorkingSet state implementation may clear any data structures that it may have constructed\n\t// for computing cryptoHash and persisting the changes for the stateDelta (passed in PrepareWorkingSet method)\n\tClearWorkingSet(changesPersisted bool)\n\n\t// GetStateSnapshotIterator state implementation to provide an iterator that is supposed to give\n\t// All the key-value of global state. A particular implementation may need to remove additional information\n\t// that the implementation keeps for faster crypto-hash computation. For instance, filter a few of the\n\t// key-values or remove some data from particular key-values.\n\tGetStateSnapshotIterator(snapshot *gorocksdb.Snapshot) (StateSnapshotIterator, error)\n\n\t// GetRangeScanIterator - state implementation to provide an iterator that is supposed to give\n\t// All the key-values for a given chaincodeID such that a return key should be lexically greater than or\n\t// equal to startKey and less than or equal to endKey. If the value for startKey parameter is an empty string\n\t// startKey is assumed to be the smallest key available in the db for the chaincodeID. Similarly, an empty string\n\t// for endKey parameter assumes the endKey to be the greatest key available in the db for the chaincodeID\n\tGetRangeScanIterator(chaincodeID string, startKey string, endKey string) (RangeScanIterator, error)\n\n\t// PerfHintKeyChanged state implementation may be provided with some hints before (e.g., during tx execution)\n\t// the StateDelta is prepared and passed in PrepareWorkingSet method.\n\t// A state implementation may use this hint for prefetching relevant data so as if this could improve\n\t// the performance of ComputeCryptoHash method (when gets called at a later time)\n\tPerfHintKeyChanged(chaincodeID string, key string)\n}\n```\nHashableState - Interface that is be implemented by state management Different state management implementation can be effiecient for computing crypto-hash for state under different workload conditions.\n\n```go\ntype RangeScanIterator interface {\n\n\t// Next moves to next key-value. Returns true if next key-value exists\n\tNext() bool\n\n\t// GetKeyValue returns next key-value\n\tGetKeyValue() (string, []byte)\n\n\t// Close releases resources occupied by the iterator\n\tClose()\n}\n```\nRangeScanIterator - is to be implemented by the return value of GetRangeScanIterator method in the implementation of HashableState interface\n\n```go\ntype StateDelta struct {\n\tChaincodeStateDeltas map[string]*ChaincodeStateDelta\n\t// RollBackwards allows one to contol whether this delta will roll the state\n\t// forwards or backwards.\n\tRollBackwards bool\n}\n```\nStateDelta holds the changes to existing state. This struct is used for holding the uncommitted changes during execution of a tx-batch Also, to be used for transferring the state to another peer in chunks\n\n```go\nfunc ConstructRandomStateDelta(\n\tt testing.TB,\n\tchaincodeIDPrefix string,\n\tnumChaincodes int,\n\tmaxKeySuffix int,\n\tnumKeysToInsert int,\n\tkvSize int) *StateDelta\n```\nConstructRandomStateDelta creates a random state delta for testing\n\n```go\nfunc NewStateDelta() *StateDelta\n```\nNewStateDelta constructs an empty StateDelta struct\n\n```go\nfunc (stateDelta *StateDelta) ApplyChanges(anotherStateDelta *StateDelta)\n```\nApplyChanges merges another delta - if a key is present in both, the value of the existing key is overwritten\n\n```go\nfunc (stateDelta *StateDelta) ComputeCryptoHash() []byte\n```\nComputeCryptoHash computes crypto-hash for the data held returns nil if no data is present\n\n```go\nfunc (stateDelta *StateDelta) Delete(chaincodeID string, key string, previousValue []byte)\n```\nDelete deletes a key from the state\n\n```go\nfunc (stateDelta *StateDelta) Get(chaincodeID string, key string) *UpdatedValue\n```\nGet get the state from delta if exists\n\n```go\nfunc (stateDelta *StateDelta) GetUpdatedChaincodeIds(sorted bool) []string\n```\nGetUpdatedChaincodeIds return the chaincodeIDs that are prepsent in the delta If sorted is true, the method return chaincodeIDs in lexicographical sorted order\n\n```go\nfunc (stateDelta *StateDelta) GetUpdates(chaincodeID string) map[string]*UpdatedValue\n```\nGetUpdates returns changes associated with given chaincodeId\n\n```go\nfunc (stateDelta *StateDelta) IsEmpty() bool\n```\nIsEmpty checks whether StateDelta contains any data\n\n```go\nfunc (stateDelta *StateDelta) IsUpdatedValueSet(chaincodeID, key string) bool\n```\nIsUpdatedValueSet returns true if a update value is already set for the given chaincode ID and key.\n\n```go\nfunc (stateDelta *StateDelta) Marshal() (b []byte)\n```\nMarshal serializes the StateDelta\n\n```go\nfunc (stateDelta *StateDelta) Set(chaincodeID string, key string, value, previousValue []byte)\n```\nSet sets state value for a key\n\n```go\nfunc (stateDelta *StateDelta) Unmarshal(bytes []byte) error\n```\nUnmarshal deserializes StateDelta\n\n```go\ntype StateDeltaIterator struct {\n\t// contains filtered or unexported fields\n}\n```\nStateDeltaIterator - An iterator implementation over state-delta\n\n```go\nfunc NewStateDeltaRangeScanIterator(delta *StateDelta, chaincodeID string, startKey string, endKey string) *StateDeltaIterator\n```\nNewStateDeltaRangeScanIterator - return an iterator for performing a range scan over a state-delta object\n\n```go\nfunc (itr *StateDeltaIterator) Close()\n```\nClose - see interface 'RangeScanIterator' for details\n\n```go\nfunc (itr *StateDeltaIterator) ContainsKey(key string) bool\n```\nContainsKey - checks wether the given key is present in the state-delta\n\n```go\nfunc (itr *StateDeltaIterator) GetKeyValue() (string, []byte)\n```\nGetKeyValue - see interface 'RangeScanIterator' for details\n\n```go\nfunc (itr *StateDeltaIterator) Next() bool\n```\nNext - see interface 'RangeScanIterator' for details\n\n```go\ntype StateSnapshotIterator interface {\n\n\t// Next moves to next key-value. Returns true if next key-value exists\n\tNext() bool\n\n\t// GetRawKeyValue returns next key-value\n\tGetRawKeyValue() ([]byte, []byte)\n\n\t// Close releases resources occupied by the iterator\n\tClose()\n}\n```\nStateSnapshotIterator An interface that is to be implemented by the return value of GetStateSnapshotIterator method in the implementation of HashableState interface\n\n```go\ntype UpdatedValue struct {\n\tValue         []byte\n\tPreviousValue []byte\n}\n```\nUpdatedValue holds the value for a key\n\n```go\nfunc (updatedValue *UpdatedValue) GetPreviousValue() []byte\n```\nGetPreviousValue returns the previous value\n\n```go\nfunc (updatedValue *UpdatedValue) GetValue() []byte\n```\nGetValue returns the value\n\n```go\nfunc (updatedValue *UpdatedValue) IsDeleted() bool\n```\nIsDeleted checks whether the key was deleted\n\n","path":"github.com/eric-erki/https-hyperledger.org/core/ledger/statemgmt","name":"statemgmt","synopsis":"","isRedistributable":true}
