# MsgInfosQuery

jigu.query.msginfo.MsgInfosQuery

A sequence of MsgInfo objects with additional querying capacities, automatically generated from TxInfo and TxInfosQuery. 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

Our example has 28 MsgExchangeRatePrevotes and 28 MsgExchangeRateVotes.

# Sequence interoperability

MsgInfosQuery[int, slice]

You can index or iterate over a MsgInfosQuery just as if it were a list of MsgInfo. If you take a slice, it will recursively return another MsgInfosQuery.

msgs[0] # -> MsgInfo
msgs[0:5] # -> MsgInfosQuery

for msg in msgs:
    msg._pp

print(len(msgs))

# Filtering

# By type

MsgInfosQuery[type]

You can filter an MsgInfosQuery by its type.

prevote_msgs = msgs["oracle/MsgExchangeRatePrevote"]

for prevote_msg in prevote_msgs:
    print(prevote_msg.hash)

# By action

MsgInfosQuery[action_name]
MsgInfosQuery.action_name

Or by its action name (which is also available through dot attribute access).

# prevote_msgs = msgs["exchangerateprevote"]
prevote_msgs = msgs.exchangerateprevote # -> MsgInfosQuery

for prevote_msg in prevote_msgs:
    print(prevote_msg.hash)

# By message class

MsgInfosQuery[class]

Alternatively, if you do not know the correct values for type and action, you can directly use the message class.

from jigu.core.msg import MsgExchangeRatePrevote

prevote_msgs = msgs[MsgExchangeRatePrevote]

for prevote_msg in prevote_msgs:
    print(prevote_msg.hash)

# Check for a message type / action

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

"oracle/MsgExchangeRatePrevote" in msgs # -> True
"bank/MsgSend" in msgs # -> False
MsgExchangeRatePrevote in msgs # -> True
"send" in msgs # -> False

# Get all types / actions

MsgInfosQuery.types
MsgInfosQuery.actions

You can see message types / actions and their frequency.

print(msgs.types)
# {'oracle/MsgExchangeRateVote': 28, 'oracle/MsgExchangeRatePrevote': 28}
print(msgs[10:].actions)
# {'exchangeratevote': 22, 'exchangerateprevote': 24}

# Access events collectively

MsgInfosQuery.events

Normally, you would need to process each MsgInfo individually to access the aggregate of its events. MsgInfosQuery provides direct access to all the message's events.

for message in msgs.events.message:
    print(message.module[0]) # all oracle..

# Property Value

EventsQuery

Queryable sequence of all events from messages.

Updated on: 3/10/2020, 5:13:30 PM