/
mercury_config_provider.go
44 lines (36 loc) · 1.46 KB
/
mercury_config_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
package evm
import (
"errors"
"fmt"
"github.com/ethereum/go-ethereum/common"
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types"
)
func newMercuryConfigProvider(lggr logger.Logger, chain legacyevm.Chain, opts *types.RelayOpts) (commontypes.ConfigProvider, error) {
if !common.IsHexAddress(opts.ContractID) {
return nil, errors.New("invalid contractID, expected hex address")
}
aggregatorAddress := common.HexToAddress(opts.ContractID)
relayConfig, err := opts.RelayConfig()
if err != nil {
return nil, fmt.Errorf("failed to get relay config: %w", err)
}
if relayConfig.FeedID == nil {
return nil, errors.New("feed ID is required for tracking config on mercury contracts")
}
cp, err := mercury.NewConfigPoller(
lggr.Named(relayConfig.FeedID.String()),
chain.LogPoller(),
aggregatorAddress,
*relayConfig.FeedID,
// TODO: Does mercury need to support config contract? DF-19182
)
if err != nil {
return nil, err
}
offchainConfigDigester := mercury.NewOffchainConfigDigester(*relayConfig.FeedID, chain.Config().EVM().ChainID(), aggregatorAddress)
return newConfigWatcher(lggr, aggregatorAddress, offchainConfigDigester, cp, chain, relayConfig.FromBlock, opts.New), nil
}