-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
rpc_handlers.go
79 lines (65 loc) · 1.84 KB
/
rpc_handlers.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
package feeds
import (
"context"
"github.com/google/uuid"
pb "github.com/smartcontractkit/chainlink/v2/core/services/feeds/proto"
)
// RPCHandlers define handlers for RPC method calls from the Feeds Manager
type RPCHandlers struct {
svc Service
feedsManagerID int64
}
func NewRPCHandlers(svc Service, feedsManagerID int64) *RPCHandlers {
return &RPCHandlers{
svc: svc,
feedsManagerID: feedsManagerID,
}
}
// ProposeJob creates a new job proposal record for the feeds manager
func (h *RPCHandlers) ProposeJob(ctx context.Context, req *pb.ProposeJobRequest) (*pb.ProposeJobResponse, error) {
remoteUUID, err := uuid.Parse(req.Id)
if err != nil {
return nil, err
}
_, err = h.svc.ProposeJob(ctx, &ProposeJobArgs{
Spec: req.GetSpec(),
FeedsManagerID: h.feedsManagerID,
RemoteUUID: remoteUUID,
Version: int32(req.GetVersion()),
Multiaddrs: req.GetMultiaddrs(),
})
if err != nil {
return nil, err
}
return &pb.ProposeJobResponse{}, nil
}
// DeleteJob deletes a job proposal record.
func (h *RPCHandlers) DeleteJob(ctx context.Context, req *pb.DeleteJobRequest) (*pb.DeleteJobResponse, error) {
remoteUUID, err := uuid.Parse(req.Id)
if err != nil {
return nil, err
}
_, err = h.svc.DeleteJob(ctx, &DeleteJobArgs{
FeedsManagerID: h.feedsManagerID,
RemoteUUID: remoteUUID,
})
if err != nil {
return nil, err
}
return &pb.DeleteJobResponse{}, nil
}
// RevokeJob revokes a pending job proposal record.
func (h *RPCHandlers) RevokeJob(ctx context.Context, req *pb.RevokeJobRequest) (*pb.RevokeJobResponse, error) {
remoteUUID, err := uuid.Parse(req.Id)
if err != nil {
return nil, err
}
_, err = h.svc.RevokeJob(ctx, &RevokeJobArgs{
FeedsManagerID: h.feedsManagerID,
RemoteUUID: remoteUUID,
})
if err != nil {
return nil, err
}
return &pb.RevokeJobResponse{}, nil
}