Events and Rollbacks
‘Events’ refer to specific pieces of data that are generated within the contract and are recorded on the blockchain. Once an event occurs, all blockchain nodes can observe their corresponding data. ‘Rollbacks’ refer to the binding of methods of handling an ‘event’ in a contract. When a specific type of event is triggered, the corresponding binding method will be executed. The official wallet provides a default script rollback, which can also be customised by the user on a situational basis.
When the Citizen node executes a contract and triggers an event, it will package the event into a block, and broadcasts it onto the chain. When a smart contract is invoked at different time or under different external conditions, it may continue in different branches of the contract code and execute different code logic. For the invoker, the status of the contract execution is difficult to know. With the event mechanism, the user has the ability to known the status of the contract execution and hence obtain the result of the contract execution.
With this ability, the user can take relevant actions based on corresponding events they have received, such as re-initiating a transaction, initiating a contract invocation, or performing local actions (such as logging, database logging, making HTTP requests, and so on). Users can even make programs connected to the blockchain with decision-making ability, executing practical decisions and implementing different operations according to outcomes.