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}
orcontract.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 fromcontract.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
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
columns (Optional[Union[List[str], List[ColumnField]]]) – The columns list should be built from
ContractLedger.Functions.Columns
and function input columns usingContractLedger.Functions.InputCol('input-name')
(whereinput-name
is the name of an input for the particular contract function.) For events, useContractLedger.Events.Columns
andContractLedger.Events.InputCol()
.aggregates (Optional[List[Tuple[str, str]]]) – The aggregates list should be built from
ContractLedger.Aggregate()
calls where the expression contains an SQL function (ex. MAX, SUM etc.) and column names as described for thecolumns
parameter.where (Optional[str]) – The where portion of an SQL query (without the word WHERE.) The column names are as described for the
columns
parameter. Aggregate column names must be in double-quotes.group_by (Optional[Union[List[str], List[ColumnField]]]) – The “group by” portion of an SQL query (without the words “GROUP BY”.) The column names are as described for the
columns
parameter. Aggregate column names must be in double-quotes.order_by (Optional[Union[str, ColumnField]]) – The “order by” portion of an SQL query (without the words “ORDER BY”.) The column names are as described for the
columns
parameter. Aggregate column names must be in double-quotes.having (Optional[str]) – The “having” portion of an SQL query (without the word “HAVING”.) The column names are as described for the
columns
parameter. Aggregate column names must be in double-quotes.limit (Optional[int]) – The “limit” portion of an SQL query (without the word “LIMIT”.) Typically this can be an integer as a string.
offset (Optional[int]) – The “offset” portion of an SQL query (without the word “OFFSET”.) Typically this can be an integer as a string.
joins (Optional[list[Union[tuple[credmark.cmf.types.ledger.JoinType, credmark.cmf.types.ledger.LedgerTable, str], tuple[credmark.cmf.types.ledger.LedgerTable, str], tuple[credmark.cmf.types.ledger.JoinType, credmark.cmf.types.ledger.LedgerTable, credmark.cmf.types.ledger.ColumnField], tuple[credmark.cmf.types.ledger.LedgerTable, credmark.cmf.types.ledger.ColumnField]]]]) –
- 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 usingContractLedger.Functions.Columns
,ContractLedger.Functions.InputCol('...')
, and aggregate columns names.- Return type
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