-
Notifications
You must be signed in to change notification settings - Fork 45
/
message.go
53 lines (41 loc) · 1.35 KB
/
message.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
package messages
import (
"context"
"go.opencensus.io/tag"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/label"
"github.com/filecoin-project/sentinel-visor/metrics"
"github.com/filecoin-project/sentinel-visor/model"
)
type Message struct {
Height int64 `pg:",pk,notnull,use_zero"`
Cid string `pg:",pk,notnull"`
From string `pg:",notnull"`
To string `pg:",notnull"`
Value string `pg:",notnull"`
GasFeeCap string `pg:",notnull"`
GasPremium string `pg:",notnull"`
GasLimit int64 `pg:",use_zero"`
SizeBytes int `pg:",use_zero"`
Nonce uint64 `pg:",use_zero"`
Method uint64 `pg:",use_zero"`
}
func (m *Message) Persist(ctx context.Context, s model.StorageBatch) error {
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "messages"))
stop := metrics.Timer(ctx, metrics.PersistDuration)
defer stop()
return s.PersistModel(ctx, m)
}
type Messages []*Message
func (ms Messages) Persist(ctx context.Context, s model.StorageBatch) error {
if len(ms) == 0 {
return nil
}
ctx, span := global.Tracer("").Start(ctx, "Messages.Persist", trace.WithAttributes(label.Int("count", len(ms))))
defer span.End()
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "messages"))
stop := metrics.Timer(ctx, metrics.PersistDuration)
defer stop()
return s.PersistModel(ctx, ms)
}