-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add chain_reader.go with ChainReader type defs, add ChainReader() to …
…PluginProvider Also add loop definitions for ChainReader Service, update medianProviderClient, and regenerate protobuf files
- Loading branch information
1 parent
65aceb8
commit 98f7b4b
Showing
9 changed files
with
1,198 additions
and
214 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,63 @@ | ||
package internal | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/smartcontractkit/chainlink-relay/pkg/loop/internal/pb" | ||
"github.com/smartcontractkit/chainlink-relay/pkg/types" | ||
) | ||
|
||
var _ types.ChainReader = (*chainReaderClient)(nil) | ||
|
||
type chainReaderClient struct { | ||
*brokerExt | ||
grpc pb.ChainReaderClient | ||
} | ||
|
||
func (c *chainReaderClient) GetLatestValue(ctx context.Context, bc types.BoundContract, method string, params, retValues any) ([]byte, error) { | ||
boundContract := pb.BoundContract{Name: bc.Name, Address: bc.Address, Pending: bc.Pending} | ||
jsonParams, err := json.Marshal(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
jsonRetValues, err := json.Marshal(retValues) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
reply, err := c.grpc.GetLatestValue(ctx, &pb.GetLatestValueRequest{Bc: &boundContract, Method: method, Params: jsonParams, ReturnValues: jsonRetValues}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return reply.RetValues, nil | ||
} | ||
|
||
var _ pb.ChainReaderServer = (*chainReaderServer)(nil) | ||
|
||
type chainReaderServer struct { | ||
pb.UnimplementedChainReaderServer | ||
impl types.ChainReader | ||
} | ||
|
||
func (c *chainReaderServer) GetLatestValue(ctx context.Context, request *pb.GetLatestValueRequest) (*pb.GetLatestValueReply, error) { | ||
var bc types.BoundContract | ||
bc.Name = request.Bc.Name[:] | ||
bc.Address = request.Bc.Address[:] | ||
bc.Pending = request.Bc.Pending | ||
retValues, err := c.impl.GetLatestValue(ctx, bc, request.Method, request.Params, request.ReturnValues) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &pb.GetLatestValueReply{RetValues: retValues}, nil | ||
} | ||
|
||
func (c *chainReaderServer) RegisterEventFilter(ctx context.Context, in *pb.RegisterEventFilterRequest) (*pb.RegisterEventFilterReply, error) { | ||
return nil, nil | ||
} | ||
func (c *chainReaderServer) UnregisterEventFilter(ctx context.Context, in *pb.UnregisterEventFilterRequest) (*pb.RegisterEventFilterReply, error) { | ||
return nil, nil | ||
} | ||
func (c *chainReaderServer) QueryEvents(ctx context.Context, in *pb.QueryEventsRequest) (*pb.QueryEventsReply, error) { | ||
return nil, nil | ||
} |
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
Oops, something went wrong.