credmark.cmf.types.ledger_contract.LedgerQueryContractEvents

class LedgerQueryContractEvents(**kwargs)[source]

Bases: ContractEventsTable, ContractEntityQuery

Methods

as_

describe

field

select

Run a query on a contract's function or event data.

Attributes

BLOCK_NUMBER

BLOCK_TIMESTAMP

CONTRACT_ADDRESS

LOG_INDEX

SIGNATURE

TXN_HASH

alias

bigint_cols

colnames

Return the set of column names in the table.

columns

Return the set of column names for the table.

table_key

property colnames: List[str]

Return the set of column names in the table. They can be used in the query.

property columns: List[str]

Return the set of column names for the table. They will be used in the database.

For contract ledger tables, the set will include all contract-specific columns.

select(columns=None, joins=None, where=None, group_by=None, order_by=None, limit=None, offset=None, aggregates=None, having=None, bigint_cols=None, analytics_mode=None)

Run a query on a contract’s function or event data.

Parameters
Returns

An object with a data property which is a list of dicts, each dict holding a row with the keys being the column names. The column names can be referenced using ContractLedger.Functions.Columns, ContractLedger.Functions.InputCol('...'), and aggregate columns names.

Return type

LedgerModelOutput

Example usage:

contract = Contract(address='0x3a3a65aab0dd2a17e3f1947ba16138cd37d08c04')

with contract.ledger.functions.approve as q:
    ret = q.select(
        aggregates=[(q.VALUE.max_(), 'max_value')],
        group_by=[q.SPENDER],
        order_by=q.field('max_value').dquote().desc(),
        limit=5)
# ret.data contains a list of row dicts, keyed by column name