erigon-pulse/direct/mining_client.go

215 lines
6.1 KiB
Go
Raw Normal View History

2022-11-20 03:41:20 +00:00
/*
Copyright 2021 Erigon contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2022-02-12 11:41:17 +00:00
package direct
import (
"context"
"io"
2022-02-12 11:41:17 +00:00
txpool_proto "github.com/ledgerwatch/erigon-lib/gointerfaces/txpool"
"github.com/ledgerwatch/erigon-lib/gointerfaces/types"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/emptypb"
)
2022-02-12 11:48:42 +00:00
var _ txpool_proto.MiningClient = (*MiningClient)(nil)
2022-02-12 11:41:17 +00:00
2022-02-12 11:48:42 +00:00
type MiningClient struct {
2022-02-12 11:41:17 +00:00
server txpool_proto.MiningServer
}
2022-02-12 11:48:42 +00:00
func NewMiningClient(server txpool_proto.MiningServer) *MiningClient {
return &MiningClient{server: server}
2022-02-12 11:41:17 +00:00
}
2022-02-12 11:48:42 +00:00
func (s *MiningClient) Version(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*types.VersionReply, error) {
2022-02-12 11:41:17 +00:00
return s.server.Version(ctx, in)
}
// -- start OnPendingBlock
2022-02-12 11:48:42 +00:00
func (s *MiningClient) OnPendingBlock(ctx context.Context, in *txpool_proto.OnPendingBlockRequest, opts ...grpc.CallOption) (txpool_proto.Mining_OnPendingBlockClient, error) {
ch := make(chan *onPendigBlockReply, 16384)
streamServer := &MiningOnPendingBlockS{ch: ch, ctx: ctx}
2022-02-12 11:41:17 +00:00
go func() {
defer close(ch)
streamServer.Err(s.server.OnPendingBlock(in, streamServer))
2022-02-12 11:41:17 +00:00
}()
return &MiningOnPendingBlockC{ch: ch, ctx: ctx}, nil
}
type onPendigBlockReply struct {
r *txpool_proto.OnPendingBlockReply
err error
2022-02-12 11:41:17 +00:00
}
type MiningOnPendingBlockS struct {
ch chan *onPendigBlockReply
ctx context.Context
2022-02-12 11:41:17 +00:00
grpc.ServerStream
}
func (s *MiningOnPendingBlockS) Send(m *txpool_proto.OnPendingBlockReply) error {
s.ch <- &onPendigBlockReply{r: m}
2022-02-12 11:41:17 +00:00
return nil
}
func (s *MiningOnPendingBlockS) Context() context.Context { return s.ctx }
2022-02-17 04:24:13 +00:00
func (s *MiningOnPendingBlockS) Err(err error) {
if err == nil {
return
}
s.ch <- &onPendigBlockReply{err: err}
}
2022-02-12 11:41:17 +00:00
type MiningOnPendingBlockC struct {
ch chan *onPendigBlockReply
ctx context.Context
2022-02-12 11:41:17 +00:00
grpc.ClientStream
}
func (c *MiningOnPendingBlockC) Recv() (*txpool_proto.OnPendingBlockReply, error) {
2022-02-17 04:24:13 +00:00
m, ok := <-c.ch
if !ok || m == nil {
return nil, io.EOF
}
return m.r, m.err
2022-02-12 11:41:17 +00:00
}
2022-02-17 04:24:13 +00:00
func (c *MiningOnPendingBlockC) Context() context.Context { return c.ctx }
2022-02-12 11:41:17 +00:00
// -- end OnPendingBlock
// -- start OnMinedBlock
2022-02-12 11:48:42 +00:00
func (s *MiningClient) OnMinedBlock(ctx context.Context, in *txpool_proto.OnMinedBlockRequest, opts ...grpc.CallOption) (txpool_proto.Mining_OnMinedBlockClient, error) {
ch := make(chan *onMinedBlockReply, 16384)
streamServer := &MiningOnMinedBlockS{ch: ch, ctx: ctx}
2022-02-12 11:41:17 +00:00
go func() {
defer close(ch)
streamServer.Err(s.server.OnMinedBlock(in, streamServer))
2022-02-12 11:41:17 +00:00
}()
return &MiningOnMinedBlockC{ch: ch, ctx: ctx}, nil
}
type onMinedBlockReply struct {
r *txpool_proto.OnMinedBlockReply
err error
2022-02-12 11:41:17 +00:00
}
type MiningOnMinedBlockS struct {
ch chan *onMinedBlockReply
ctx context.Context
2022-02-12 11:41:17 +00:00
grpc.ServerStream
}
func (s *MiningOnMinedBlockS) Send(m *txpool_proto.OnMinedBlockReply) error {
s.ch <- &onMinedBlockReply{r: m}
2022-02-12 11:41:17 +00:00
return nil
}
func (s *MiningOnMinedBlockS) Context() context.Context { return s.ctx }
2022-02-17 04:24:13 +00:00
func (s *MiningOnMinedBlockS) Err(err error) {
if err == nil {
return
}
s.ch <- &onMinedBlockReply{err: err}
}
2022-02-12 11:41:17 +00:00
type MiningOnMinedBlockC struct {
ch chan *onMinedBlockReply
ctx context.Context
2022-02-12 11:41:17 +00:00
grpc.ClientStream
}
func (c *MiningOnMinedBlockC) Recv() (*txpool_proto.OnMinedBlockReply, error) {
2022-02-17 04:24:13 +00:00
m, ok := <-c.ch
if !ok || m == nil {
return nil, io.EOF
}
return m.r, m.err
2022-02-12 11:41:17 +00:00
}
func (c *MiningOnMinedBlockC) Context() context.Context { return c.ctx }
2022-02-12 11:41:17 +00:00
// -- end OnMinedBlock
// -- end OnPendingLogs
2022-02-12 11:48:42 +00:00
func (s *MiningClient) OnPendingLogs(ctx context.Context, in *txpool_proto.OnPendingLogsRequest, opts ...grpc.CallOption) (txpool_proto.Mining_OnPendingLogsClient, error) {
ch := make(chan *onPendingLogsReply, 16384)
streamServer := &MiningOnPendingLogsS{ch: ch, ctx: ctx}
2022-02-12 11:41:17 +00:00
go func() {
defer close(ch)
streamServer.Err(s.server.OnPendingLogs(in, streamServer))
2022-02-12 11:41:17 +00:00
}()
return &MiningOnPendingLogsC{ch: ch, ctx: ctx}, nil
2022-02-12 11:41:17 +00:00
}
type onPendingLogsReply struct {
r *txpool_proto.OnPendingLogsReply
err error
}
2022-02-12 11:41:17 +00:00
type MiningOnPendingLogsS struct {
ch chan *onPendingLogsReply
ctx context.Context
2022-02-12 11:41:17 +00:00
grpc.ServerStream
}
func (s *MiningOnPendingLogsS) Send(m *txpool_proto.OnPendingLogsReply) error {
s.ch <- &onPendingLogsReply{r: m}
2022-02-12 11:41:17 +00:00
return nil
}
func (s *MiningOnPendingLogsS) Context() context.Context { return s.ctx }
2022-02-17 04:24:13 +00:00
func (s *MiningOnPendingLogsS) Err(err error) {
if err == nil {
return
}
s.ch <- &onPendingLogsReply{err: err}
}
2022-02-12 11:41:17 +00:00
type MiningOnPendingLogsC struct {
ch chan *onPendingLogsReply
ctx context.Context
2022-02-12 11:41:17 +00:00
grpc.ClientStream
}
func (c *MiningOnPendingLogsC) Recv() (*txpool_proto.OnPendingLogsReply, error) {
2022-02-17 04:24:13 +00:00
m, ok := <-c.ch
if !ok || m == nil {
return nil, io.EOF
}
return m.r, m.err
2022-02-12 11:41:17 +00:00
}
func (c *MiningOnPendingLogsC) Context() context.Context { return c.ctx }
2022-02-12 11:41:17 +00:00
// -- end OnPendingLogs
2022-02-12 11:48:42 +00:00
func (s *MiningClient) GetWork(ctx context.Context, in *txpool_proto.GetWorkRequest, opts ...grpc.CallOption) (*txpool_proto.GetWorkReply, error) {
2022-02-12 11:41:17 +00:00
return s.server.GetWork(ctx, in)
}
2022-02-12 11:48:42 +00:00
func (s *MiningClient) SubmitWork(ctx context.Context, in *txpool_proto.SubmitWorkRequest, opts ...grpc.CallOption) (*txpool_proto.SubmitWorkReply, error) {
2022-02-12 11:41:17 +00:00
return s.server.SubmitWork(ctx, in)
}
2022-02-12 11:48:42 +00:00
func (s *MiningClient) SubmitHashRate(ctx context.Context, in *txpool_proto.SubmitHashRateRequest, opts ...grpc.CallOption) (*txpool_proto.SubmitHashRateReply, error) {
2022-02-12 11:41:17 +00:00
return s.server.SubmitHashRate(ctx, in)
}
2022-02-12 11:48:42 +00:00
func (s *MiningClient) HashRate(ctx context.Context, in *txpool_proto.HashRateRequest, opts ...grpc.CallOption) (*txpool_proto.HashRateReply, error) {
2022-02-12 11:41:17 +00:00
return s.server.HashRate(ctx, in)
}
2022-02-12 11:48:42 +00:00
func (s *MiningClient) Mining(ctx context.Context, in *txpool_proto.MiningRequest, opts ...grpc.CallOption) (*txpool_proto.MiningReply, error) {
2022-02-12 11:41:17 +00:00
return s.server.Mining(ctx, in)
}