-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathevents.go
66 lines (60 loc) · 1.51 KB
/
events.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
package web3
import (
"context"
"time"
"github.com/lilypad-tech/lilypad/pkg/system"
"github.com/rs/zerolog/log"
)
type EventChannels struct {
Token *TokenEventChannels
Payment *PaymentEventChannels
Storage *StorageEventChannels
JobCreator *JobCreatorEventChannels
Mediation *MediationEventChannels
Pow *PowEventChannels
collections []EventChannelCollection
}
func NewEventChannels() *EventChannels {
tokenChannels := NewTokenEventChannels()
paymentChannels := NewPaymentEventChannels()
storageChannels := NewStorageEventChannels()
jobCreatorChannels := NewJobCreatorEventChannels()
mediationChannels := NewMediationEventChannels()
powChannels := NewPowEventChannels()
collections := []EventChannelCollection{
tokenChannels,
paymentChannels,
storageChannels,
jobCreatorChannels,
mediationChannels,
powChannels,
}
return &EventChannels{
Token: tokenChannels,
Payment: paymentChannels,
Storage: storageChannels,
JobCreator: jobCreatorChannels,
Mediation: mediationChannels,
Pow: powChannels,
collections: collections,
}
}
func (eventChannels *EventChannels) Start(
sdk *Web3SDK,
ctx context.Context,
cm *system.CleanupManager,
) error {
for _, collection := range eventChannels.collections {
c := collection
go func() {
for {
err := c.Start(sdk, ctx, cm)
if err != nil {
log.Error().Msgf("error starting listeners: %s reconnect in 2 seconds", err.Error())
}
time.Sleep(time.Second * 2)
}
}()
}
return nil
}