batch

package
v0.0.0-...-5522db4 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2021 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultAuthenticator

func DefaultAuthenticator(ctx contractapi.TransactionContextInterface, msg Msg) error

DefaultAuthenticator ...

func DefaultGetPeerTime

func DefaultGetPeerTime(stub shim.ChaincodeStubInterface) int64

DefaultGetPeerTime uses local clock in peer

Types

type Authenticator

type Authenticator func(ctx contractapi.TransactionContextInterface, msg Msg) error

Authenticator defines an authenticator that authenticates a given msg with a transaction context

type BatchContract

type BatchContract struct {
	Authenticator Authenticator
	FnRegistry    map[string]Fn

	// parameters for the batch algorithm
	TotalQueryLimit        uint32 // the value should be match `totalQueryLimit` in core.yaml
	MsgTimeGapAllowance    int64  // the value indicates current time window when Msg is submitted
	CommitTimeGapAllowance int64  // the value indicates current time window when Commit is executed

	// GetPeerTime returns current time on peer
	GetPeerTime func(stub shim.ChaincodeStubInterface) int64
}

BatchContract implements on-chain batch logic without trusted third party

func (*BatchContract) Commit

func (s *BatchContract) Commit(ctx contractapi.TransactionContextInterface, commitTime int64) (int64, error)

Commit executes Msg submitted between the last commit time and `commitTime`.

func (*BatchContract) GetIgnoredFunctions

func (s *BatchContract) GetIgnoredFunctions() []string

GetIgnoredFunctions implements contractapi.IgnoreContractInterface

func (*BatchContract) RegisterFn

func (s *BatchContract) RegisterFn(fnName string, fn Fn) error

RegisterFn registers a given function

func (*BatchContract) SubmitMsg

func (s *BatchContract) SubmitMsg(ctx contractapi.TransactionContextInterface, msg Msg, currentTime int64) error

SubmitMsg inserts Msg for a key with `currentTime` prefix Theses Msgs will be committed by the commit function.

type BatchState

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

BatchState manages a state in a batch execution

func NewBatchState

func NewBatchState(stub shim.ChaincodeStubInterface) *BatchState

NewBatchState returns a new BatchState

func (*BatchState) Apply

func (s *BatchState) Apply() error

Apply applies the committed state to the state DB

func (*BatchState) CommitMsg

func (s *BatchState) CommitMsg() error

CommitMsg commits the provisional state

func (*BatchState) CreateCompositeKey

func (s *BatchState) CreateCompositeKey(objectType string, attributes []string) (string, error)

CreateCompositeKey combines the given `attributes` to form a composite key. The objectType and attributes are expected to have only valid utf8 strings and should not contain U+0000 (nil byte) and U+10FFFF (biggest and unallocated code point). The resulting composite key can be used as the key in PutState().

func (*BatchState) DelPrivateData

func (s *BatchState) DelPrivateData(collection string, key string) error

DelPrivateData records the specified `key` to be deleted in the private writeset of the transaction. Note that only hash of the private writeset goes into the transaction proposal response (which is sent to the client who issued the transaction) and the actual private writeset gets temporarily stored in a transient store. The `key` and its value will be deleted from the collection when the transaction is validated and successfully committed.

func (*BatchState) DelState

func (s *BatchState) DelState(key string) error

DelState records the specified `key` to be deleted in the writeset of the transaction proposal. The `key` and its value will be deleted from the ledger when the transaction is validated and successfully committed.

func (*BatchState) GetArgs

func (s *BatchState) GetArgs() [][]byte

GetArgs returns the arguments intended for the chaincode Init and Invoke as an array of byte arrays.

func (*BatchState) GetArgsSlice

func (s *BatchState) GetArgsSlice() ([]byte, error)

GetArgsSlice returns the arguments intended for the chaincode Init and Invoke as a byte array

func (*BatchState) GetBinding

func (s *BatchState) GetBinding() ([]byte, error)

GetBinding returns the transaction binding, which is used to enforce a link between application data (like those stored in the transient field above) to the proposal itself. This is useful to avoid possible replay attacks.

func (*BatchState) GetChannelID

func (s *BatchState) GetChannelID() string

GetChannelID returns the channel the proposal is sent to for chaincode to process. This would be the channel_id of the transaction proposal (see https://godoc.org/github.com/hyperledger/fabric-protos-go/common#ChannelHeader ) except where the chaincode is calling another on a different channel.

func (*BatchState) GetCreator

func (s *BatchState) GetCreator() ([]byte, error)

GetCreator returns `SignatureHeader.Creator` (e.g. an identity) of the `SignedProposal`. This is the identity of the agent (or user) submitting the transaction.

func (*BatchState) GetDecorations

func (s *BatchState) GetDecorations() map[string][]byte

GetDecorations returns additional data (if applicable) about the proposal that originated from the peer. This data is set by the decorators of the peer, which append or mutate the chaincode input passed to the chaincode.

func (*BatchState) GetFunctionAndParameters

func (s *BatchState) GetFunctionAndParameters() (string, []string)

GetFunctionAndParameters returns the first argument as the function name and the rest of the arguments as parameters in a string array. Only use GetFunctionAndParameters if the client passes arguments intended to be used as strings.

func (*BatchState) GetHistoryForKey

func (s *BatchState) GetHistoryForKey(key string) (shim.HistoryQueryIteratorInterface, error)

GetHistoryForKey returns a history of key values across time. For each historic key update, the historic value and associated transaction id and timestamp are returned. The timestamp is the timestamp provided by the client in the proposal header. GetHistoryForKey requires peer configuration core.ledger.history.enableHistoryDatabase to be true. The query is NOT re-executed during validation phase, phantom reads are not detected. That is, other committed transactions may have updated the key concurrently, impacting the result set, and this would not be detected at validation/commit time. Applications susceptible to this should therefore not use GetHistoryForKey as part of transactions that update ledger, and should limit use to read-only chaincode operations.

func (*BatchState) GetPrivateData

func (s *BatchState) GetPrivateData(collection string, key string) ([]byte, error)

GetPrivateData returns the value of the specified `key` from the specified `collection`. Note that GetPrivateData doesn't read data from the private writeset, which has not been committed to the `collection`. In other words, GetPrivateData doesn't consider data modified by PutPrivateData that has not been committed.

func (*BatchState) GetPrivateDataByPartialCompositeKey

func (s *BatchState) GetPrivateDataByPartialCompositeKey(collection string, objectType string, keys []string) (shim.StateQueryIteratorInterface, error)

GetPrivateDataByPartialCompositeKey queries the state in a given private collection based on a given partial composite key. This function returns an iterator which can be used to iterate over all composite keys whose prefix matches the given partial composite key. The `objectType` and attributes are expected to have only valid utf8 strings and should not contain U+0000 (nil byte) and U+10FFFF (biggest and unallocated code point). See related functions SplitCompositeKey and CreateCompositeKey. Call Close() on the returned StateQueryIteratorInterface object when done. The query is re-executed during validation phase to ensure result set has not changed since transaction endorsement (phantom reads detected).

func (*BatchState) GetPrivateDataByRange

func (s *BatchState) GetPrivateDataByRange(collection string, startKey string, endKey string) (shim.StateQueryIteratorInterface, error)

GetPrivateDataByRange returns a range iterator over a set of keys in a given private collection. The iterator can be used to iterate over all keys between the startKey (inclusive) and endKey (exclusive). The keys are returned by the iterator in lexical order. Note that startKey and endKey can be empty string, which implies unbounded range query on start or end. Call Close() on the returned StateQueryIteratorInterface object when done. The query is re-executed during validation phase to ensure result set has not changed since transaction endorsement (phantom reads detected).

func (*BatchState) GetPrivateDataHash

func (s *BatchState) GetPrivateDataHash(collection string, key string) ([]byte, error)

GetPrivateDataHash returns the hash of the value of the specified `key` from the specified `collection`

func (*BatchState) GetPrivateDataQueryResult

func (s *BatchState) GetPrivateDataQueryResult(collection string, query string) (shim.StateQueryIteratorInterface, error)

GetPrivateDataQueryResult performs a "rich" query against a given private collection. It is only supported for state databases that support rich query, e.g.CouchDB. The query string is in the native syntax of the underlying state database. An iterator is returned which can be used to iterate (next) over the query result set. The query is NOT re-executed during validation phase, phantom reads are not detected. That is, other committed transactions may have added, updated, or removed keys that impact the result set, and this would not be detected at validation/commit time. Applications susceptible to this should therefore not use GetPrivateDataQueryResult as part of transactions that update ledger, and should limit use to read-only chaincode operations.

func (*BatchState) GetPrivateDataValidationParameter

func (s *BatchState) GetPrivateDataValidationParameter(collection string, key string) ([]byte, error)

GetPrivateDataValidationParameter retrieves the key-level endorsement policy for the private data specified by `key`. Note that this introduces a read dependency on `key` in the transaction's readset.

func (*BatchState) GetQueryResult

func (s *BatchState) GetQueryResult(query string) (shim.StateQueryIteratorInterface, error)

GetQueryResult performs a "rich" query against a state database. It is only supported for state databases that support rich query, e.g.CouchDB. The query string is in the native syntax of the underlying state database. An iterator is returned which can be used to iterate over all keys in the query result set. However, if the number of keys in the query result set is greater than the totalQueryLimit (defined in core.yaml), this iterator cannot be used to fetch all keys in the query result set (results will be limited by the totalQueryLimit). The query is NOT re-executed during validation phase, phantom reads are not detected. That is, other committed transactions may have added, updated, or removed keys that impact the result set, and this would not be detected at validation/commit time. Applications susceptible to this should therefore not use GetQueryResult as part of transactions that update ledger, and should limit use to read-only chaincode operations.

func (*BatchState) GetQueryResultWithPagination

func (s *BatchState) GetQueryResultWithPagination(query string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)

GetQueryResultWithPagination performs a "rich" query against a state database. It is only supported for state databases that support rich query, e.g., CouchDB. The query string is in the native syntax of the underlying state database. An iterator is returned which can be used to iterate over keys in the query result set. When an empty string is passed as a value to the bookmark argument, the returned iterator can be used to fetch the first `pageSize` of query results. When the bookmark is a non-emptry string, the iterator can be used to fetch the first `pageSize` keys between the bookmark and the last key in the query result. Note that only the bookmark present in a prior page of query results (ResponseMetadata) can be used as a value to the bookmark argument. Otherwise, an empty string must be passed as bookmark. This call is only supported in a read only transaction.

func (*BatchState) GetSignedProposal

func (s *BatchState) GetSignedProposal() (*pb.SignedProposal, error)

GetSignedProposal returns the SignedProposal object, which contains all data elements part of a transaction proposal.

func (*BatchState) GetState

func (s *BatchState) GetState(key string) ([]byte, error)

GetState returns the value of the specified `key` from the ledger. Note that GetState doesn't read data from the writeset, which has not been committed to the ledger. In other words, GetState doesn't consider data modified by PutState that has not been committed. If the key does not exist in the state database, (nil, nil) is returned.

func (*BatchState) GetStateByPartialCompositeKey

func (s *BatchState) GetStateByPartialCompositeKey(objectType string, keys []string) (shim.StateQueryIteratorInterface, error)

GetStateByPartialCompositeKey queries the state in the ledger based on a given partial composite key. This function returns an iterator which can be used to iterate over all composite keys whose prefix matches the given partial composite key. However, if the number of matching composite keys is greater than the totalQueryLimit (defined in core.yaml), this iterator cannot be used to fetch all matching keys (results will be limited by the totalQueryLimit). The `objectType` and attributes are expected to have only valid utf8 strings and should not contain U+0000 (nil byte) and U+10FFFF (biggest and unallocated code point). See related functions SplitCompositeKey and CreateCompositeKey. Call Close() on the returned StateQueryIteratorInterface object when done. The query is re-executed during validation phase to ensure result set has not changed since transaction endorsement (phantom reads detected).

func (*BatchState) GetStateByPartialCompositeKeyWithPagination

func (s *BatchState) GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)

GetStateByPartialCompositeKeyWithPagination queries the state in the ledger based on a given partial composite key. This function returns an iterator which can be used to iterate over the composite keys whose prefix matches the given partial composite key. When an empty string is passed as a value to the bookmark argument, the returned iterator can be used to fetch the first `pageSize` composite keys whose prefix matches the given partial composite key. When the bookmark is a non-emptry string, the iterator can be used to fetch the first `pageSize` keys between the bookmark (inclusive) and the last matching composite key. Note that only the bookmark present in a prior page of query result (ResponseMetadata) can be used as a value to the bookmark argument. Otherwise, an empty string must be passed as bookmark. The `objectType` and attributes are expected to have only valid utf8 strings and should not contain U+0000 (nil byte) and U+10FFFF (biggest and unallocated code point). See related functions SplitCompositeKey and CreateCompositeKey. Call Close() on the returned StateQueryIteratorInterface object when done. This call is only supported in a read only transaction.

func (*BatchState) GetStateByRange

func (s *BatchState) GetStateByRange(startKey string, endKey string) (shim.StateQueryIteratorInterface, error)

GetStateByRange returns a range iterator over a set of keys in the ledger. The iterator can be used to iterate over all keys between the startKey (inclusive) and endKey (exclusive). However, if the number of keys between startKey and endKey is greater than the totalQueryLimit (defined in core.yaml), this iterator cannot be used to fetch all keys (results will be capped by the totalQueryLimit). The keys are returned by the iterator in lexical order. Note that startKey and endKey can be empty string, which implies unbounded range query on start or end. Call Close() on the returned StateQueryIteratorInterface object when done. The query is re-executed during validation phase to ensure result set has not changed since transaction endorsement (phantom reads detected).

func (*BatchState) GetStateByRangeWithPagination

func (s *BatchState) GetStateByRangeWithPagination(startKey string, endKey string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error)

GetStateByRangeWithPagination returns a range iterator over a set of keys in the ledger. The iterator can be used to fetch keys between the startKey (inclusive) and endKey (exclusive). When an empty string is passed as a value to the bookmark argument, the returned iterator can be used to fetch the first `pageSize` keys between the startKey (inclusive) and endKey (exclusive). When the bookmark is a non-emptry string, the iterator can be used to fetch the first `pageSize` keys between the bookmark (inclusive) and endKey (exclusive). Note that only the bookmark present in a prior page of query results (ResponseMetadata) can be used as a value to the bookmark argument. Otherwise, an empty string must be passed as bookmark. The keys are returned by the iterator in lexical order. Note that startKey and endKey can be empty string, which implies unbounded range query on start or end. Call Close() on the returned StateQueryIteratorInterface object when done. This call is only supported in a read only transaction.

func (*BatchState) GetStateValidationParameter

func (s *BatchState) GetStateValidationParameter(key string) ([]byte, error)

GetStateValidationParameter retrieves the key-level endorsement policy for `key`. Note that this will introduce a read dependency on `key` in the transaction's readset.

func (*BatchState) GetStringArgs

func (s *BatchState) GetStringArgs() []string

GetStringArgs returns the arguments intended for the chaincode Init and Invoke as a string array. Only use GetStringArgs if the client passes arguments intended to be used as strings.

func (*BatchState) GetTransient

func (s *BatchState) GetTransient() (map[string][]byte, error)

GetTransient returns the `ChaincodeProposalPayload.Transient` field. It is a map that contains data (e.g. cryptographic material) that might be used to implement some form of application-level confidentiality. The contents of this field, as prescribed by `ChaincodeProposalPayload`, are supposed to always be omitted from the transaction and excluded from the ledger.

func (*BatchState) GetTxID

func (s *BatchState) GetTxID() string

GetTxID returns the tx_id of the transaction proposal, which is unique per transaction and per client. See https://godoc.org/github.com/hyperledger/fabric-protos-go/common#ChannelHeader for further details.

func (*BatchState) GetTxTimestamp

func (s *BatchState) GetTxTimestamp() (*timestamp.Timestamp, error)

GetTxTimestamp returns the timestamp when the transaction was created. This is taken from the transaction ChannelHeader, therefore it will indicate the client's timestamp and will have the same value across all endorsers.

func (*BatchState) InvokeChaincode

func (s *BatchState) InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response

InvokeChaincode locally calls the specified chaincode `Invoke` using the same transaction context; that is, chaincode calling chaincode doesn't create a new transaction message. If the called chaincode is on the same channel, it simply adds the called chaincode read set and write set to the calling transaction. If the called chaincode is on a different channel, only the Response is returned to the calling chaincode; any PutState calls from the called chaincode will not have any effect on the ledger; that is, the called chaincode on a different channel will not have its read set and write set applied to the transaction. Only the calling chaincode's read set and write set will be applied to the transaction. Effectively the called chaincode on a different channel is a `Query`, which does not participate in state validation checks in subsequent commit phase. If `channel` is empty, the caller's channel is assumed.

func (*BatchState) PutPrivateData

func (s *BatchState) PutPrivateData(collection string, key string, value []byte) error

PutPrivateData puts the specified `key` and `value` into the transaction's private writeset. Note that only hash of the private writeset goes into the transaction proposal response (which is sent to the client who issued the transaction) and the actual private writeset gets temporarily stored in a transient store. PutPrivateData doesn't effect the `collection` until the transaction is validated and successfully committed. Simple keys must not be an empty string and must not start with a null character (0x00) in order to avoid range query collisions with composite keys, which internally get prefixed with 0x00 as composite key namespace. In addition, if using CouchDB, keys can only contain valid UTF-8 strings and cannot begin with an an underscore ("_").

func (*BatchState) PutState

func (s *BatchState) PutState(key string, value []byte) error

PutState puts the specified `key` and `value` into the transaction's writeset as a data-write proposal. PutState doesn't effect the ledger until the transaction is validated and successfully committed. Simple keys must not be an empty string and must not start with a null character (0x00) in order to avoid range query collisions with composite keys, which internally get prefixed with 0x00 as composite key namespace. In addition, if using CouchDB, keys can only contain valid UTF-8 strings and cannot begin with an underscore ("_").

func (*BatchState) RevertMsg

func (s *BatchState) RevertMsg() error

RevertMsg discards the provisional state

func (*BatchState) SetEvent

func (s *BatchState) SetEvent(name string, payload []byte) error

SetEvent allows the chaincode to set an event on the response to the proposal to be included as part of a transaction. The event will be available within the transaction in the committed block regardless of the validity of the transaction.

func (*BatchState) SetPrivateDataValidationParameter

func (s *BatchState) SetPrivateDataValidationParameter(collection string, key string, ep []byte) error

SetPrivateDataValidationParameter sets the key-level endorsement policy for the private data specified by `key`.

func (*BatchState) SetStateValidationParameter

func (s *BatchState) SetStateValidationParameter(key string, ep []byte) error

SetStateValidationParameter sets the key-level endorsement policy for `key`.

func (*BatchState) SplitCompositeKey

func (s *BatchState) SplitCompositeKey(compositeKey string) (string, []string, error)

SplitCompositeKey splits the specified key into attributes on which the composite key was formed. Composite keys found during range queries or partial composite key queries can therefore be split into their composite parts.

type Fn

type Fn func(ctx contractapi.TransactionContextInterface, args [][]byte) error

Fn defines a function to process Msg

type Msg

type Msg struct {
	Fn   string
	Args [][]byte
}

Msg is a chaincode invocation

func (Msg) Validate

func (msg Msg) Validate() error

Validate validates the msg

Jump to

Keyboard shortcuts

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