-
Notifications
You must be signed in to change notification settings - Fork 20
/
client.ts
1549 lines (1404 loc) · 54.1 KB
/
client.ts
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
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import * as grpcWeb from 'grpc-web';
import * as proto from '../proto';
import * as misc from './misc';
import * as types from './types';
function toCBOR(v: unknown) {
// gRPC cannot handle nil arguments unmarshalled from CBOR, so we use a special case to
// marshal `nil` to an empty byte string.
if (v == null) return new Uint8Array();
return misc.toCBOR(v);
}
function createMethodDescriptorUnary<REQ, RESP>(serviceName: string, methodName: string) {
const MethodType = grpcWeb.MethodType;
return new grpcWeb.MethodDescriptor<REQ, RESP>(
`/oasis-core.${serviceName}/${methodName}`,
MethodType.UNARY,
null,
null,
toCBOR,
misc.fromCBOR,
);
}
function createMethodDescriptorServerStreaming<REQ, RESP>(serviceName: string, methodName: string) {
const MethodType = grpcWeb.MethodType;
return new grpcWeb.MethodDescriptor<REQ, RESP>(
`/oasis-core.${serviceName}/${methodName}`,
MethodType.SERVER_STREAMING,
null,
null,
toCBOR,
misc.fromCBOR,
);
}
// beacon
const methodDescriptorBeaconGetBaseEpoch = createMethodDescriptorUnary<void, types.longnum>(
'Beacon',
'GetBaseEpoch',
);
const methodDescriptorBeaconGetEpoch = createMethodDescriptorUnary<types.longnum, types.longnum>(
'Beacon',
'GetEpoch',
);
const methodDescriptorBeaconGetFutureEpoch = createMethodDescriptorUnary<
types.longnum,
types.BeaconEpochTimeState
>('Beacon', 'GetFutureEpoch');
const methodDescriptorBeaconWaitEpoch = createMethodDescriptorUnary<types.longnum, void>(
'Beacon',
'WaitEpoch',
);
const methodDescriptorBeaconGetEpochBlock = createMethodDescriptorUnary<
types.longnum,
types.longnum
>('Beacon', 'GetEpochBlock');
const methodDescriptorBeaconGetBeacon = createMethodDescriptorUnary<types.longnum, Uint8Array>(
'Beacon',
'GetBeacon',
);
const methodDescriptorBeaconStateToGenesis = createMethodDescriptorUnary<
types.longnum,
types.BeaconGenesis
>('Beacon', 'StateToGenesis');
const methodDescriptorBeaconConsensusParameters = createMethodDescriptorUnary<
types.longnum,
types.BeaconConsensusParameters
>('Beacon', 'ConsensusParameters');
const methodDescriptorBeaconWatchEpochs = createMethodDescriptorServerStreaming<
void,
types.longnum
>('Beacon', 'WatchEpochs');
// scheduler
const methodDescriptorSchedulerGetValidators = createMethodDescriptorUnary<
types.longnum,
types.SchedulerValidator[]
>('Scheduler', 'GetValidators');
const methodDescriptorSchedulerGetCommittees = createMethodDescriptorUnary<
types.SchedulerGetCommitteesRequest,
types.SchedulerCommittee[]
>('Scheduler', 'GetCommittees');
const methodDescriptorSchedulerStateToGenesis = createMethodDescriptorUnary<
types.longnum,
types.SchedulerGenesis
>('Scheduler', 'StateToGenesis');
const methodDescriptorSchedulerConsensusParameters = createMethodDescriptorUnary<
types.longnum,
types.SchedulerConsensusParameters
>('Scheduler', 'ConsensusParameters');
const methodDescriptorSchedulerWatchCommittees = createMethodDescriptorServerStreaming<
void,
types.SchedulerCommittee
>('Scheduler', 'WatchCommittees');
// registry
const methodDescriptorRegistryGetEntity = createMethodDescriptorUnary<
types.RegistryIDQuery,
types.Entity
>('Registry', 'GetEntity');
const methodDescriptorRegistryGetEntities = createMethodDescriptorUnary<
types.longnum,
types.Entity[]
>('Registry', 'GetEntities');
const methodDescriptorRegistryGetNode = createMethodDescriptorUnary<
types.RegistryIDQuery,
types.Node
>('Registry', 'GetNode');
const methodDescriptorRegistryGetNodeByConsensusAddress = createMethodDescriptorUnary<
types.RegistryConsensusAddressQuery,
types.Node
>('Registry', 'GetNodeByConsensusAddress');
const methodDescriptorRegistryGetNodeStatus = createMethodDescriptorUnary<
types.RegistryIDQuery,
types.Node
>('Registry', 'GetNodeStatus');
const methodDescriptorRegistryGetNodes = createMethodDescriptorUnary<types.longnum, types.Node[]>(
'Registry',
'GetNodes',
);
const methodDescriptorRegistryGetRuntime = createMethodDescriptorUnary<
types.RegistryNamespaceQuery,
types.RegistryRuntime
>('Registry', 'GetRuntime');
const methodDescriptorRegistryGetRuntimes = createMethodDescriptorUnary<
types.RegistryGetRuntimesQuery,
types.RegistryRuntime[]
>('Registry', 'GetRuntimes');
const methodDescriptorRegistryStateToGenesis = createMethodDescriptorUnary<
types.longnum,
types.RegistryGenesis
>('Registry', 'StateToGenesis');
const methodDescriptorRegistryGetEvents = createMethodDescriptorUnary<
types.longnum,
types.RegistryEvent[]
>('Registry', 'GetEvents');
const methodDescriptorRegistryWatchEntities = createMethodDescriptorServerStreaming<
void,
types.RegistryEntityEvent
>('Registry', 'WatchEntities');
const methodDescriptorRegistryWatchNodes = createMethodDescriptorServerStreaming<
void,
types.RegistryNodeEvent
>('Registry', 'WatchNodes');
const methodDescriptorRegistryWatchNodeList = createMethodDescriptorServerStreaming<
void,
types.RegistryNodeList
>('Registry', 'WatchNodeList');
const methodDescriptorRegistryWatchRuntimes = createMethodDescriptorServerStreaming<
void,
types.RegistryRuntime
>('Registry', 'WatchRuntimes');
// staking
const methodDescriptorStakingTokenSymbol = createMethodDescriptorUnary<void, string>(
'Staking',
'TokenSymbol',
);
const methodDescriptorStakingTokenValueExponent = createMethodDescriptorUnary<void, number>(
'Staking',
'TokenValueExponent',
);
const methodDescriptorStakingTotalSupply = createMethodDescriptorUnary<types.longnum, Uint8Array>(
'Staking',
'TotalSupply',
);
const methodDescriptorStakingCommonPool = createMethodDescriptorUnary<types.longnum, Uint8Array>(
'Staking',
'CommonPool',
);
const methodDescriptorStakingLastBlockFees = createMethodDescriptorUnary<types.longnum, Uint8Array>(
'Staking',
'LastBlockFees',
);
const methodDescriptorStakingGovernanceDeposits = createMethodDescriptorUnary<
types.longnum,
Uint8Array
>('Staking', 'GovernanceDeposits');
const methodDescriptorStakingThreshold = createMethodDescriptorUnary<
types.StakingThresholdQuery,
Uint8Array
>('Staking', 'Threshold');
const methodDescriptorStakingAddresses = createMethodDescriptorUnary<types.longnum, Uint8Array[]>(
'Staking',
'Addresses',
);
const methodDescriptorStakingAccount = createMethodDescriptorUnary<
types.StakingOwnerQuery,
types.StakingAccount
>('Staking', 'Account');
const methodDescriptorStakingDelegationsFor = createMethodDescriptorUnary<
types.StakingOwnerQuery,
Map<Uint8Array, types.StakingDelegation>
>('Staking', 'DelegationsFor');
const methodDescriptorStakingDelegationInfosFor = createMethodDescriptorUnary<
types.StakingOwnerQuery,
Map<Uint8Array, types.StakingDelegationInfo>
>('Staking', 'DelegationInfosFor');
const methodDescriptorStakingDelegationsTo = createMethodDescriptorUnary<
types.StakingOwnerQuery,
Map<Uint8Array, types.StakingDelegation>
>('Staking', 'DelegationsTo');
const methodDescriptorStakingDebondingDelegationsFor = createMethodDescriptorUnary<
types.StakingOwnerQuery,
Map<Uint8Array, types.StakingDebondingDelegation[]>
>('Staking', 'DebondingDelegationsFor');
const methodDescriptorStakingDebondingDelegationInfosFor = createMethodDescriptorUnary<
types.StakingOwnerQuery,
Map<Uint8Array, types.StakingDebondingDelegationInfo[]>
>('Staking', 'DebondingDelegationInfosFor');
const methodDescriptorStakingDebondingDelegationsTo = createMethodDescriptorUnary<
types.StakingOwnerQuery,
Map<Uint8Array, types.StakingDebondingDelegation[]>
>('Staking', 'DebondingDelegationsTo');
const methodDescriptorStakingAllowance = createMethodDescriptorUnary<
types.StakingAllowanceQuery,
Uint8Array
>('Staking', 'Allowance');
const methodDescriptorStakingStateToGenesis = createMethodDescriptorUnary<
types.longnum,
types.StakingGenesis
>('Staking', 'StateToGenesis');
const methodDescriptorStakingConsensusParameters = createMethodDescriptorUnary<
types.longnum,
types.StakingConsensusParameters
>('Staking', 'ConsensusParameters');
const methodDescriptorStakingGetEvents = createMethodDescriptorUnary<
types.longnum,
types.StakingEvent[]
>('Staking', 'GetEvents');
const methodDescriptorStakingWatchEvents = createMethodDescriptorServerStreaming<
void,
types.StakingEvent
>('Staking', 'WatchEvents');
// keymanager
const methodDescriptorKeyManagerGetStatus = createMethodDescriptorUnary<
types.RegistryNamespaceQuery,
types.KeyManagerStatus
>('KeyManager', 'GetStatus');
const methodDescriptorKeyManagerGetStatuses = createMethodDescriptorUnary<
types.longnum,
types.KeyManagerStatus[]
>('KeyManager', 'GetStatuses');
// roothash
const methodDescriptorRootHashGetGenesisBlock = createMethodDescriptorUnary<
types.RootHashRuntimeRequest,
types.RootHashBlock
>('RootHash', 'GetGenesisBlock');
const methodDescriptorRootHashGetLatestBlock = createMethodDescriptorUnary<
types.RootHashRuntimeRequest,
types.RootHashBlock
>('RootHash', 'GetLatestBlock');
const methodDescriptorRootHashGetRuntimeState = createMethodDescriptorUnary<
types.RootHashRuntimeRequest,
types.RootHashRuntimeState
>('RootHash', 'GetRuntimeState');
const methodDescriptorRootHashGetLastRoundResults = createMethodDescriptorUnary<
types.RootHashRuntimeRequest,
types.RootHashRoundResults
>('RootHash', 'GetLastRoundResults');
const methodDescriptorRootHashGetIncomingMessageQueueMeta = createMethodDescriptorUnary<
types.RootHashRuntimeRequest,
types.RootHashIncomingMessageQueueMeta
>('RootHash', 'GetIncomingMessageQueueMeta');
const methodDescriptorRootHashGetIncomingMessageQueue = createMethodDescriptorUnary<
types.RootHashInMessageQueueRequest,
types.RootHashIncomingMessage[]
>('RootHash', 'GetIncomingMessageQueue');
const methodDescriptorRootHashStateToGenesis = createMethodDescriptorUnary<
types.longnum,
types.RootHashGenesis
>('RootHash', 'StateToGenesis');
const methodDescriptorRootHashConsensusParameters = createMethodDescriptorUnary<
types.longnum,
types.RootHashConsensusParameters
>('RootHash', 'ConsensusParameters');
const methodDescriptorRootHashGetEvents = createMethodDescriptorUnary<
types.longnum,
types.RootHashEvent[]
>('RootHash', 'GetEvents');
const methodDescriptorRootHashWatchBlocks = createMethodDescriptorServerStreaming<
Uint8Array,
types.RootHashAnnotatedBlock
>('RootHash', 'WatchBlocks');
const methodDescriptorRootHashWatchEvents = createMethodDescriptorServerStreaming<
Uint8Array,
types.RootHashEvent
>('RootHash', 'WatchEvents');
// governance
const methodDescriptorGovernanceActiveProposals = createMethodDescriptorUnary<
types.longnum,
types.GovernanceProposal[]
>('Governance', 'ActiveProposals');
const methodDescriptorGovernanceProposals = createMethodDescriptorUnary<
types.longnum,
types.GovernanceProposal[]
>('Governance', 'Proposals');
const methodDescriptorGovernanceProposal = createMethodDescriptorUnary<
types.GovernanceProposalQuery,
types.GovernanceProposal
>('Governance', 'Proposal');
const methodDescriptorGovernanceVotes = createMethodDescriptorUnary<
types.GovernanceProposalQuery,
types.GovernanceVoteEntry[]
>('Governance', 'Votes');
const methodDescriptorGovernancePendingUpgrades = createMethodDescriptorUnary<
types.longnum,
types.UpgradeDescriptor[]
>('Governance', 'PendingUpgrades');
const methodDescriptorGovernanceStateToGenesis = createMethodDescriptorUnary<
types.longnum,
types.GovernanceGenesis
>('Governance', 'StateToGenesis');
const methodDescriptorGovernanceConsensusParameters = createMethodDescriptorUnary<
types.longnum,
types.GovernanceConsensusParameters
>('Governance', 'ConsensusParameters');
const methodDescriptorGovernanceGetEvents = createMethodDescriptorUnary<
types.longnum,
types.GovernanceEvent[]
>('Governance', 'GetEvents');
const methodDescriptorGovernanceWatchEvents = createMethodDescriptorServerStreaming<
void,
types.GovernanceEvent
>('Governance', 'WatchEvents');
// storage
const methodDescriptorStorageSyncGet = createMethodDescriptorUnary<
types.StorageGetRequest,
types.StorageProofResponse
>('Storage', 'SyncGet');
const methodDescriptorStorageSyncGetPrefixes = createMethodDescriptorUnary<
types.StorageGetPrefixesRequest,
types.StorageProofResponse
>('Storage', 'SyncGetPrefixes');
const methodDescriptorStorageSyncIterate = createMethodDescriptorUnary<
types.StorageIterateRequest,
types.StorageProofResponse
>('Storage', 'SyncIterate');
const methodDescriptorStorageGetCheckpoints = createMethodDescriptorUnary<
types.StorageGetCheckpointsRequest,
types.StorageMetadata[]
>('Storage', 'GetCheckpoints');
const methodDescriptorStorageGetDiff = createMethodDescriptorServerStreaming<
types.StorageGetDiffRequest,
types.StorageSyncChunk
>('Storage', 'GetDiff');
const methodDescriptorStorageGetCheckpointChunk = createMethodDescriptorServerStreaming<
types.StorageChunkMetadata,
Uint8Array
>('Storage', 'GetCheckpointChunk');
// worker/storage
const methodDescriptorStorageWorkerGetLastSyncedRound = createMethodDescriptorUnary<
types.WorkerStorageGetLastSyncedRoundRequest,
types.WorkerStorageGetLastSyncedRoundResponse
>('StorageWorker', 'GetLastSyncedRound');
const methodDescriptorStorageWorkerWaitForRound = createMethodDescriptorUnary<
types.WorkerStorageWaitForRoundRequest,
types.WorkerStorageWaitForRoundResponse
>('StorageWorker', 'WaitForRound');
const methodDescriptorStorageWorkerPauseCheckpointer = createMethodDescriptorUnary<
types.WorkerStoragePauseCheckpointerRequest,
void
>('StorageWorker', 'PauseCheckpointer');
// runtime/client
const methodDescriptorRuntimeClientSubmitTx = createMethodDescriptorUnary<
types.RuntimeClientSubmitTxRequest,
Uint8Array
>('RuntimeClient', 'SubmitTx');
const methodDescriptorRuntimeClientSubmitTxMeta = createMethodDescriptorUnary<
types.RuntimeClientSubmitTxRequest,
types.RuntimeClientSubmitTxMetaResponse
>('RuntimeClient', 'SubmitTxMeta');
const methodDescriptorRuntimeClientSubmitTxNoWait = createMethodDescriptorUnary<
types.RuntimeClientSubmitTxRequest,
void
>('RuntimeClient', 'SubmitTxNoWait');
const methodDescriptorRuntimeClientCheckTx = createMethodDescriptorUnary<
types.RuntimeClientCheckTxRequest,
void
>('RuntimeClient', 'CheckTx');
const methodDescriptorRuntimeClientGetGenesisBlock = createMethodDescriptorUnary<
Uint8Array,
types.RootHashBlock
>('RuntimeClient', 'GetGenesisBlock');
const methodDescriptorRuntimeClientGetBlock = createMethodDescriptorUnary<
types.RuntimeClientGetBlockRequest,
types.RootHashBlock
>('RuntimeClient', 'GetBlock');
const methodDescriptorRuntimeClientGetLastRetainedBlock = createMethodDescriptorUnary<
Uint8Array,
types.RootHashBlock
>('RuntimeClient', 'GetLastRetainedBlock');
const methodDescriptorRuntimeClientGetTransactions = createMethodDescriptorUnary<
types.RuntimeClientGetTransactionsRequest,
Uint8Array[]
>('RuntimeClient', 'GetTransactions');
const methodDescriptorRuntimeClientGetTransactionsWithResults = createMethodDescriptorUnary<
types.RuntimeClientGetTransactionsRequest,
types.RuntimeClientTransactionWithResults
>('RuntimeClient', 'GetTransactionsWithResults');
const methodDescriptorRuntimeClientGetEvents = createMethodDescriptorUnary<
types.RuntimeClientGetEventsRequest,
types.RuntimeClientEvent[]
>('RuntimeClient', 'GetEvents');
const methodDescriptorRuntimeClientQuery = createMethodDescriptorUnary<
types.RuntimeClientQueryRequest,
types.RuntimeClientQueryResponse
>('RuntimeClient', 'Query');
const methodDescriptorRuntimeClientWatchBlocks = createMethodDescriptorServerStreaming<
Uint8Array,
types.RootHashAnnotatedBlock
>('RuntimeClient', 'WatchBlocks');
// consensus
const methodDescriptorConsensusSubmitTx = createMethodDescriptorUnary<types.SignatureSigned, void>(
'Consensus',
'SubmitTx',
);
const methodDescriptorConsensusStateToGenesis = createMethodDescriptorUnary<
types.longnum,
types.GenesisDocument
>('Consensus', 'StateToGenesis');
const methodDescriptorConsensusEstimateGas = createMethodDescriptorUnary<
types.ConsensusEstimateGasRequest,
types.longnum
>('Consensus', 'EstimateGas');
const methodDescriptorConsensusGetSignerNonce = createMethodDescriptorUnary<
types.ConsensusGetSignerNonceRequest,
// TODO: remove `undefined` after https://github.com/grpc/grpc-web/pull/1230
// and see TODO in callUnary.
types.longnum | undefined
>('Consensus', 'GetSignerNonce');
const methodDescriptorConsensusGetBlock = createMethodDescriptorUnary<
types.longnum,
types.ConsensusBlock
>('Consensus', 'GetBlock');
const methodDescriptorConsensusGetTransactions = createMethodDescriptorUnary<
types.longnum,
Uint8Array[]
>('Consensus', 'GetTransactions');
const methodDescriptorConsensusGetTransactionsWithResults = createMethodDescriptorUnary<
types.longnum,
types.ConsensusTransactionsWithResults
>('Consensus', 'GetTransactionsWithResults');
const methodDescriptorConsensusGetUnconfirmedTransactions = createMethodDescriptorUnary<
void,
Uint8Array[]
>('Consensus', 'GetUnconfirmedTransactions');
const methodDescriptorConsensusGetGenesisDocument = createMethodDescriptorUnary<
void,
types.GenesisDocument
>('Consensus', 'GetGenesisDocument');
const methodDescriptorConsensusGetChainContext = createMethodDescriptorUnary<void, string>(
'Consensus',
'GetChainContext',
);
const methodDescriptorConsensusGetStatus = createMethodDescriptorUnary<void, types.ConsensusStatus>(
'Consensus',
'GetStatus',
);
const methodDescriptorConsensusGetNextBlockState = createMethodDescriptorUnary<
void,
types.ConsensusNextBlockState
>('Consensus', 'GetNextBlockState');
const methodDescriptorConsensusWatchBlocks = createMethodDescriptorServerStreaming<
void,
types.ConsensusBlock
>('Consensus', 'WatchBlocks');
const methodDescriptorConsensusLightGetLightBlock = createMethodDescriptorUnary<
types.longnum,
types.ConsensusLightBlock
>('ConsensusLight', 'GetLightBlock');
const methodDescriptorConsensusLightGetParameters = createMethodDescriptorUnary<
types.longnum,
types.ConsensusLightParameters
>('ConsensusLight', 'GetParameters');
const methodDescriptorConsensusLightStateSyncGet = createMethodDescriptorUnary<
types.StorageGetRequest,
types.StorageProofResponse
>('ConsensusLight', 'StateSyncGet');
const methodDescriptorConsensusLightStateSyncGetPrefixes = createMethodDescriptorUnary<
types.StorageGetPrefixesRequest,
types.StorageProofResponse
>('ConsensusLight', 'StateSyncGetPrefixes');
const methodDescriptorConsensusLightStateSyncIterate = createMethodDescriptorUnary<
types.StorageIterateRequest,
types.StorageProofResponse
>('ConsensusLight', 'StateSyncIterate');
const methodDescriptorConsensusLightSubmitTxNoWait = createMethodDescriptorUnary<
types.SignatureSigned,
void
>('ConsensusLight', 'SubmitTxNoWait');
const methodDescriptorConsensusLightSubmitEvidence = createMethodDescriptorUnary<
types.ConsensusEvidence,
void
>('ConsensusLight', 'SubmitEvidence');
// control
const methodDescriptorNodeControllerRequestShutdown = createMethodDescriptorUnary<void, void>(
'NodeController',
'RequestShutdown',
);
const methodDescriptorNodeControllerWaitSync = createMethodDescriptorUnary<void, void>(
'NodeController',
'WaitSync',
);
const methodDescriptorNodeControllerIsSynced = createMethodDescriptorUnary<void, boolean>(
'NodeController',
'IsSynced',
);
const methodDescriptorNodeControllerWaitReady = createMethodDescriptorUnary<void, void>(
'NodeController',
'WaitReady',
);
const methodDescriptorNodeControllerIsReady = createMethodDescriptorUnary<void, boolean>(
'NodeController',
'IsReady',
);
const methodDescriptorNodeControllerUpgradeBinary = createMethodDescriptorUnary<
types.UpgradeDescriptor,
void
>('NodeController', 'UpgradeBinary');
const methodDescriptorNodeControllerCancelUpgrade = createMethodDescriptorUnary<
types.UpgradeDescriptor,
void
>('NodeController', 'CancelUpgrade');
const methodDescriptorNodeControllerGetStatus = createMethodDescriptorUnary<
void,
types.ControlStatus
>('NodeController', 'GetStatus');
const methodDescriptorDebugControllerSetEpoch = createMethodDescriptorUnary<types.longnum, void>(
'DebugController',
'SetEpoch',
);
const methodDescriptorDebugControllerWaitNodesRegistered = createMethodDescriptorUnary<
number,
void
>('DebugController', 'WaitNodesRegistered');
// see oasis-core/go/common/grpc/errors.go
/**
* grpcError is a serializable error.
*/
interface GRPCError {
module?: string;
code?: number;
}
export class OasisCodedError extends Error {
oasisCode: number;
oasisModule: string;
}
export class GRPCWrapper {
client: grpcWeb.AbstractClientBase;
base: string;
constructor(base: string) {
this.client = new grpcWeb.GrpcWebClientBase({});
this.base = base;
}
protected callUnary<REQ, RESP>(
desc: grpcWeb.MethodDescriptor<REQ, RESP>,
request: REQ,
): Promise<RESP> {
const method = this.base + desc.getName();
// Some browsers with enormous market share aren't able to preserve the stack between here
// and our `.catch` callback below. Save a copy explicitly.
const invocationStack = new Error().stack;
return this.client.thenableCall(method, request, null, desc).catch((e) => {
if (e.message === 'Incomplete response') {
// This seems to be normal. Void methods don't send back anything, which makes
// grpc-web freak out. I don't know why we don't send a CBOR undefined or
// something.
// TODO: remove after https://github.com/grpc/grpc-web/pull/1230
// and see TODO in methodDescriptorConsensusGetSignerNonce
return undefined;
}
if (e.metadata && 'grpc-status-details-bin' in e.metadata) {
const statusU8 = misc.fromBase64(e.metadata['grpc-status-details-bin']);
const status = proto.google.rpc.Status.decode(statusU8);
const details = status.details;
// `errorFromGrpc` from oasis-core checks for exactly one entry in Details.
// We additionally check that the type URL is empty, consistent with how
// `errorToGrpc` leaves it blank.
if (details.length === 1 && details[0].type_url === '' && details[0].value) {
const grpcError = misc.fromCBOR(details[0].value) as GRPCError;
const innerMessage =
e.message ||
`Message missing, module=${grpcError.module} code=${grpcError.code}`;
const message = `callUnary method ${method}: ${innerMessage}`;
// @ts-expect-error options and cause not modeled
const wrapped = new OasisCodedError(message, {cause: e});
wrapped.oasisCode = grpcError.code;
wrapped.oasisModule = grpcError.module;
wrapped.stack += `
Cause stack:
${e.stack}
End of cause stack
Invocation stack:
${invocationStack}
End of invocation stack`;
throw wrapped;
}
}
// Just in case there's some non-Error rejection reason that doesn't come with metadata
// from oasis-core as expected above, try using JSON to stringify it so that we don't
// end up with [object Object].
const innerMessage = e instanceof Error ? e.toString() : JSON.stringify(e);
const message = `callUnary method ${method}: ${innerMessage}`;
// @ts-expect-error options and cause not modeled
const wrapped = new Error(message, {cause: e});
wrapped.stack += `
Cause stack:
${e.stack}
End of cause stack
Invocation stack:
${invocationStack}
End of invocation stack`;
throw wrapped;
});
}
protected callServerStreaming<REQ, RESP>(
desc: grpcWeb.MethodDescriptor<REQ, RESP>,
request: REQ,
): grpcWeb.ClientReadableStream<RESP> {
return this.client.serverStreaming(this.base + desc.getName(), request, null, desc);
}
}
export class NodeInternal extends GRPCWrapper {
constructor(base: string) {
super(base);
}
// beacon
/**
* GetBaseEpoch returns the base epoch.
*/
beaconGetBaseEpoch() {
return this.callUnary(methodDescriptorBeaconGetBaseEpoch, undefined);
}
/**
* GetEpoch returns the epoch number at the specified block height.
* Calling this method with height `consensus.HeightLatest`, should
* return the epoch of latest known block.
*/
beaconGetEpoch(height: types.longnum) {
return this.callUnary(methodDescriptorBeaconGetEpoch, height);
}
/**
* GetFutureEpoch returns any future epoch that is currently scheduled
* to occur at a specific height.
*
* Note that this may return a nil state in case no future epoch is
* currently scheduled.
*/
beaconGetFutureEpoch(height: types.longnum) {
return this.callUnary(methodDescriptorBeaconGetFutureEpoch, height);
}
/**
* WaitEpoch waits for a specific epoch.
*
* Note that an epoch is considered reached even if any epoch greater
* than the one specified is reached (e.g., that the current epoch
* is already in the future).
*/
beaconWaitEpoch(epoch: types.longnum) {
return this.callUnary(methodDescriptorBeaconWaitEpoch, epoch);
}
/**
* GetEpochBlock returns the block height at the start of the said
* epoch.
*/
beaconGetEpochBlock(epoch: types.longnum) {
return this.callUnary(methodDescriptorBeaconGetEpochBlock, epoch);
}
/**
* GetBeacon gets the beacon for the provided block height.
* Calling this method with height `consensus.HeightLatest` should
* return the beacon for the latest finalized block.
*/
beaconGetBeacon(height: types.longnum) {
return this.callUnary(methodDescriptorBeaconGetBeacon, height);
}
/**
* StateToGenesis returns the genesis state at specified block height.
*/
beaconStateToGenesis(height: types.longnum) {
return this.callUnary(methodDescriptorBeaconStateToGenesis, height);
}
/**
* ConsensusParameters returns the beacon consensus parameters.
*/
beaconConsensusParameters(height: types.longnum) {
return this.callUnary(methodDescriptorBeaconConsensusParameters, height);
}
/**
* WatchEpochs returns a channel that produces a stream of messages
* on epoch transitions.
*
* Upon subscription the current epoch is sent immediately.
*/
beaconWatchEpochs(arg: void) {
return this.callServerStreaming(methodDescriptorBeaconWatchEpochs, arg);
}
// scheduler
/**
* GetValidators returns the vector of consensus validators for
* a given epoch.
*/
schedulerGetValidators(height: types.longnum) {
return this.callUnary(methodDescriptorSchedulerGetValidators, height);
}
/**
* GetCommittees returns the vector of committees for a given
* runtime ID, at the specified block height, and optional callback
* for querying the beacon for a given epoch/block height.
*
* Iff the callback is nil, `beacon.GetBlockBeacon` will be used.
*/
schedulerGetCommittees(request: types.SchedulerGetCommitteesRequest) {
return this.callUnary(methodDescriptorSchedulerGetCommittees, request);
}
/**
* StateToGenesis returns the genesis state at specified block height.
*/
schedulerStateToGenesis(height: types.longnum) {
return this.callUnary(methodDescriptorSchedulerStateToGenesis, height);
}
/**
* ConsensusParameters returns the scheduler consensus parameters.
*/
schedulerConsensusParameters(height: types.longnum) {
return this.callUnary(methodDescriptorSchedulerConsensusParameters, height);
}
/**
* WatchCommittees returns a channel that produces a stream of
* Committee.
*
* Upon subscription, all committees for the current epoch will
* be sent immediately.
*/
schedulerWatchCommittees() {
return this.callServerStreaming(methodDescriptorSchedulerWatchCommittees, undefined);
}
// registry
/**
* GetEntity gets an entity by ID.
*/
registryGetEntity(query: types.RegistryIDQuery) {
return this.callUnary(methodDescriptorRegistryGetEntity, query);
}
/**
* GetEntities gets a list of all registered entities.
*/
registryGetEntities(height: types.longnum) {
return this.callUnary(methodDescriptorRegistryGetEntities, height);
}
/**
* GetNode gets a node by ID.
*/
registryGetNode(query: types.RegistryIDQuery) {
return this.callUnary(methodDescriptorRegistryGetNode, query);
}
/**
* GetNodeByConsensusAddress looks up a node by its consensus address at the
* specified block height. The nature and format of the consensus address depends
* on the specific consensus backend implementation used.
*/
registryGetNodeByConsensusAddress(query: types.RegistryConsensusAddressQuery) {
return this.callUnary(methodDescriptorRegistryGetNodeByConsensusAddress, query);
}
/**
* GetNodeStatus returns a node's status.
*/
registryGetNodeStatus(query: types.RegistryIDQuery) {
return this.callUnary(methodDescriptorRegistryGetNodeStatus, query);
}
/**
* GetNodes gets a list of all registered nodes.
*/
registryGetNodes(height: types.longnum) {
return this.callUnary(methodDescriptorRegistryGetNodes, height);
}
/**
* GetRuntime gets a runtime by ID.
*/
registryGetRuntime(query: types.RegistryNamespaceQuery) {
return this.callUnary(methodDescriptorRegistryGetRuntime, query);
}
/**
* GetRuntimes returns the registered Runtimes at the specified
* block height.
*/
registryGetRuntimes(query: types.RegistryGetRuntimesQuery) {
return this.callUnary(methodDescriptorRegistryGetRuntimes, query);
}
/**
* StateToGenesis returns the genesis state at specified block height.
*/
registryStateToGenesis(height: types.longnum) {
return this.callUnary(methodDescriptorRegistryStateToGenesis, height);
}
/**
* GetEvents returns the events at specified block height.
*/
registryGetEvents(height: types.longnum) {
return this.callUnary(methodDescriptorRegistryGetEvents, height);
}
/**
* WatchEntities returns a channel that produces a stream of
* EntityEvent on entity registration changes.
*/
registryWatchEntities() {
return this.callServerStreaming(methodDescriptorRegistryWatchEntities, undefined);
}
/**
* WatchNodes returns a channel that produces a stream of
* NodeEvent on node registration changes.
*/
registryWatchNodes() {
return this.callServerStreaming(methodDescriptorRegistryWatchNodes, undefined);
}
/**
* WatchNodeList returns a channel that produces a stream of NodeList.
* Upon subscription, the node list for the current epoch will be sent
* immediately.
*
* Each node list will be sorted by node ID in lexicographically ascending
* order.
*/
registryWatchNodeList() {
return this.callServerStreaming(methodDescriptorRegistryWatchNodeList, undefined);
}
/**
* WatchRuntimes returns a stream of Runtime. Upon subscription,
* all runtimes will be sent immediately.
*/
registryWatchRuntimes() {
return this.callServerStreaming(methodDescriptorRegistryWatchRuntimes, undefined);
}
// staking
/**
* TokenSymbol returns the token's ticker symbol.
*/
stakingTokenSymbol() {
return this.callUnary(methodDescriptorStakingTokenSymbol, undefined);
}
/**
* TokenValueExponent is the token's value base-10 exponent, i.e.
* 1 token = 10**TokenValueExponent base units.
*/
stakingTokenValueExponent() {
return this.callUnary(methodDescriptorStakingTokenValueExponent, undefined);
}
/**
* TotalSupply returns the total number of base units.
*/
stakingTotalSupply(height: types.longnum) {
return this.callUnary(methodDescriptorStakingTotalSupply, height);
}
/**
* CommonPool returns the common pool balance.
*/
stakingCommonPool(height: types.longnum) {
return this.callUnary(methodDescriptorStakingCommonPool, height);
}
/**
* LastBlockFees returns the collected fees for previous block.
*/
stakingLastBlockFees(height: types.longnum) {
return this.callUnary(methodDescriptorStakingLastBlockFees, height);
}
/**
* GovernanceDeposits returns the governance deposits account balance.
*/
stakingGovernanceDeposits(height: types.longnum) {
return this.callUnary(methodDescriptorStakingGovernanceDeposits, height);
}
/**
* Threshold returns the specific staking threshold by kind.
*/
stakingThreshold(query: types.StakingThresholdQuery) {
return this.callUnary(methodDescriptorStakingThreshold, query);
}
/**
* Addresses returns the addresses of all accounts with a non-zero general
* or escrow balance.
*/
stakingAddresses(height: types.longnum) {
return this.callUnary(methodDescriptorStakingAddresses, height);
}
/**
* Account returns the account descriptor for the given account.
*/
stakingAccount(query: types.StakingOwnerQuery) {
return this.callUnary(methodDescriptorStakingAccount, query);
}
/**
* DelegationsFor returns the list of (outgoing) delegations for the given
* owner (delegator).
*/
stakingDelegationsFor(query: types.StakingOwnerQuery) {
return this.callUnary(methodDescriptorStakingDelegationsFor, query);
}
/**
* DelegationsInfosFor returns (outgoing) delegations with additional
* information for the given owner (delegator).
*/
stakingDelegationInfosFor(query: types.StakingOwnerQuery) {
return this.callUnary(methodDescriptorStakingDelegationInfosFor, query);
}
/**
* DelegationsTo returns the list of (incoming) delegations to the given
* account.
*/
stakingDelegationsTo(query: types.StakingOwnerQuery) {
return this.callUnary(methodDescriptorStakingDelegationsTo, query);
}
/**
* DebondingDelegationsFor returns the list of (outgoing) debonding
* delegations for the given owner (delegator).
*/
stakingDebondingDelegationsFor(query: types.StakingOwnerQuery) {
return this.callUnary(methodDescriptorStakingDebondingDelegationsFor, query);
}
/**
* DebondingDelegationsInfosFor returns (outgoing) debonding delegations
* with additional information for the given owner (delegator).
*/
stakingDebondingDelegationInfosFor(query: types.StakingOwnerQuery) {
return this.callUnary(methodDescriptorStakingDebondingDelegationInfosFor, query);
}
/**
* DebondingDelegationsTo returns the list of (incoming) debonding
* delegations to the given account.
*/
stakingDebondingDelegationsTo(query: types.StakingOwnerQuery) {
return this.callUnary(methodDescriptorStakingDebondingDelegationsTo, query);
}
/**
* Allowance looks up the allowance for the given owner/beneficiary combination.