-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e20511d
commit 5080c48
Showing
5 changed files
with
252 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/hashicorp/go-plugin" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/loop" | ||
) | ||
|
||
const ( | ||
loggerName = "PluginMercury" | ||
) | ||
|
||
func main() { | ||
s := loop.MustNewStartedServer(loggerName) | ||
defer s.Stop() | ||
|
||
p := NewPlugin(s.Logger) | ||
defer s.Logger.ErrorIfFn(p.Close, "Failed to close") | ||
|
||
s.MustRegister(p) | ||
|
||
stop := make(chan struct{}) | ||
defer close(stop) | ||
|
||
plugin.Serve(&plugin.ServeConfig{ | ||
HandshakeConfig: loop.PluginMercuryHandshakeConfig(), | ||
Plugins: map[string]plugin.Plugin{ | ||
loop.PluginMercuryName: &loop.GRPCPluginMercury{ | ||
PluginServer: p, | ||
BrokerConfig: loop.BrokerConfig{ | ||
StopCh: stop, | ||
Logger: s.Logger, | ||
GRPCOpts: s.GRPCOpts, | ||
}, | ||
}, | ||
}, | ||
GRPCServer: s.GRPCOpts.NewServer, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/logger" | ||
"github.com/smartcontractkit/chainlink-common/pkg/loop" | ||
"github.com/smartcontractkit/chainlink-common/pkg/services" | ||
"github.com/smartcontractkit/chainlink-common/pkg/types" | ||
v1 "github.com/smartcontractkit/chainlink-common/pkg/types/mercury/v1" | ||
v2 "github.com/smartcontractkit/chainlink-common/pkg/types/mercury/v2" | ||
v3 "github.com/smartcontractkit/chainlink-common/pkg/types/mercury/v3" | ||
ds_v1 "github.com/smartcontractkit/chainlink-data-streams/mercury/v1" | ||
ds_v2 "github.com/smartcontractkit/chainlink-data-streams/mercury/v2" | ||
ds_v3 "github.com/smartcontractkit/chainlink-data-streams/mercury/v3" | ||
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" | ||
) | ||
|
||
type Plugin struct { | ||
loop.Plugin | ||
stop services.StopChan | ||
} | ||
|
||
func NewPlugin(lggr logger.Logger) *Plugin { | ||
return &Plugin{Plugin: loop.Plugin{Logger: lggr}, stop: make(services.StopChan)} | ||
} | ||
|
||
func (p *Plugin) NewMercuryV1Factory(ctx context.Context, provider types.MercuryProvider, dataSource v1.DataSource) (types.MercuryPluginFactory, error) { | ||
Check failure on line 28 in cmd/datastreams/plugin.go GitHub Actions / lint
|
||
var ctxVals loop.ContextValues | ||
ctxVals.SetValues(ctx) | ||
lggr := logger.With(p.Logger, ctxVals.Args()...) | ||
|
||
factory := ds_v1.NewFactory(dataSource, lggr, provider.OnchainConfigCodec(), provider.ReportCodecV1()) | ||
|
||
s := &mercuryPluginFactoryService{lggr: logger.Named(lggr, "MercuryV1PluginFactory"), MercuryPluginFactory: factory} | ||
|
||
p.SubService(s) | ||
|
||
return s, nil | ||
} | ||
|
||
func (p *Plugin) NewMercuryV2Factory(ctx context.Context, provider types.MercuryProvider, dataSource v2.DataSource) (types.MercuryPluginFactory, error) { | ||
Check failure on line 42 in cmd/datastreams/plugin.go GitHub Actions / lint
|
||
var ctxVals loop.ContextValues | ||
ctxVals.SetValues(ctx) | ||
lggr := logger.With(p.Logger, ctxVals.Args()...) | ||
|
||
factory := ds_v2.NewFactory(dataSource, lggr, provider.OnchainConfigCodec(), provider.ReportCodecV2()) | ||
|
||
s := &mercuryPluginFactoryService{lggr: logger.Named(lggr, "MercuryV2PluginFactory"), MercuryPluginFactory: factory} | ||
|
||
p.SubService(s) | ||
|
||
return s, nil | ||
} | ||
|
||
func (p *Plugin) NewMercuryV3Factory(ctx context.Context, provider types.MercuryProvider, dataSource v3.DataSource) (types.MercuryPluginFactory, error) { | ||
Check failure on line 56 in cmd/datastreams/plugin.go GitHub Actions / lint
|
||
var ctxVals loop.ContextValues | ||
ctxVals.SetValues(ctx) | ||
lggr := logger.With(p.Logger, ctxVals.Args()...) | ||
|
||
factory := ds_v3.NewFactory(dataSource, lggr, provider.OnchainConfigCodec(), provider.ReportCodecV3()) | ||
|
||
s := &mercuryPluginFactoryService{lggr: logger.Named(lggr, "MercuryV3PluginFactory"), MercuryPluginFactory: factory} | ||
|
||
p.SubService(s) | ||
|
||
return s, nil | ||
} | ||
|
||
type mercuryPluginFactoryService struct { | ||
services.StateMachine | ||
lggr logger.Logger | ||
ocr3types.MercuryPluginFactory | ||
} | ||
|
||
func (r *mercuryPluginFactoryService) Name() string { return r.lggr.Name() } | ||
|
||
func (r *mercuryPluginFactoryService) Start(ctx context.Context) error { | ||
return r.StartOnce("ReportingPluginFactory", func() error { return nil }) | ||
} | ||
|
||
func (r *mercuryPluginFactoryService) Close() error { | ||
return r.StopOnce("ReportingPluginFactory", func() error { return nil }) | ||
} | ||
|
||
func (r *mercuryPluginFactoryService) HealthReport() map[string]error { | ||
return map[string]error{r.Name(): r.Healthy()} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters