forked from smartcontractkit/chainlink
/
rpc_handlers.go
43 lines (35 loc) · 978 Bytes
/
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
package feeds
import (
"context"
uuid "github.com/satori/go.uuid"
pb "github.com/DCMMC/chainlink/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.FromString(req.Id)
if err != nil {
return nil, err
}
jp := &JobProposal{
Spec: req.GetSpec(),
FeedsManagerID: h.feedsManagerID,
RemoteUUID: remoteUUID,
Multiaddrs: req.GetMultiaddrs(),
}
_, err = h.svc.ProposeJob(jp)
if err != nil {
return nil, err
}
return &pb.ProposeJobResponse{}, nil
}