|
| 1 | +/* |
| 2 | +Copyright SecureKey Technologies Inc. All Rights Reserved. |
| 3 | +
|
| 4 | +SPDX-License-Identifier: Apache-2.0 |
| 5 | +*/ |
| 6 | + |
| 7 | +package apifabclient |
| 8 | + |
| 9 | +import ( |
| 10 | + cb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" |
| 11 | + pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" |
| 12 | +) |
| 13 | + |
| 14 | +// BlockEvent contains the data for the block event |
| 15 | +type BlockEvent struct { |
| 16 | + Block *cb.Block |
| 17 | +} |
| 18 | + |
| 19 | +// FilteredBlockEvent contains the data for a filtered block event |
| 20 | +type FilteredBlockEvent struct { |
| 21 | + FilteredBlock *pb.FilteredBlock |
| 22 | +} |
| 23 | + |
| 24 | +// TxStatusEvent contains the data for a transaction status event |
| 25 | +type TxStatusEvent struct { |
| 26 | + TxID string |
| 27 | + TxValidationCode pb.TxValidationCode |
| 28 | +} |
| 29 | + |
| 30 | +// CCEvent contains the data for a chaincode event |
| 31 | +type CCEvent struct { |
| 32 | + TxID string |
| 33 | + ChaincodeID string |
| 34 | + EventName string |
| 35 | +} |
| 36 | + |
| 37 | +// Registration is a handle that is returned from a successful RegisterXXXEvent. |
| 38 | +// This handle should be used in Unregister in order to unregister the event. |
| 39 | +type Registration interface{} |
| 40 | + |
| 41 | +// BlockFilter is a function that determines whether a Block event |
| 42 | +// should be ignored |
| 43 | +type BlockFilter func(block *cb.Block) bool |
| 44 | + |
| 45 | +// EventService is a service that receives events such as block, filtered block, |
| 46 | +// chaincode, and transaction status events. |
| 47 | +type EventService interface { |
| 48 | + // RegisterBlockEvent registers for block events. If the caller does not have permission |
| 49 | + // to register for block events then an error is returned. |
| 50 | + // Note that Unregister must be called when the registration is no longer needed. |
| 51 | + // - filter is an optional filter that filters out unwanted events. (Note: Only one filter may be specified.) |
| 52 | + // - Returns the registration and a channel that is used to receive events. The channel |
| 53 | + // is closed when Unregister is called. |
| 54 | + RegisterBlockEvent(filter ...BlockFilter) (Registration, <-chan *BlockEvent, error) |
| 55 | + |
| 56 | + // RegisterFilteredBlockEvent registers for filtered block events. |
| 57 | + // Note that Unregister must be called when the registration is no longer needed. |
| 58 | + // - Returns the registration and a channel that is used to receive events. The channel |
| 59 | + // is closed when Unregister is called. |
| 60 | + RegisterFilteredBlockEvent() (Registration, <-chan *FilteredBlockEvent, error) |
| 61 | + |
| 62 | + // RegisterChaincodeEvent registers for chaincode events. |
| 63 | + // Note that Unregister must be called when the registration is no longer needed. |
| 64 | + // - ccID is the chaincode ID for which events are to be received |
| 65 | + // - eventFilter is the chaincode event filter (regular expression) for which events are to be received |
| 66 | + // - Returns the registration and a channel that is used to receive events. The channel |
| 67 | + // is closed when Unregister is called. |
| 68 | + RegisterChaincodeEvent(ccID, eventFilter string) (Registration, <-chan *CCEvent, error) |
| 69 | + |
| 70 | + // RegisterTxStatusEvent registers for transaction status events. |
| 71 | + // Note that Unregister must be called when the registration is no longer needed. |
| 72 | + // - txID is the transaction ID for which events are to be received |
| 73 | + // - Returns the registration and a channel that is used to receive events. The channel |
| 74 | + // is closed when Unregister is called. |
| 75 | + RegisterTxStatusEvent(txID string) (Registration, <-chan *TxStatusEvent, error) |
| 76 | + |
| 77 | + // Unregister removes the given registration and closes the event channel. |
| 78 | + // - reg is the registration handle that was returned from one of the Register functions |
| 79 | + Unregister(reg Registration) |
| 80 | +} |
| 81 | + |
| 82 | +// EventClient is a client that connects to a peer and receives channel events |
| 83 | +// such as block, filtered block, chaincode, and transaction status events. |
| 84 | +type EventClient interface { |
| 85 | + EventService |
| 86 | + |
| 87 | + // Connect connects to the event server. |
| 88 | + Connect() error |
| 89 | + |
| 90 | + // Close closes the connection to the event server and releases all resources. |
| 91 | + // Once this function is invoked the client may no longer be used. |
| 92 | + Close() |
| 93 | +} |
0 commit comments