Skip to content

0Chain Events

Piers Shepperson edited this page Jan 27, 2022 · 5 revisions

Events

Events are data packets that can be emitted by smart contracts. They work in much the same way as Ethereum events

Once an event is emitted from a smart contract, it is forgotten by the blockchain which can no longer access the event. Instead, the event is logged into the event database.

image

image

The event database is a postgreSQL attached to the sharder.

Events

An event takes the following form

	BlockNumber int64  
	TxHash      string 
	Type        int   
	Tag         int    
	Index       string 
	Data        string 

There are five searchable fields, plus one data field.

  • blockNumber: The block number that contains the transaction that emitted the event
  • txHash: The hash of the transaction that emitted the event.
  • Type: Information about how the EventDb is to process the event. TypeStats indicates the event contains instructions to modify an Event database table. Other events currently are given no special treatment.
  • Tag: Further information on the event and how to interpret the data field. Typically indicates what modification to which table. Is the data a marshalled object to be added or the id of a row to be removed?
  • Index: This is used to identify events. So events are uniquely defined by txhash and Index. So all but one copy of an event are discarded.
  • Data: Information packet. For example, a json marshalled object to be added to an event database table.

Event Table

All events are added to an event table, searchable on BlockNumber, TxHash, Type, Tag and Index.

There is a zwallet command events for viewing this database table.

./zwallet events --filters "txHash, Type" --values "d0939e912851959637257573b08c748474f0dd0ebbc8e191e4f6ad69e4fdc7ac, 1" 

Where 1 indicates event.TypeError. This should return any error produced by the transaction with hash "d0939e912851959637257573b08c748474f0dd0ebbc8e191e4f6ad69e4fdc7ac"

Blobber Table

Contains all the active blobbers. Used for the \getBlobber and the \getBlobbers endpoints.

Other tables will be added in due course.

Errors

Any transaction that fails, will have emitted events cancelled and replaced with one TypeError event. This event can be queried later from the event database.

Proposed Event database structure

image