util

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package util provides generic CRUD methods for working with Hyperledger Fabric golang chaincode.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangeInfo

func ChangeInfo(stub shim.ChaincodeStubInterface, DocPrefix string, rowKey []string, data interface{}) error

ChangeInfo overwrites a value in the state database by performing an insert with overwrite indicator

func CheckChaincodeFunctionCallWellFormedness

func CheckChaincodeFunctionCallWellFormedness(args []string, expected_arg_count int) error

func CreateData

func CreateData(stub shim.ChaincodeStubInterface, DocPrefix string, rowKey []string, data interface{}) error

CreateData simply inserts a new key-value pair into the state database. It will fail if the key already exists. The pair is formatted as follows.

Key: DocPrefix_rowKey[0]_rowKey[1]_..._rowKey[n]_randomId Value: JSON document parsed from the data object.

func DeleteTableRow

func DeleteTableRow(
	stub shim.ChaincodeStubInterface,
	table_name string,
	row_keys []string,
	old_row_value interface{},
	failure_option GetTableRow_FailureOption,
) (rowWasFound bool, err error)

If old_row_value is not nil, then the table row will be unmarshaled into old_row_value before being deleted.

func GetDataById

func GetDataById(stub shim.ChaincodeStubInterface, ID string, DocPrefix string) (interface{}, error)

GetDataById get the state value of a key from the state database It returns a generic object.

func GetDataByIdWithResponse

func GetDataByIdWithResponse(stub shim.ChaincodeStubInterface, DataID string, data interface{}, ModelTable string) peer.Response

GetDataByIdWithResponse returns the peer.Response object directly to the caller so that the caller does not have to format it into Fabric response.

func GetDataByRowKeys

func GetDataByRowKeys(stub shim.ChaincodeStubInterface, rowKeys []string, DocPrefix string) (interface{}, error)

GetDataByRowKeys returns the state value of a key that is constructed with only document prefix and rowKeys. This is used for documents that we don't need random generated value in the key.

func GetDataByRowKeysWithResponse

func GetDataByRowKeysWithResponse(stub shim.ChaincodeStubInterface, rowKeys []string, data interface{}, ModelTable string) peer.Response

GetDataByRowKeysWithResponse returns the peer.Response directly to the caller so that the caller does not have to format it into Fabric response

func GetTableRow

func GetTableRow(
	stub shim.ChaincodeStubInterface,
	table_name string,
	row_keys []string,
	row_value interface{},
	failure_option GetTableRow_FailureOption,
) (rowWasFound bool, err error)

If row_value is nil, then don't bother unmarshaling the data. Thus a check for the presence of a particular table row can be done by specifying nil for row_value.

func GetTableRows

func GetTableRows(
	stub shim.ChaincodeStubInterface,
	table_name string,
	row_keys []string,
) (chan []byte, error)

If row_value is nil, then don't bother unmarshaling the data. Thus a check for the presence of a particular table row can be done by specifying nil for row_value.

func InsertTableRow

func InsertTableRow(
	stub shim.ChaincodeStubInterface,
	table_name string,
	row_keys []string,
	new_row_value interface{},
	failure_option InsertTableRow_FailureOption,
	old_row_value interface{},
) (rowWasFound bool, err error)

NOTE: This is the current abstraction to port old v0.6 style tables to current non-tables style ledger. Note that row_value must be json.Marshal-able. If old_row_value is not nil and the requested row is present, then the row will be unmarshaled into old_row_value before the new value (specified by row_value). Note that if FAIL_BEFORE_OVERWRITE is triggered, then old_row_value will contain the row that existed already that triggered the failure. If an error is returned, then the table will not have been modified (TODO: Probably need to verify this).

func MakeErrorRetval

func MakeErrorRetval(error_message string, args ...interface{}) ([]byte, error)

Pass through to Sprintf

func UpdateExistingData

func UpdateExistingData(stub shim.ChaincodeStubInterface, DocPrefix string, rowKey []string, data interface{}) error

UpdateExistingData works similar to ChangeInfo function. However, it does not check if the document is already existed This is useful if we already query out the row before and do not want to query again.

func UpdateTableRow

func UpdateTableRow(
	stub shim.ChaincodeStubInterface,
	table_name string,
	row_keys []string,
	new_row_value interface{},
) (err error)

UpdateTableRow is similar to InsertTableRow without re-checking if the row is already exist

Types

type GetTableRow_FailureOption

type GetTableRow_FailureOption bool

This is effectively a strongly typed enum declaration.

const (
	DONT_FAIL_IF_MISSING GetTableRow_FailureOption = false
	FAIL_IF_MISSING      GetTableRow_FailureOption = true
)

type InsertTableRow_FailureOption

type InsertTableRow_FailureOption uint8

This is effectively a strongly typed enum declaration.

const (
	DONT_FAIL_UPON_OVERWRITE InsertTableRow_FailureOption = 0
	FAIL_BEFORE_OVERWRITE    InsertTableRow_FailureOption = 1
	FAIL_UNLESS_OVERWRITE    InsertTableRow_FailureOption = 2
)

Jump to

Keyboard shortcuts

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