util

package module
v0.0.0-...-104a8d5 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2019 License: GPL-2.0 Imports: 20 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// DefaultBaseURL is the default address of CouchDB server.
	DefaultBaseURL = "localhost:5984"

	// The couchDB test will have this name: DefaultChannelName_DefaultNamespace
	DefaultChannelName   = "channel"   // Fabric channel
	DefaultChaincodeName = "chaincode" // Fabric chaincode
)

Variables

This section is empty.

Functions

func Changeinfo

func Changeinfo(stub shim.ChaincodeStubInterface, TableModel string, row_key []string, data interface{}) error

Update Infomation

func CheckChaincodeFunctionCallWellFormedness

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

func Createdata

func Createdata(stub shim.ChaincodeStubInterface, TableModel string, row_key []string, data interface{}) error

create data

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 GetAllData

func GetAllData(stub shim.ChaincodeStubInterface, data interface{}, ModelTable string) pb.Response

GetAllData

func GetDataByID

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

GetDataByID

func GetDataByRowKeys

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

GetDataByKey

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 Getalldata

func Getalldata(stub shim.ChaincodeStubInterface, MODELTABLE string) (chan []byte, error)

get all data

func Getdatabyid

func Getdatabyid(stub shim.ChaincodeStubInterface, ID string, MODELTABLE string) (interface{}, error)

get information of data by ID

func Getdatabyrowkeys

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

get information of data by row keys

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 MockInitTransaction

func MockInitTransaction(t *testing.T, stub *MockStubExtend, args [][]byte) string

MockIInit creates a mock invoke transaction using MockStubExtend

func MockInvokeTransaction

func MockInvokeTransaction(t *testing.T, stub *MockStubExtend, args [][]byte) string

MockInvokeTransaction creates a mock invoke transaction using MockStubExtend

func MockQueryTransaction

func MockQueryTransaction(t *testing.T, stub *MockStubExtend, args [][]byte) string

MockQueryTransaction creates a mock query transaction using MockStubExtend

func UpdateExistingData

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

UpdateExistingData works similar to Changeinfo. 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 AkcQueryIterator

type AkcQueryIterator struct {
	*StateQueryIterator
	// contains filtered or unexported fields
}

AkcQueryIterator inherits StateQueryIterator to simulate how the peer handle query string response

func FromResultsIterator

func FromResultsIterator(rit statedb.ResultsIterator) (*AkcQueryIterator, error)

FromResultsIterator provides a way of converting ResultsIterator into StateQueryIterator

func (*AkcQueryIterator) Close

func (it *AkcQueryIterator) Close() error

func (*AkcQueryIterator) HasNext

func (it *AkcQueryIterator) HasNext() bool

func (*AkcQueryIterator) Length

func (it *AkcQueryIterator) Length() int

func (*AkcQueryIterator) Next

func (it *AkcQueryIterator) Next() (*queryresult.KV, error)

type CouchDBHandler

type CouchDBHandler struct {
	// contains filtered or unexported fields
}

CouchDBHandler holds 1 parameter: dbEngine: a VersionedDB object that is used by the chaincode to query. This is to guarantee that the test uses the same logic in interaction with stateDB as the chaincode. This also includes how chaincode builds its query to interact with the stateDB.

func NewCouchDBHandler

func NewCouchDBHandler(dbName string, isDrop bool) (*CouchDBHandler, error)

NewCouchDBHandler that is compatibles with previous release

func NewCouchDBHandlerWithConnection

func NewCouchDBHandlerWithConnection(dbName string, isDrop bool, connectionString string) (*CouchDBHandler, error)

NewCouchDBHandlerWithConnection that is compatibles with previous release

func NewCouchDBHandlerWithConnectionAuthentication

func NewCouchDBHandlerWithConnectionAuthentication(isDrop bool) (*CouchDBHandler, error)

NewCouchDBHandlerWithConnectionAuthentication returns a new CouchDBHandler and setup database for testing

func (*CouchDBHandler) QueryDocument

func (handler *CouchDBHandler) QueryDocument(query string) (statedb.ResultsIterator, error)

QueryDocument executes a query string and return results

func (*CouchDBHandler) QueryDocumentByRange

func (handler *CouchDBHandler) QueryDocumentByRange(startKey, endKey string) (statedb.ResultsIterator, error)

QueryDocumentByRange get a list of documents from couchDB by key range

func (*CouchDBHandler) QueryDocumentWithPagination

func (handler *CouchDBHandler) QueryDocumentWithPagination(query string, limit int32, bookmark string) (statedb.ResultsIterator, error)

QueryDocumentWithPagination executes a query string and return results

func (*CouchDBHandler) ReadDocument

func (handler *CouchDBHandler) ReadDocument(id string) ([]byte, error)

ReadDocument executes a query string and return results

func (*CouchDBHandler) SaveDocument

func (handler *CouchDBHandler) SaveDocument(key string, value []byte) error

SaveDocument stores a value in couchDB

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
)

type MockStubExtend

type MockStubExtend struct {
	CouchDB   bool            // if we use couchDB
	DbHandler *CouchDBHandler // if we use couchDB
	*MockStub
	// contains filtered or unexported fields
}

MockStubExtend provides composition class for MockStub as some of the mockstub methods are not implemented

func NewMockStubExtend

func NewMockStubExtend(stub *MockStub, c Chaincode) *MockStubExtend

NewMockStubExtend constructor

func (*MockStubExtend) GetFunctionAndParameters

func (stub *MockStubExtend) GetFunctionAndParameters() (function string, params []string)

GetFunctionAndParameters Override this function from MockStub

func (*MockStubExtend) GetQueryResult

func (stub *MockStubExtend) GetQueryResult(query string) (StateQueryIteratorInterface, error)

GetQueryResult overrides the same function in MockStub that did not implement anything.

func (*MockStubExtend) GetQueryResultWithPagination

func (stub *MockStubExtend) GetQueryResultWithPagination(query string, pageSize int32,
	bookmark string) (StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)

GetQueryResultWithPagination overrides the same function in MockStub that did not implement anything.

func (*MockStubExtend) GetState

func (stub *MockStubExtend) GetState(key string) ([]byte, error)

GetState retrieves the value for a given key from the ledger

func (*MockStubExtend) GetStateByPartialCompositeKey

func (stub *MockStubExtend) GetStateByPartialCompositeKey(objectType string, attributes []string) (StateQueryIteratorInterface, error)

GetStateByPartialCompositeKey queries couchdb by range

func (*MockStubExtend) GetStateOriginal

func (stub *MockStubExtend) GetStateOriginal(key string) ([]byte, error)

GetStateOriginal is copied from mockstub as we still need to carry on normal GetState operation with the mock ledger map

func (*MockStubExtend) GetStringArgs

func (stub *MockStubExtend) GetStringArgs() []string

GetStringArgs override this function from MockStub

func (*MockStubExtend) MockInit

func (stub *MockStubExtend) MockInit(uuid string, args [][]byte) pb.Response

MockInit Override this function from MockStub

func (*MockStubExtend) MockInvoke

func (stub *MockStubExtend) MockInvoke(uuid string, args [][]byte) pb.Response

MockInvoke Override this function from MockStub

func (*MockStubExtend) PutState

func (stub *MockStubExtend) PutState(key string, value []byte) error

PutState writes the specified `value` and `key` into the ledger.

func (*MockStubExtend) SetCouchDBConfiguration

func (stub *MockStubExtend) SetCouchDBConfiguration(handler *CouchDBHandler)

SetCouchDBConfiguration sets the couchdb configuration with appropriate database handler

Jump to

Keyboard shortcuts

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