-
Notifications
You must be signed in to change notification settings - Fork 45
/
receipt.go
47 lines (36 loc) · 1.28 KB
/
receipt.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
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 Receipt struct {
Height int64 `pg:",pk,notnull,use_zero"` // note this is the height of the receipt not the message
Message string `pg:",pk,notnull"`
StateRoot string `pg:",pk,notnull"`
Idx int `pg:",use_zero"`
ExitCode int64 `pg:",use_zero"`
GasUsed int64 `pg:",use_zero"`
}
func (r *Receipt) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error {
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "receipts"))
stop := metrics.Timer(ctx, metrics.PersistDuration)
defer stop()
return s.PersistModel(ctx, r)
}
type Receipts []*Receipt
func (rs Receipts) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error {
if len(rs) == 0 {
return nil
}
ctx, span := global.Tracer("").Start(ctx, "Receipts.Persist", trace.WithAttributes(label.Int("count", len(rs))))
defer span.End()
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "receipts"))
stop := metrics.Timer(ctx, metrics.PersistDuration)
defer stop()
return s.PersistModel(ctx, rs)
}