-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
upkeep_provider.go
50 lines (41 loc) · 1.31 KB
/
upkeep_provider.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
package evm
import (
"context"
"fmt"
ocr2keepers "github.com/smartcontractkit/ocr2keepers/pkg/v3/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evm21/core"
)
var _ ocr2keepers.ConditionalUpkeepProvider = &upkeepProvider{}
type upkeepProvider struct {
activeUpkeeps ActiveUpkeepList
bs *BlockSubscriber
lp logpoller.LogPoller
}
func NewUpkeepProvider(activeUpkeeps ActiveUpkeepList, bs *BlockSubscriber, lp logpoller.LogPoller) *upkeepProvider {
return &upkeepProvider{
activeUpkeeps: activeUpkeeps,
bs: bs,
lp: lp,
}
}
func (p *upkeepProvider) GetActiveUpkeeps(ctx context.Context) ([]ocr2keepers.UpkeepPayload, error) {
latestBlock := p.bs.latestBlock.Load()
if latestBlock == nil {
return nil, fmt.Errorf("no latest block found when fetching active upkeeps")
}
var payloads []ocr2keepers.UpkeepPayload
for _, uid := range p.activeUpkeeps.View(ocr2keepers.ConditionTrigger) {
payload, err := core.NewUpkeepPayload(
uid,
ocr2keepers.NewTrigger(ocr2keepers.BlockNumber(latestBlock.Number), latestBlock.Hash),
nil,
)
if err != nil {
// skip invalid payloads
continue
}
payloads = append(payloads, payload)
}
return payloads, nil
}