Class: ContractEventListener

fabric-network. ContractEventListener

The Contract Event Listener handles contract events from the chaincode.

new ContractEventListener(contract, listenerName, eventName, eventCallback, options)

Constructor.
Parameters:
Name Type Description
contract Contract The contract instance
listenerName string a unique name identifying the listener
eventName string The name of the contract event being listened for
eventCallback function The event callback called when an event is received. It has signature (err, BlockEvent, blockNumber, transactionId)
options module:fabric-network.Network~ListenerOptions

Methods


<async> _onError(error)

This callback is triggered when the event was unsuccessful. If the error indicates that the event hub shutdown and the listener is still registered, it updates the EventHubSelectionStrategy status of event hubs (if implemented) and finds a new event hub to connect to
Parameters:
Name Type Description
error Error The error emitted

<async> _onEvent(event, blockNumber, transactionId, status [, expectedNumber])

The callback triggered when the event was successful. Checkpoints the last block and transaction seen once the callback has run and unregisters the listener if the unregister flag was provided
Parameters:
Name Type Argument Description
event ChaincodeEvent the event emitted
blockNumber String the block number this transaction was committed inside
transactionId string the transaction ID of the transaction this event was emitted by
status string the status of the the transaction
expectedNumber string <optional>
the expected number of events from the block

<async> register()

Finds and connects to an event hub then creates the listener registration

unregister()

Unregisters the registration from the event hub