Skip to content

Commit b32efef

Browse files
committed
tapdb: add support for timestamp range filter in QueryEventIDs
1 parent 961f5b8 commit b32efef

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

address/event.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ type EventQueryParams struct {
6060
// (inclusive). Can be set to nil to return events of all creation
6161
// times.
6262
CreationTimeFrom *time.Time
63+
64+
// CreationTimeTo is the latest creation time to query for
65+
// (inclusive). Can be set to nil to return events of all creation
66+
// times.
67+
CreationTimeTo *time.Time
6368
}
6469

6570
// AssetOutput holds the information about a single asset output that was sent

tapdb/addrs.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -990,9 +990,10 @@ func (t *TapAddressBook) QueryAddrEvents(
990990
error) {
991991

992992
sqlQuery := AddrEventQuery{
993-
StatusFrom: int16(address.StatusTransactionDetected),
994-
StatusTo: int16(address.StatusCompleted),
995-
CreatedAfter: time.Unix(0, 0).UTC(),
993+
StatusFrom: int16(address.StatusTransactionDetected),
994+
StatusTo: int16(address.StatusCompleted),
995+
CreatedAfter: time.Unix(0, 0).UTC(),
996+
CreatedBefore: time.Now().UTC(),
996997
}
997998
if len(params.AddrTaprootOutputKey) > 0 {
998999
sqlQuery.AddrTaprootKey = params.AddrTaprootOutputKey
@@ -1006,6 +1007,13 @@ func (t *TapAddressBook) QueryAddrEvents(
10061007
if params.CreationTimeFrom != nil && !params.CreationTimeFrom.IsZero() {
10071008
sqlQuery.CreatedAfter = params.CreationTimeFrom.UTC()
10081009
}
1010+
if params.CreationTimeTo != nil && !params.CreationTimeTo.IsZero() {
1011+
sqlQuery.CreatedBefore = params.CreationTimeTo.UTC()
1012+
}
1013+
if sqlQuery.CreatedAfter.After(sqlQuery.CreatedBefore) {
1014+
return nil, fmt.Errorf("created after time after " +
1015+
"created before time")
1016+
}
10091017

10101018
var (
10111019
readTxOpts = NewAssetStoreReadTx()

tapdb/sqlc/addrs.sql.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tapdb/sqlc/queries/addrs.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ WHERE addr_events.status >= @status_from
226226
AND addr_events.status <= @status_to
227227
AND COALESCE(@addr_taproot_key, addrs.taproot_output_key) = addrs.taproot_output_key
228228
AND addr_events.creation_time >= @created_after
229+
AND addr_events.creation_time <= @created_before
229230
ORDER by addr_events.creation_time;
230231

231232
-- name: QueryLastEventHeight :one

0 commit comments

Comments
 (0)