forked from ledgerwatch/erigon-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheth_backend_client.go
204 lines (168 loc) · 6 KB
/
eth_backend_client.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package direct
import (
"context"
"io"
"github.com/ledgerwatch/erigon-lib/gointerfaces/remote"
"github.com/ledgerwatch/erigon-lib/gointerfaces/types"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/emptypb"
)
type EthBackendClientDirect struct {
server remote.ETHBACKENDServer
}
func NewEthBackendClientDirect(server remote.ETHBACKENDServer) *EthBackendClientDirect {
return &EthBackendClientDirect{server: server}
}
func (s *EthBackendClientDirect) Etherbase(ctx context.Context, in *remote.EtherbaseRequest, opts ...grpc.CallOption) (*remote.EtherbaseReply, error) {
return s.server.Etherbase(ctx, in)
}
func (s *EthBackendClientDirect) NetVersion(ctx context.Context, in *remote.NetVersionRequest, opts ...grpc.CallOption) (*remote.NetVersionReply, error) {
return s.server.NetVersion(ctx, in)
}
func (s *EthBackendClientDirect) NetPeerCount(ctx context.Context, in *remote.NetPeerCountRequest, opts ...grpc.CallOption) (*remote.NetPeerCountReply, error) {
return s.server.NetPeerCount(ctx, in)
}
func (s *EthBackendClientDirect) EngineGetPayloadV1(ctx context.Context, in *remote.EngineGetPayloadRequest, opts ...grpc.CallOption) (*types.ExecutionPayload, error) {
return s.server.EngineGetPayloadV1(ctx, in)
}
func (s *EthBackendClientDirect) EngineNewPayloadV1(ctx context.Context, in *types.ExecutionPayload, opts ...grpc.CallOption) (*remote.EnginePayloadStatus, error) {
return s.server.EngineNewPayloadV1(ctx, in)
}
func (s *EthBackendClientDirect) EngineForkChoiceUpdatedV1(ctx context.Context, in *remote.EngineForkChoiceUpdatedRequest, opts ...grpc.CallOption) (*remote.EngineForkChoiceUpdatedReply, error) {
return s.server.EngineForkChoiceUpdatedV1(ctx, in)
}
func (s *EthBackendClientDirect) Version(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*types.VersionReply, error) {
return s.server.Version(ctx, in)
}
func (s *EthBackendClientDirect) ProtocolVersion(ctx context.Context, in *remote.ProtocolVersionRequest, opts ...grpc.CallOption) (*remote.ProtocolVersionReply, error) {
return s.server.ProtocolVersion(ctx, in)
}
func (s *EthBackendClientDirect) ClientVersion(ctx context.Context, in *remote.ClientVersionRequest, opts ...grpc.CallOption) (*remote.ClientVersionReply, error) {
return s.server.ClientVersion(ctx, in)
}
// -- start Subscribe
func (s *EthBackendClientDirect) Subscribe(ctx context.Context, in *remote.SubscribeRequest, opts ...grpc.CallOption) (remote.ETHBACKEND_SubscribeClient, error) {
ch := make(chan *subscribeReply, 16384)
streamServer := &SubscribeStreamS{ch: ch, ctx: ctx}
go func() {
defer close(ch)
streamServer.Err(s.server.Subscribe(in, streamServer))
}()
return &SubscribeStreamC{ch: ch, ctx: ctx}, nil
}
type subscribeReply struct {
r *remote.SubscribeReply
err error
}
type SubscribeStreamS struct {
ch chan *subscribeReply
ctx context.Context
grpc.ServerStream
}
func (s *SubscribeStreamS) Send(m *remote.SubscribeReply) error {
s.ch <- &subscribeReply{r: m}
return nil
}
func (s *SubscribeStreamS) Context() context.Context { return s.ctx }
func (s *SubscribeStreamS) Err(err error) {
if err == nil {
return
}
s.ch <- &subscribeReply{err: err}
}
type SubscribeStreamC struct {
ch chan *subscribeReply
ctx context.Context
grpc.ClientStream
}
func (c *SubscribeStreamC) Recv() (*remote.SubscribeReply, error) {
m, ok := <-c.ch
if !ok || m == nil {
return nil, io.EOF
}
return m.r, m.err
}
func (c *SubscribeStreamC) Context() context.Context { return c.ctx }
// -- end Subscribe
// -- SubscribeLogs
func (s *EthBackendClientDirect) SubscribeLogs(ctx context.Context, opts ...grpc.CallOption) (remote.ETHBACKEND_SubscribeLogsClient, error) {
subscribeLogsRequestChan := make(chan *subscribeLogsRequest, 16384)
subscribeLogsReplyChan := make(chan *subscribeLogsReply, 16384)
srv := &SubscribeLogsStreamS{
chSend: subscribeLogsReplyChan,
chRecv: subscribeLogsRequestChan,
ctx: ctx,
}
go func() {
defer close(subscribeLogsRequestChan)
defer close(subscribeLogsReplyChan)
srv.Err(s.server.SubscribeLogs(srv))
}()
cli := &SubscribeLogsStreamC{
chSend: subscribeLogsRequestChan,
chRecv: subscribeLogsReplyChan,
ctx: ctx,
}
return cli, nil
}
type SubscribeLogsStreamS struct {
chSend chan *subscribeLogsReply
chRecv chan *subscribeLogsRequest
ctx context.Context
grpc.ServerStream
}
type subscribeLogsReply struct {
r *remote.SubscribeLogsReply
err error
}
type subscribeLogsRequest struct {
r *remote.LogsFilterRequest
err error
}
func (s *SubscribeLogsStreamS) Send(m *remote.SubscribeLogsReply) error {
s.chSend <- &subscribeLogsReply{r: m}
return nil
}
func (s *SubscribeLogsStreamS) Recv() (*remote.LogsFilterRequest, error) {
m, ok := <-s.chRecv
if !ok || m == nil {
return nil, io.EOF
}
return m.r, m.err
}
func (s *SubscribeLogsStreamS) Err(err error) {
if err == nil {
return
}
s.chSend <- &subscribeLogsReply{err: err}
}
type SubscribeLogsStreamC struct {
chSend chan *subscribeLogsRequest
chRecv chan *subscribeLogsReply
ctx context.Context
grpc.ClientStream
}
func (c *SubscribeLogsStreamC) Send(m *remote.LogsFilterRequest) error {
c.chSend <- &subscribeLogsRequest{r: m}
return nil
}
func (c *SubscribeLogsStreamC) Recv() (*remote.SubscribeLogsReply, error) {
m, ok := <-c.chRecv
if !ok || m == nil {
return nil, io.EOF
}
return m.r, m.err
}
// -- end SubscribeLogs
func (s *EthBackendClientDirect) Block(ctx context.Context, in *remote.BlockRequest, opts ...grpc.CallOption) (*remote.BlockReply, error) {
return s.server.Block(ctx, in)
}
func (s *EthBackendClientDirect) TxnLookup(ctx context.Context, in *remote.TxnLookupRequest, opts ...grpc.CallOption) (*remote.TxnLookupReply, error) {
return s.server.TxnLookup(ctx, in)
}
func (s *EthBackendClientDirect) NodeInfo(ctx context.Context, in *remote.NodesInfoRequest, opts ...grpc.CallOption) (*remote.NodesInfoReply, error) {
return s.server.NodeInfo(ctx, in)
}
func (s *EthBackendClientDirect) Peers(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*remote.PeersReply, error) {
return s.server.Peers(ctx, in)
}