Events
The implementation of Events is largely inspired by events in Solidity/Ethereum.
Accessing events
The events are stored in the contract call object and can be accessed by looking up the transaction in which they were emitted.
Let's consider the following Sophia example:
If we assume that emit_events
, was called in a transaction with transaction hash th_a5239bd8e3...
we can access it from the HTTP API /v2/transactions/th_a5239bd8e3.../info
:
First look at the data
field. For the first event it is <<"cb_Xfbg4g==">>
which decodes to <<>>
, i.e. no data (and that is expected since the event did not have any extra data.). For the second event we see <<"cb_VGhpcyBpcyBub3QgaW5kZXhlZK+w140=">>
which decodes to <<"This is not indexed">>
. For the topics
field we see that there is actually two values per event. The events only contain one value each, but there is one extra implicit topic added per event. This additional value is the Blake2b hash of the event constructor name, i.e. Blake2b("TheFirstEvent")
and Blake2b("AnotherEvent")
respectively:
The implicit value goes first in the topics
array. The topics are (currently, this might change in the future) presented as 256-bit unsigned integers - i.e. 1875564187002476023854543820981509249331367502514562901623081521315128929137
in the second event in the example corresponds to <<"ct_2pvLLjPfjq...">>
. A boolean argument would come out as 0
(= false) or 1
(= true).
Argument order
It is only possible to have one (1) string
parameter in the event, but it can be placed in any position (and its value will end up in the data
field), i.e.
would yield exactly the same result in the example above!
Event indexing
Finally it has to be pointed out that there is no indexing going on in the æternity node itself. One could imagine this being part of a middleware service, with a subscribe/notify interface or applications could be scraping the chain by other means.
Last updated