/
grpc.go
862 lines (790 loc) · 25.6 KB
/
grpc.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
package api
import (
"context"
"google.golang.org/grpc"
beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
cmnGrpc "github.com/oasisprotocol/oasis-core/go/common/grpc"
"github.com/oasisprotocol/oasis-core/go/common/pubsub"
"github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
genesis "github.com/oasisprotocol/oasis-core/go/genesis/api"
governance "github.com/oasisprotocol/oasis-core/go/governance/api"
registry "github.com/oasisprotocol/oasis-core/go/registry/api"
roothash "github.com/oasisprotocol/oasis-core/go/roothash/api"
scheduler "github.com/oasisprotocol/oasis-core/go/scheduler/api"
staking "github.com/oasisprotocol/oasis-core/go/staking/api"
"github.com/oasisprotocol/oasis-core/go/storage/mkvs/syncer"
)
var (
// serviceName is the gRPC service name.
serviceName = cmnGrpc.NewServiceName("Consensus")
// lightServiceName is the gRPC service name for the light consensus interface.
lightServiceName = cmnGrpc.NewServiceName("ConsensusLight")
// methodSubmitTx is the SubmitTx method.
methodSubmitTx = serviceName.NewMethod("SubmitTx", transaction.SignedTransaction{})
// methodStateToGenesis is the StateToGenesis method.
methodStateToGenesis = serviceName.NewMethod("StateToGenesis", int64(0))
// methodEstimateGas is the EstimateGas method.
methodEstimateGas = serviceName.NewMethod("EstimateGas", &EstimateGasRequest{})
// methodGetSignerNonce is a GetSignerNonce method.
methodGetSignerNonce = serviceName.NewMethod("GetSignerNonce", &GetSignerNonceRequest{})
// methodGetBlock is the GetBlock method.
methodGetBlock = serviceName.NewMethod("GetBlock", int64(0))
// methodGetTransactions is the GetTransactions method.
methodGetTransactions = serviceName.NewMethod("GetTransactions", int64(0))
// methodGetTransactionsWithResults is the GetTransactionsWithResults method.
methodGetTransactionsWithResults = serviceName.NewMethod("GetTransactionsWithResults", int64(0))
// methodGetUnconfirmedTransactions is the GetUnconfirmedTransactions method.
methodGetUnconfirmedTransactions = serviceName.NewMethod("GetUnconfirmedTransactions", nil)
// methodGetGenesisDocument is the GetGenesisDocument method.
methodGetGenesisDocument = serviceName.NewMethod("GetGenesisDocument", nil)
// methodGetChainContext is the GetChainContext method.
methodGetChainContext = serviceName.NewMethod("GetChainContext", nil)
// methodGetStatus is the GetStatus method.
methodGetStatus = serviceName.NewMethod("GetStatus", nil)
// methodGetNextBlockState is the GetNextBlockState method.
methodGetNextBlockState = serviceName.NewMethod("GetNextBlockState", nil)
// methodWatchBlocks is the WatchBlocks method.
methodWatchBlocks = serviceName.NewMethod("WatchBlocks", nil)
// methodGetLightBlock is the GetLightBlock method.
methodGetLightBlock = lightServiceName.NewMethod("GetLightBlock", int64(0))
// methodGetParameters is the GetParameters method.
methodGetParameters = lightServiceName.NewMethod("GetParameters", int64(0))
// methodStateSyncGet is the StateSyncGet method.
methodStateSyncGet = lightServiceName.NewMethod("StateSyncGet", syncer.GetRequest{})
// methodStateSyncGetPrefixes is the StateSyncGetPrefixes method.
methodStateSyncGetPrefixes = lightServiceName.NewMethod("StateSyncGetPrefixes", syncer.GetPrefixesRequest{})
// methodStateSyncIterate is the StateSyncIterate method.
methodStateSyncIterate = lightServiceName.NewMethod("StateSyncIterate", syncer.IterateRequest{})
// methodSubmitTxNoWait is the SubmitTxNoWait method.
methodSubmitTxNoWait = lightServiceName.NewMethod("SubmitTxNoWait", transaction.SignedTransaction{})
// methodSubmitEvidence is the SubmitEvidence method.
methodSubmitEvidence = lightServiceName.NewMethod("SubmitEvidence", &Evidence{})
// serviceDesc is the gRPC service descriptor.
serviceDesc = grpc.ServiceDesc{
ServiceName: string(serviceName),
HandlerType: (*ClientBackend)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: methodSubmitTx.ShortName(),
Handler: handlerSubmitTx,
},
{
MethodName: methodStateToGenesis.ShortName(),
Handler: handlerStateToGenesis,
},
{
MethodName: methodEstimateGas.ShortName(),
Handler: handlerEstimateGas,
},
{
MethodName: methodGetSignerNonce.ShortName(),
Handler: handlerGetSignerNonce,
},
{
MethodName: methodGetBlock.ShortName(),
Handler: handlerGetBlock,
},
{
MethodName: methodGetTransactions.ShortName(),
Handler: handlerGetTransactions,
},
{
MethodName: methodGetTransactionsWithResults.ShortName(),
Handler: handlerGetTransactionsWithResults,
},
{
MethodName: methodGetUnconfirmedTransactions.ShortName(),
Handler: handlerGetUnconfirmedTransactions,
},
{
MethodName: methodGetGenesisDocument.ShortName(),
Handler: handlerGetGenesisDocument,
},
{
MethodName: methodGetChainContext.ShortName(),
Handler: handlerGetChainContext,
},
{
MethodName: methodGetStatus.ShortName(),
Handler: handlerGetStatus,
},
{
MethodName: methodGetNextBlockState.ShortName(),
Handler: handlerGetNextBlockState,
},
},
Streams: []grpc.StreamDesc{
{
StreamName: methodWatchBlocks.ShortName(),
Handler: handlerWatchBlocks,
ServerStreams: true,
},
},
}
// lightServiceDesc is the gRPC service descriptor for the light consensus service.
lightServiceDesc = grpc.ServiceDesc{
ServiceName: string(lightServiceName),
HandlerType: (*LightClientBackend)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: methodGetLightBlock.ShortName(),
Handler: handlerGetLightBlock,
},
{
MethodName: methodGetParameters.ShortName(),
Handler: handlerGetParameters,
},
{
MethodName: methodStateSyncGet.ShortName(),
Handler: handlerStateSyncGet,
},
{
MethodName: methodStateSyncGetPrefixes.ShortName(),
Handler: handlerStateSyncGetPrefixes,
},
{
MethodName: methodStateSyncIterate.ShortName(),
Handler: handlerStateSyncIterate,
},
{
MethodName: methodSubmitTxNoWait.ShortName(),
Handler: handlerSubmitTxNoWait,
},
{
MethodName: methodSubmitEvidence.ShortName(),
Handler: handlerSubmitEvidence,
},
},
}
)
func handlerSubmitTx( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
rq := new(transaction.SignedTransaction)
if err := dec(rq); err != nil {
return nil, err
}
if interceptor == nil {
return nil, srv.(ClientBackend).SubmitTx(ctx, rq)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodSubmitTx.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return nil, srv.(ClientBackend).SubmitTx(ctx, req.(*transaction.SignedTransaction))
}
return interceptor(ctx, rq, info, handler)
}
func handlerStateToGenesis( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
var height int64
if err := dec(&height); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ClientBackend).StateToGenesis(ctx, height)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodStateToGenesis.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ClientBackend).StateToGenesis(ctx, req.(int64))
}
return interceptor(ctx, height, info, handler)
}
func handlerEstimateGas( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
rq := new(EstimateGasRequest)
if err := dec(rq); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ClientBackend).EstimateGas(ctx, rq)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodEstimateGas.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ClientBackend).EstimateGas(ctx, req.(*EstimateGasRequest))
}
return interceptor(ctx, rq, info, handler)
}
func handlerGetSignerNonce( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
rq := new(GetSignerNonceRequest)
if err := dec(rq); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ClientBackend).GetSignerNonce(ctx, rq)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodGetSignerNonce.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ClientBackend).GetSignerNonce(ctx, req.(*GetSignerNonceRequest))
}
return interceptor(ctx, rq, info, handler)
}
func handlerGetBlock( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
var height int64
if err := dec(&height); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ClientBackend).GetBlock(ctx, height)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodGetBlock.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ClientBackend).GetBlock(ctx, req.(int64))
}
return interceptor(ctx, height, info, handler)
}
func handlerGetTransactions( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
var height int64
if err := dec(&height); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ClientBackend).GetTransactions(ctx, height)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodGetTransactions.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ClientBackend).GetTransactions(ctx, req.(int64))
}
return interceptor(ctx, height, info, handler)
}
func handlerGetTransactionsWithResults( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
var height int64
if err := dec(&height); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ClientBackend).GetTransactionsWithResults(ctx, height)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodGetTransactionsWithResults.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ClientBackend).GetTransactionsWithResults(ctx, req.(int64))
}
return interceptor(ctx, height, info, handler)
}
func handlerGetUnconfirmedTransactions( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
if interceptor == nil {
return srv.(ClientBackend).GetUnconfirmedTransactions(ctx)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodGetUnconfirmedTransactions.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ClientBackend).GetUnconfirmedTransactions(ctx)
}
return interceptor(ctx, nil, info, handler)
}
func handlerGetGenesisDocument( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
if interceptor == nil {
return srv.(ClientBackend).GetGenesisDocument(ctx)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodGetGenesisDocument.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ClientBackend).GetGenesisDocument(ctx)
}
return interceptor(ctx, nil, info, handler)
}
func handlerGetChainContext( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
if interceptor == nil {
return srv.(ClientBackend).GetChainContext(ctx)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodGetChainContext.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ClientBackend).GetChainContext(ctx)
}
return interceptor(ctx, nil, info, handler)
}
func handlerGetStatus( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
if interceptor == nil {
return srv.(ClientBackend).GetStatus(ctx)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodGetStatus.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ClientBackend).GetStatus(ctx)
}
return interceptor(ctx, nil, info, handler)
}
func handlerGetNextBlockState( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
if interceptor == nil {
return srv.(ClientBackend).GetNextBlockState(ctx)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodGetNextBlockState.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ClientBackend).GetNextBlockState(ctx)
}
return interceptor(ctx, nil, info, handler)
}
func handlerWatchBlocks(srv interface{}, stream grpc.ServerStream) error {
if err := stream.RecvMsg(nil); err != nil {
return err
}
ctx := stream.Context()
ch, sub, err := srv.(ClientBackend).WatchBlocks(ctx)
if err != nil {
return err
}
defer sub.Close()
for {
select {
case blk, ok := <-ch:
if !ok {
return nil
}
if err := stream.SendMsg(blk); err != nil {
return err
}
case <-ctx.Done():
return ctx.Err()
}
}
}
func handlerGetLightBlock( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
var height int64
if err := dec(&height); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LightClientBackend).GetLightBlock(ctx, height)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodGetLightBlock.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LightClientBackend).GetLightBlock(ctx, req.(int64))
}
return interceptor(ctx, height, info, handler)
}
func handlerGetParameters( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
var height int64
if err := dec(&height); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LightClientBackend).GetParameters(ctx, height)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodGetParameters.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LightClientBackend).GetParameters(ctx, req.(int64))
}
return interceptor(ctx, height, info, handler)
}
func handlerStateSyncGet( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
rq := new(syncer.GetRequest)
if err := dec(rq); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LightClientBackend).State().SyncGet(ctx, rq)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodStateSyncGet.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LightClientBackend).State().SyncGet(ctx, req.(*syncer.GetRequest))
}
return interceptor(ctx, rq, info, handler)
}
func handlerStateSyncGetPrefixes( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
rq := new(syncer.GetPrefixesRequest)
if err := dec(rq); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LightClientBackend).State().SyncGetPrefixes(ctx, rq)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodStateSyncGetPrefixes.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LightClientBackend).State().SyncGetPrefixes(ctx, req.(*syncer.GetPrefixesRequest))
}
return interceptor(ctx, rq, info, handler)
}
func handlerStateSyncIterate( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
rq := new(syncer.IterateRequest)
if err := dec(rq); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LightClientBackend).State().SyncIterate(ctx, rq)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodStateSyncIterate.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LightClientBackend).State().SyncIterate(ctx, req.(*syncer.IterateRequest))
}
return interceptor(ctx, rq, info, handler)
}
func handlerSubmitTxNoWait( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
rq := new(transaction.SignedTransaction)
if err := dec(rq); err != nil {
return nil, err
}
if interceptor == nil {
return nil, srv.(LightClientBackend).SubmitTxNoWait(ctx, rq)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodSubmitTxNoWait.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return nil, srv.(LightClientBackend).SubmitTxNoWait(ctx, req.(*transaction.SignedTransaction))
}
return interceptor(ctx, rq, info, handler)
}
func handlerSubmitEvidence( // nolint: golint
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
rq := new(Evidence)
if err := dec(rq); err != nil {
return nil, err
}
if interceptor == nil {
return nil, srv.(LightClientBackend).SubmitEvidence(ctx, rq)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodSubmitEvidence.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return nil, srv.(LightClientBackend).SubmitEvidence(ctx, req.(*Evidence))
}
return interceptor(ctx, rq, info, handler)
}
// RegisterService registers a new client backend service with the given gRPC server.
func RegisterService(server *grpc.Server, service ClientBackend) {
server.RegisterService(&serviceDesc, service)
RegisterLightService(server, service)
}
// RegisterLightService registers a new light client backend service with the given gRPC server.
func RegisterLightService(server *grpc.Server, service LightClientBackend) {
server.RegisterService(&lightServiceDesc, service)
}
type consensusLightClient struct {
conn *grpc.ClientConn
}
// Implements LightClientBackend.
func (c *consensusLightClient) GetLightBlock(ctx context.Context, height int64) (*LightBlock, error) {
var rsp LightBlock
if err := c.conn.Invoke(ctx, methodGetLightBlock.FullName(), height, &rsp); err != nil {
return nil, err
}
return &rsp, nil
}
// Implements LightClientBackend.
func (c *consensusLightClient) GetParameters(ctx context.Context, height int64) (*Parameters, error) {
var rsp Parameters
if err := c.conn.Invoke(ctx, methodGetParameters.FullName(), height, &rsp); err != nil {
return nil, err
}
return &rsp, nil
}
type stateReadSync struct {
c *consensusLightClient
}
// Implements syncer.ReadSyncer.
func (rs *stateReadSync) SyncGet(ctx context.Context, request *syncer.GetRequest) (*syncer.ProofResponse, error) {
var rsp syncer.ProofResponse
if err := rs.c.conn.Invoke(ctx, methodStateSyncGet.FullName(), request, &rsp); err != nil {
return nil, err
}
return &rsp, nil
}
// Implements syncer.ReadSyncer.
func (rs *stateReadSync) SyncGetPrefixes(ctx context.Context, request *syncer.GetPrefixesRequest) (*syncer.ProofResponse, error) {
var rsp syncer.ProofResponse
if err := rs.c.conn.Invoke(ctx, methodStateSyncGetPrefixes.FullName(), request, &rsp); err != nil {
return nil, err
}
return &rsp, nil
}
// Implements syncer.ReadSyncer.
func (rs *stateReadSync) SyncIterate(ctx context.Context, request *syncer.IterateRequest) (*syncer.ProofResponse, error) {
var rsp syncer.ProofResponse
if err := rs.c.conn.Invoke(ctx, methodStateSyncIterate.FullName(), request, &rsp); err != nil {
return nil, err
}
return &rsp, nil
}
// Implements LightClientBackend.
func (c *consensusLightClient) State() syncer.ReadSyncer {
return &stateReadSync{c}
}
// Implements LightClientBackend.
func (c *consensusLightClient) SubmitTxNoWait(ctx context.Context, tx *transaction.SignedTransaction) error {
return c.conn.Invoke(ctx, methodSubmitTxNoWait.FullName(), tx, nil)
}
// Implements LightClientBackend.
func (c *consensusLightClient) SubmitEvidence(ctx context.Context, evidence *Evidence) error {
return c.conn.Invoke(ctx, methodSubmitEvidence.FullName(), evidence, nil)
}
type consensusClient struct {
consensusLightClient
conn *grpc.ClientConn
}
func (c *consensusClient) SubmitTx(ctx context.Context, tx *transaction.SignedTransaction) error {
return c.conn.Invoke(ctx, methodSubmitTx.FullName(), tx, nil)
}
func (c *consensusClient) StateToGenesis(ctx context.Context, height int64) (*genesis.Document, error) {
var rsp genesis.Document
if err := c.conn.Invoke(ctx, methodStateToGenesis.FullName(), height, &rsp); err != nil {
return nil, err
}
return &rsp, nil
}
func (c *consensusClient) EstimateGas(ctx context.Context, req *EstimateGasRequest) (transaction.Gas, error) {
var gas transaction.Gas
if err := c.conn.Invoke(ctx, methodEstimateGas.FullName(), req, &gas); err != nil {
return transaction.Gas(0), err
}
return gas, nil
}
func (c *consensusClient) GetSignerNonce(ctx context.Context, req *GetSignerNonceRequest) (uint64, error) {
var nonce uint64
if err := c.conn.Invoke(ctx, methodGetSignerNonce.FullName(), req, &nonce); err != nil {
return nonce, err
}
return nonce, nil
}
func (c *consensusClient) GetBlock(ctx context.Context, height int64) (*Block, error) {
var rsp Block
if err := c.conn.Invoke(ctx, methodGetBlock.FullName(), height, &rsp); err != nil {
return nil, err
}
return &rsp, nil
}
func (c *consensusClient) GetTransactions(ctx context.Context, height int64) ([][]byte, error) {
var rsp [][]byte
if err := c.conn.Invoke(ctx, methodGetTransactions.FullName(), height, &rsp); err != nil {
return nil, err
}
return rsp, nil
}
func (c *consensusClient) GetTransactionsWithResults(ctx context.Context, height int64) (*TransactionsWithResults, error) {
var rsp TransactionsWithResults
if err := c.conn.Invoke(ctx, methodGetTransactionsWithResults.FullName(), height, &rsp); err != nil {
return nil, err
}
return &rsp, nil
}
func (c *consensusClient) GetUnconfirmedTransactions(ctx context.Context) ([][]byte, error) {
var rsp [][]byte
if err := c.conn.Invoke(ctx, methodGetUnconfirmedTransactions.FullName(), nil, &rsp); err != nil {
return nil, err
}
return rsp, nil
}
func (c *consensusClient) GetGenesisDocument(ctx context.Context) (*genesis.Document, error) {
var rsp genesis.Document
if err := c.conn.Invoke(ctx, methodGetGenesisDocument.FullName(), nil, &rsp); err != nil {
return nil, err
}
return &rsp, nil
}
func (c *consensusClient) GetChainContext(ctx context.Context) (string, error) {
var rsp string
if err := c.conn.Invoke(ctx, methodGetChainContext.FullName(), nil, &rsp); err != nil {
return "", err
}
return rsp, nil
}
func (c *consensusClient) GetStatus(ctx context.Context) (*Status, error) {
var rsp Status
if err := c.conn.Invoke(ctx, methodGetStatus.FullName(), nil, &rsp); err != nil {
return nil, err
}
return &rsp, nil
}
func (c *consensusClient) GetNextBlockState(ctx context.Context) (*NextBlockState, error) {
var rsp NextBlockState
if err := c.conn.Invoke(ctx, methodGetNextBlockState.FullName(), nil, &rsp); err != nil {
return nil, err
}
return &rsp, nil
}
func (c *consensusClient) WatchBlocks(ctx context.Context) (<-chan *Block, pubsub.ClosableSubscription, error) {
ctx, sub := pubsub.NewContextSubscription(ctx)
stream, err := c.conn.NewStream(ctx, &serviceDesc.Streams[0], methodWatchBlocks.FullName())
if err != nil {
return nil, nil, err
}
if err = stream.SendMsg(nil); err != nil {
return nil, nil, err
}
if err = stream.CloseSend(); err != nil {
return nil, nil, err
}
ch := make(chan *Block)
go func() {
defer close(ch)
for {
var blk Block
if serr := stream.RecvMsg(&blk); serr != nil {
return
}
select {
case ch <- &blk:
case <-ctx.Done():
return
}
}
}()
return ch, sub, nil
}
func (c *consensusClient) Beacon() beacon.Backend {
return beacon.NewBeaconClient(c.conn)
}
func (c *consensusClient) Registry() registry.Backend {
return registry.NewRegistryClient(c.conn)
}
func (c *consensusClient) Staking() staking.Backend {
return staking.NewStakingClient(c.conn)
}
func (c *consensusClient) Scheduler() scheduler.Backend {
return scheduler.NewSchedulerClient(c.conn)
}
func (c *consensusClient) Governance() governance.Backend {
return governance.NewGovernanceClient(c.conn)
}
func (c *consensusClient) RootHash() roothash.Backend {
return roothash.NewRootHashClient(c.conn)
}
// NewConsensusClient creates a new gRPC consensus client service.
func NewConsensusClient(c *grpc.ClientConn) ClientBackend {
return &consensusClient{
consensusLightClient: consensusLightClient{c},
conn: c,
}
}
// NewConsensusLightClient creates a new gRPC consensus light client service.
func NewConsensusLightClient(c *grpc.ClientConn) LightClientBackend {
return &consensusLightClient{c}
}