credmark.cmf.types.ledger_contract.LedgerQueryContractEvents
- class LedgerQueryContractEvents(**kwargs)[source]
Bases:
ContractEventsTable
,ContractEntityQuery
Methods
as_
describe
field
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
Return the set of column names in the table.
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
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