-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
plugin.go
83 lines (72 loc) · 2.82 KB
/
plugin.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package median
import (
"encoding/json"
"time"
"github.com/smartcontractkit/chainlink/core/services/ocr2/plugins/median/config"
"github.com/smartcontractkit/libocr/commontypes"
"github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median"
ocr2types "github.com/smartcontractkit/libocr/offchainreporting2/types"
"github.com/smartcontractkit/chainlink/core/logger"
"github.com/smartcontractkit/chainlink/core/services/job"
"github.com/smartcontractkit/chainlink/core/services/ocr2/plugins"
"github.com/smartcontractkit/chainlink/core/services/ocrcommon"
"github.com/smartcontractkit/chainlink/core/services/pipeline"
"github.com/smartcontractkit/chainlink/core/services/relay/types"
)
// The Median struct holds parameters needed to run a Median plugin.
type Median struct {
jb job.Job
ocr2Provider types.OCR2ProviderCtx
pipelineRunner pipeline.Runner
runResults chan pipeline.Run
lggr logger.Logger
ocrLogger commontypes.Logger
pluginConfig config.PluginConfig
}
var _ plugins.OraclePlugin = &Median{}
// NewMedian parses the arguments and returns a new Median struct.
func NewMedian(jb job.Job, ocr2Provider types.OCR2ProviderCtx, pipelineRunner pipeline.Runner, runResults chan pipeline.Run, lggr logger.Logger, ocrLogger commontypes.Logger) (*Median, error) {
var pluginConfig config.PluginConfig
err := json.Unmarshal(jb.OCR2OracleSpec.PluginConfig.Bytes(), &pluginConfig)
if err != nil {
return &Median{}, err
}
err = config.ValidatePluginConfig(pluginConfig)
if err != nil {
return &Median{}, err
}
return &Median{
jb: jb,
ocr2Provider: ocr2Provider,
pipelineRunner: pipelineRunner,
runResults: runResults,
lggr: lggr,
ocrLogger: ocrLogger,
pluginConfig: pluginConfig,
}, nil
}
// GetPluginFactory return a median.NumericalMedianFactory.
func (m *Median) GetPluginFactory() (ocr2types.ReportingPluginFactory, error) {
juelsPerFeeCoinPipelineSpec := pipeline.Spec{
ID: m.jb.ID,
DotDagSource: m.pluginConfig.JuelsPerFeeCoinPipeline,
CreatedAt: time.Now(),
}
return median.NumericalMedianFactory{
ContractTransmitter: m.ocr2Provider.MedianContract(),
DataSource: ocrcommon.NewDataSourceV2(m.pipelineRunner,
m.jb,
*m.jb.PipelineSpec,
m.lggr,
m.runResults,
),
JuelsPerFeeCoinDataSource: ocrcommon.NewInMemoryDataSource(m.pipelineRunner, m.jb, juelsPerFeeCoinPipelineSpec, m.lggr),
ReportCodec: m.ocr2Provider.ReportCodec(),
Logger: m.ocrLogger,
}, nil
}
// GetServices return an empty Service slice because Median does not need any services besides the generic OCR2 ones
// supplied in the OCR2 delegate. This method exists to satisfy the plugins.OraclePlugin interface.
func (m *Median) GetServices() ([]job.ServiceCtx, error) {
return []job.ServiceCtx{}, nil
}