erigon-pulse/direct/txpool_client.go

106 lines
3.0 KiB
Go
Raw Normal View History

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.TxpoolClient = (*TxPoolClient)(nil)
2022-02-12 11:41:17 +00:00
2022-02-12 11:48:42 +00:00
type TxPoolClient struct {
2022-02-12 11:41:17 +00:00
server txpool_proto.TxpoolServer
}
2022-02-12 11:48:42 +00:00
func NewTxPoolClient(server txpool_proto.TxpoolServer) *TxPoolClient {
return &TxPoolClient{server}
2022-02-12 11:41:17 +00:00
}
2022-02-12 11:48:42 +00:00
func (s *TxPoolClient) 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)
}
2022-02-12 11:48:42 +00:00
func (s *TxPoolClient) FindUnknown(ctx context.Context, in *txpool_proto.TxHashes, opts ...grpc.CallOption) (*txpool_proto.TxHashes, error) {
2022-02-12 11:41:17 +00:00
return s.server.FindUnknown(ctx, in)
}
2022-02-12 11:48:42 +00:00
func (s *TxPoolClient) Add(ctx context.Context, in *txpool_proto.AddRequest, opts ...grpc.CallOption) (*txpool_proto.AddReply, error) {
2022-02-12 11:41:17 +00:00
return s.server.Add(ctx, in)
}
2022-02-12 11:48:42 +00:00
func (s *TxPoolClient) Transactions(ctx context.Context, in *txpool_proto.TransactionsRequest, opts ...grpc.CallOption) (*txpool_proto.TransactionsReply, error) {
2022-02-12 11:41:17 +00:00
return s.server.Transactions(ctx, in)
}
2022-02-12 11:48:42 +00:00
func (s *TxPoolClient) All(ctx context.Context, in *txpool_proto.AllRequest, opts ...grpc.CallOption) (*txpool_proto.AllReply, error) {
2022-02-12 11:41:17 +00:00
return s.server.All(ctx, in)
}
2022-02-12 11:48:42 +00:00
func (s *TxPoolClient) Pending(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*txpool_proto.PendingReply, error) {
2022-02-12 11:41:17 +00:00
return s.server.Pending(ctx, in)
}
// -- start OnAdd
2022-02-12 11:48:42 +00:00
func (s *TxPoolClient) OnAdd(ctx context.Context, in *txpool_proto.OnAddRequest, opts ...grpc.CallOption) (txpool_proto.Txpool_OnAddClient, error) {
ch := make(chan *onAddReply, 16384)
streamServer := &TxPoolOnAddS{ch: ch, ctx: ctx}
2022-02-12 11:41:17 +00:00
go func() {
defer close(ch)
streamServer.Err(s.server.OnAdd(in, streamServer))
2022-02-12 11:41:17 +00:00
}()
return &TxPoolOnAddC{ch: ch, ctx: ctx}, nil
}
type onAddReply struct {
r *txpool_proto.OnAddReply
err error
2022-02-12 11:41:17 +00:00
}
type TxPoolOnAddS struct {
ch chan *onAddReply
ctx context.Context
2022-02-12 11:41:17 +00:00
grpc.ServerStream
}
func (s *TxPoolOnAddS) Send(m *txpool_proto.OnAddReply) error {
s.ch <- &onAddReply{r: m}
2022-02-12 11:41:17 +00:00
return nil
}
func (s *TxPoolOnAddS) Context() context.Context { return s.ctx }
2022-02-17 04:24:13 +00:00
func (s *TxPoolOnAddS) Err(err error) {
if err == nil {
return
}
s.ch <- &onAddReply{err: err}
}
2022-02-12 11:41:17 +00:00
type TxPoolOnAddC struct {
ch chan *onAddReply
ctx context.Context
2022-02-12 11:41:17 +00:00
grpc.ClientStream
}
func (c *TxPoolOnAddC) Recv() (*txpool_proto.OnAddReply, 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 *TxPoolOnAddC) Context() context.Context { return c.ctx }
2022-02-12 11:41:17 +00:00
// -- end OnAdd
2022-02-12 11:48:42 +00:00
func (s *TxPoolClient) Status(ctx context.Context, in *txpool_proto.StatusRequest, opts ...grpc.CallOption) (*txpool_proto.StatusReply, error) {
2022-02-12 11:41:17 +00:00
return s.server.Status(ctx, in)
}
2022-02-12 11:48:42 +00:00
func (s *TxPoolClient) Nonce(ctx context.Context, in *txpool_proto.NonceRequest, opts ...grpc.CallOption) (*txpool_proto.NonceReply, error) {
2022-02-12 11:41:17 +00:00
return s.server.Nonce(ctx, in)
}