credmark.cmf.types.ledger_contract.ContractEntityQuery

class ContractEntityQuery(**kwargs)[source]

Bases: LedgerQueryBase

Used by ContractLedger to query a contract’s function or event data. You do not need to create an instance yourself.

Access an instance with contract.ledger.functions.{NameOfFunction} or contract.ledger.events.{NameOfEvent}. The name of the function or event can be auto-completed by pressing TAB after the .. Alternatively, you could looked the name of the function/event up from contract.abi.functions or contract.abi.events.

See the select() method below for the query parameters.

Parameters
  • address – Contract address

  • entity_type – Type of entity: functions or events

  • name – Name of function or event

Methods

field

select

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

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)[source]

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