-
Notifications
You must be signed in to change notification settings - Fork 3
/
db_wrapper.go
46 lines (37 loc) · 1.04 KB
/
db_wrapper.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
package p2p
import (
"context"
"time"
"github.com/InjectiveLabs/chainlink-injective/db"
"github.com/InjectiveLabs/chainlink-injective/db/model"
)
var _ DiscovererDatabase = &announceDBWrapper{}
type announceDBWrapper struct {
svc db.JobDBService
}
func NewAnnounceDBWrapper(dbSvc db.JobDBService) DiscovererDatabase {
return &announceDBWrapper{
svc: dbSvc,
}
}
func (j *announceDBWrapper) StoreAnnouncement(ctx context.Context, peerID string, ann []byte) error {
return j.svc.UpsertAnnouncement(ctx, &model.JobPeerAnnouncement{
JobID: j.svc.JobID(),
PeerID: model.ID(peerID),
Announce: ann,
CreatedAt: time.Now().UTC(),
})
}
func (j *announceDBWrapper) ReadAnnouncements(ctx context.Context, peerIDs []string) (map[string][]byte, error) {
announcements, err := j.svc.ListAnnouncements(ctx, peerIDs, &model.Cursor{
Limit: 10000,
})
if err != nil {
return nil, err
}
result := make(map[string][]byte, len(announcements))
for _, ann := range announcements {
result[string(ann.PeerID)] = ann.Announce
}
return result, nil
}