# EventsQuery

jigu.query.events.EventsQuery

A sequence of Event objects with additional querying capacities, usually for message events but can also be used for block events. For illustration, we will use the code example from Soju testnet:

from jigu import Terra
soju = Terra("soju-0013", "https://soju-lcd.terra.dev")

block = soju.block(1434376)
msgs = block.txs.msgs
events = msgs.events

# Sequence interoperability

EventsQuery[int, slice]

You can index or iterate an EventsQuery just as if it were a list of Event. If you take a slice, it will recursively return another EventsQuery.

events[0] # -> Event
events[0:5] # -> EventsQuery

for event in events:
    print(event.type)

# Select by type

EventsQuery.type
EventsQuery[type]

You can filter an EventsQuery by its type.

events.prevote # -> EventsQuery with only prevote type events
events["prevote"] # -> same EventsQuery
for prevote in events.prevote[5:]:
    prevote._pp

# Check for event type

You can check if the EventsQuery has a type you are interested in.

"prevote" in events # -> True

# Get all types

EventsQuery.types

You can see event types and their frequency.

print(events.types)
# {'message': 56, 'vote': 28, 'prevote': 28}
print(events[10:].types)
# {'message': 51, 'prevote': 27, 'vote': 24}
Updated on: 3/10/2020, 5:13:30 PM