-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
target.go
84 lines (70 loc) · 2.68 KB
/
target.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
84
package remote
import (
"context"
"errors"
commoncap "github.com/smartcontractkit/chainlink-common/pkg/capabilities"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/remote/types"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)
// remoteTargetCaller/Receiver are shims translating between capability API calls and network messages
type remoteTargetCaller struct {
capInfo commoncap.CapabilityInfo
donInfo *types.DON
dispatcher types.Dispatcher
lggr logger.Logger
}
var _ commoncap.TargetCapability = &remoteTargetCaller{}
var _ types.Receiver = &remoteTargetCaller{}
type remoteTargetReceiver struct {
capInfo commoncap.CapabilityInfo
donInfo *types.DON
dispatcher types.Dispatcher
lggr logger.Logger
}
var _ types.Receiver = &remoteTargetReceiver{}
func NewRemoteTargetCaller(capInfo commoncap.CapabilityInfo, donInfo *types.DON, dispatcher types.Dispatcher, lggr logger.Logger) *remoteTargetCaller {
return &remoteTargetCaller{
capInfo: capInfo,
donInfo: donInfo,
dispatcher: dispatcher,
lggr: lggr,
}
}
func (c *remoteTargetCaller) Info(ctx context.Context) (commoncap.CapabilityInfo, error) {
return c.capInfo, nil
}
func (c *remoteTargetCaller) RegisterToWorkflow(ctx context.Context, request commoncap.RegisterToWorkflowRequest) error {
return errors.New("not implemented")
}
func (c *remoteTargetCaller) UnregisterFromWorkflow(ctx context.Context, request commoncap.UnregisterFromWorkflowRequest) error {
return errors.New("not implemented")
}
func (c *remoteTargetCaller) Execute(ctx context.Context, callback chan<- commoncap.CapabilityResponse, request commoncap.CapabilityRequest) error {
c.lggr.Debugw("not implemented - executing fake remote target capability", "capabilityId", c.capInfo.ID, "nMembers", len(c.donInfo.Members))
for _, peerID := range c.donInfo.Members {
m := &types.MessageBody{
CapabilityId: c.capInfo.ID,
CapabilityDonId: c.donInfo.ID,
Payload: []byte{0x01, 0x02, 0x03},
}
err := c.dispatcher.Send(peerID, m)
if err != nil {
return err
}
}
return nil
}
func (c *remoteTargetCaller) Receive(msg *types.MessageBody) {
c.lggr.Debugw("not implemented - received message", "capabilityId", c.capInfo.ID, "payload", msg.Payload)
}
func NewRemoteTargetReceiver(capInfo commoncap.CapabilityInfo, donInfo *types.DON, dispatcher types.Dispatcher, lggr logger.Logger) *remoteTargetReceiver {
return &remoteTargetReceiver{
capInfo: capInfo,
donInfo: donInfo,
dispatcher: dispatcher,
lggr: lggr,
}
}
func (c *remoteTargetReceiver) Receive(msg *types.MessageBody) {
c.lggr.Debugw("not implemented - received message", "capabilityId", c.capInfo.ID, "payload", msg.Payload)
}