-
Notifications
You must be signed in to change notification settings - Fork 11
/
event.go
70 lines (57 loc) 路 2.04 KB
/
event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// SPDX-FileCopyrightText: 2024 PK Lab AG <contact@pklab.io>
// SPDX-License-Identifier: MIT
package storage
import (
"context"
"time"
pkgTypes "github.com/celenium-io/celestia-indexer/pkg/types"
jsoniter "github.com/json-iterator/go"
"github.com/celenium-io/celestia-indexer/internal/storage/types"
"github.com/dipdup-net/indexer-sdk/pkg/storage"
"github.com/uptrace/bun"
)
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type EventFilter struct {
Limit int
Offset int
Time time.Time
}
//go:generate mockgen -source=$GOFILE -destination=mock/$GOFILE -package=mock -typed
type IEvent interface {
storage.Table[*Event]
ByTxId(ctx context.Context, txId uint64, fltrs EventFilter) ([]Event, error)
ByBlock(ctx context.Context, height pkgTypes.Level, fltrs EventFilter) ([]Event, error)
}
// Event -
type Event struct {
bun.BaseModel `bun:"event" comment:"Table with celestia events."`
Id uint64 `bun:"id,pk,notnull,autoincrement" comment:"Unique internal id"`
Height pkgTypes.Level `bun:"height,notnull" comment:"The number (height) of this block" stats:"func:min max,filterable"`
Time time.Time `bun:"time,pk,notnull" comment:"The time of block" stats:"func:min max,filterable"`
Position int64 `bun:"position" comment:"Position in transaction"`
Type types.EventType `bun:",type:event_type" comment:"Event type" stats:"filterable"`
TxId *uint64 `bun:"tx_id" comment:"Transaction id"`
Data map[string]any `bun:"data,type:jsonb,nullzero" comment:"Event data"`
}
// TableName -
func (Event) TableName() string {
return "event"
}
func (e Event) Columns() []string {
return []string{
"height", "time", "position", "type",
"tx_id", "data",
}
}
func (e Event) Flat() []any {
data := []any{
e.Height, e.Time, e.Position, e.Type, e.TxId, nil,
}
if len(e.Data) > 0 {
raw, err := json.MarshalToString(e.Data)
if err == nil {
data[5] = raw
}
}
return data
}