Skip to content

Commit

Permalink
Merge pull request #1835 from CounterpartyXCP/apiv2
Browse files Browse the repository at this point in the history
Add events filter
  • Loading branch information
ouziel-slama authored May 30, 2024
2 parents ffcfd78 + b9f0755 commit 2d9f628
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions apiary.apib
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[//]: # (Generated by genapidoc.py on 2024-05-27 11:58:19.844640. Do not edit manually.)
[//]: # (Generated by genapidoc.py on 2024-05-30 14:29:26.222649. Do not edit manually.)
FORMAT: 1A
HOST: https://api.counterparty.io:4000

Expand Down Expand Up @@ -6023,11 +6023,13 @@ Returns the dispenses of a dispenser

## Group Events

### Get All Events [GET /v2/events{?cursor}{&limit}{&offset}{&verbose}]
### Get All Events [GET /v2/events{?event_name}{&cursor}{&limit}{&offset}{&verbose}]

Returns all events

+ Parameters
+ event_name: `CREDIT,DEBIT` (str, optional) - Comma separated list of events to return
+ Default: `None`
+ cursor: `10665092` (int, optional) - The last event index to return
+ Default: `None`
+ limit: `5` (int, optional) - The maximum number of events to return
Expand Down
9 changes: 8 additions & 1 deletion counterparty-core/counterpartycore/lib/api/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,23 @@ def get_transactions_by_block(
)


def get_all_events(db, cursor: int = None, limit: int = 100, offset: int = None):
def get_all_events(
db, event_name: str = None, cursor: int = None, limit: int = 100, offset: int = None
):
"""
Returns all events
:param str event_name: Comma separated list of events to return (e.g. CREDIT,DEBIT)
:param int cursor: The last event index to return (e.g. 10665092)
:param int limit: The maximum number of events to return (e.g. 5)
:param int offset: The number of lines to skip before returning results (overrides the `cursor` parameter)
"""
where = None
if event_name:
where = [{"event": event} for event in event_name.split(",")]
return select_rows(
db,
"messages",
where=where,
cursor_field="event_index",
last_cursor=cursor,
limit=limit,
Expand Down

0 comments on commit 2d9f628

Please sign in to comment.