-
Notifications
You must be signed in to change notification settings - Fork 21
/
jsonrpc_server.go
806 lines (645 loc) · 19 KB
/
jsonrpc_server.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
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package rpc
import (
"context"
"encoding/hex"
"errors"
"fmt"
"math/big"
"net/http"
"time"
"github.com/ava-labs/avalanchego/ids"
"github.com/AnomalyFi/hypersdk/chain"
seqconsts "github.com/AnomalyFi/nodekit-seq/consts"
"github.com/AnomalyFi/hypersdk/crypto/ed25519"
"github.com/AnomalyFi/hypersdk/rpc"
"github.com/AnomalyFi/hypersdk/utils"
"github.com/AnomalyFi/nodekit-seq/actions"
"github.com/AnomalyFi/nodekit-seq/auth"
"github.com/AnomalyFi/nodekit-seq/genesis"
"github.com/AnomalyFi/nodekit-seq/types"
sequtils "github.com/AnomalyFi/nodekit-seq/utils"
"github.com/tidwall/btree"
)
type JSONRPCServer struct {
c Controller
headers *types.ShardedMap[string, *chain.StatefulBlock]
//map[ids.ID]*chain.StatefulBlock // Map block ID to block header
blocksWithValidTxs *types.ShardedMap[string, *types.SequencerBlock]
//map[ids.ID]*types.SequencerBlock // Map block ID to block header
idsByHeight btree.Map[uint64, ids.ID] // Map block ID to block height
// tmstp, height
blocks btree.Map[int64, uint64]
}
func NewJSONRPCServer(c Controller) *JSONRPCServer {
headers := types.NewShardedMap[string, *chain.StatefulBlock](10000, 10, types.HashString)
blocksWithValidTxs := types.NewShardedMap[string, *types.SequencerBlock](10000, 10, types.HashString)
return &JSONRPCServer{
c: c,
headers: headers,
blocksWithValidTxs: blocksWithValidTxs,
idsByHeight: btree.Map[uint64, ids.ID]{},
blocks: btree.Map[int64, uint64]{},
}
}
type GenesisReply struct {
Genesis *genesis.Genesis `json:"genesis"`
}
func (j *JSONRPCServer) Genesis(_ *http.Request, _ *struct{}, reply *GenesisReply) (err error) {
reply.Genesis = j.c.Genesis()
return nil
}
type SubmitMsgTxArgs struct {
ChainId string `json:"chain_id"`
NetworkID uint32 `json:"network_id"`
SecondaryChainId []byte `json:"secondary_chain_id"`
Data []byte `json:"data"`
}
type SubmitMsgTxReply struct {
TxID string `json:"txId"`
}
func (j *JSONRPCServer) SubmitMsgTx(
req *http.Request,
args *SubmitMsgTxArgs,
reply *SubmitMsgTxReply,
) error {
ctx := context.Background()
chainId, err := ids.FromString(args.ChainId)
if err != nil {
return err
}
unitPrices, err := j.c.UnitPrices(ctx)
if err != nil {
return err
}
parser := j.ServerParser(ctx, args.NetworkID, chainId)
priv, err := ed25519.HexToKey(
"323b1d8f4eed5f0da9da93071b034f2dce9d2d22692c172f3cb252a64ddfafd01b057de320297c29ad0c1f589ea216869cf1938d88c9fbd70d6748323dbf2fa7", //nolint:lll
)
factory := auth.NewED25519Factory(priv)
tpriv, err := ed25519.GeneratePrivateKey()
if err != nil {
return err
}
trsender := tpriv.PublicKey()
action := &actions.SequencerMsg{
FromAddress: trsender,
Data: args.Data,
ChainId: args.SecondaryChainId,
}
// TODO need to define action, authFactory
maxUnits, err := chain.EstimateMaxUnits(parser.Rules(time.Now().UnixMilli()), action, factory, nil)
if err != nil {
return err
}
maxFee, err := chain.MulSum(unitPrices, maxUnits)
if err != nil {
return err
}
// TODO above is generateTransaction below is generateTransactionManual
now := time.Now().UnixMilli()
rules := parser.Rules(now)
base := &chain.Base{
Timestamp: utils.UnixRMilli(now, rules.GetValidityWindow()),
ChainID: chainId,
MaxFee: maxFee,
}
// Build transaction
actionRegistry, authRegistry := parser.Registry()
tx := chain.NewTx(base, nil, action, false)
tx, err = tx.Sign(factory, actionRegistry, authRegistry)
if err != nil {
return fmt.Errorf("%w: failed to sign transaction", err)
}
// TODO above is new!
if err := tx.AuthAsyncVerify()(); err != nil {
return err
}
txID := tx.ID()
reply.TxID = txID.String()
return j.c.Submit(ctx, false, []*chain.Transaction{tx})[0]
}
type account struct {
priv ed25519.PrivateKey
factory *auth.ED25519Factory
rsender ed25519.PublicKey
sender string
}
type TxArgs struct {
TxID ids.ID `json:"txId"`
}
type TxReply struct {
Timestamp int64 `json:"timestamp"`
Success bool `json:"success"`
Units chain.Dimensions `json:"units"`
Fee uint64 `json:"fee"`
}
func (j *JSONRPCServer) Tx(req *http.Request, args *TxArgs, reply *TxReply) error {
ctx, span := j.c.Tracer().Start(req.Context(), "Server.Tx")
defer span.End()
found, t, success, units, fee, err := j.c.GetTransaction(ctx, args.TxID)
if err != nil {
return err
}
if !found {
return ErrTxNotFound
}
reply.Timestamp = t
reply.Success = success
reply.Units = units
reply.Fee = fee
return nil
}
type AssetArgs struct {
Asset ids.ID `json:"asset"`
}
type AssetReply struct {
Symbol []byte `json:"symbol"`
Decimals uint8 `json:"decimals"`
Metadata []byte `json:"metadata"`
Supply uint64 `json:"supply"`
Owner string `json:"owner"`
Warp bool `json:"warp"`
}
func (j *JSONRPCServer) Asset(req *http.Request, args *AssetArgs, reply *AssetReply) error {
ctx, span := j.c.Tracer().Start(req.Context(), "Server.Asset")
defer span.End()
exists, symbol, decimals, metadata, supply, owner, warp, err := j.c.GetAssetFromState(ctx, args.Asset)
if err != nil {
return err
}
if !exists {
return ErrAssetNotFound
}
reply.Symbol = symbol
reply.Decimals = decimals
reply.Metadata = metadata
reply.Supply = supply
reply.Owner = sequtils.Address(owner)
reply.Warp = warp
return err
}
type BalanceArgs struct {
Address string `json:"address"`
Asset ids.ID `json:"asset"`
}
type BalanceReply struct {
Amount uint64 `json:"amount"`
}
func (j *JSONRPCServer) Balance(req *http.Request, args *BalanceArgs, reply *BalanceReply) error {
ctx, span := j.c.Tracer().Start(req.Context(), "Server.Balance")
defer span.End()
addr, err := sequtils.ParseAddress(args.Address)
if err != nil {
return err
}
balance, err := j.c.GetBalanceFromState(ctx, addr, args.Asset)
if err != nil {
return err
}
reply.Amount = balance
return err
}
type LoanArgs struct {
Destination ids.ID `json:"destination"`
Asset ids.ID `json:"asset"`
}
type LoanReply struct {
Amount uint64 `json:"amount"`
}
func (j *JSONRPCServer) Loan(req *http.Request, args *LoanArgs, reply *LoanReply) error {
ctx, span := j.c.Tracer().Start(req.Context(), "Server.Loan")
defer span.End()
amount, err := j.c.GetLoanFromState(ctx, args.Asset, args.Destination)
if err != nil {
return err
}
reply.Amount = amount
return nil
}
type BlockInfo struct {
BlockId string `json:"id"`
Timestamp int64 `json:"timestamp"`
L1Head uint64 `json:"l1_head"`
Height uint64 `json:"height"`
}
type BlockHeadersResponse struct {
From uint64 `json:"from"`
Blocks []BlockInfo `json:"blocks"`
Prev BlockInfo `json:"prev"`
Next BlockInfo `json:"next"`
}
// TODO need to fix this. Tech debt
type TransactionResponse struct {
Txs []*chain.Transaction `json:"txs"`
BlockId string `json:"id"`
}
type SEQTransactionResponse struct {
Txs []*types.SEQTransaction `json:"txs"`
BlockId string `json:"id"`
}
type SequencerWarpBlockResponse struct {
Blocks []SequencerWarpBlock `json:"blocks"`
}
type SequencerWarpBlock struct {
BlockId string `json:"id"`
Timestamp int64 `json:"timestamp"`
L1Head uint64 `json:"l1_head"`
Height *big.Int `json:"height"`
BlockRoot *big.Int `json:"root"`
ParentRoot *big.Int `json:"parent"`
}
type GetBlockHeadersByHeightArgs struct {
Height uint64 `json:"height"`
End int64 `json:"end"`
}
type GetBlockHeadersIDArgs struct {
ID string `json:"id"`
End int64 `json:"end"`
}
type GetBlockHeadersByStartArgs struct {
Start int64 `json:"start"`
End int64 `json:"end"`
}
type GetBlockTransactionsArgs struct {
ID string `json:"block_id"`
}
type GetBlockCommitmentArgs struct {
First uint64 `json:"first"`
CurrentHeight uint64 `json:"current_height"`
MaxBlocks int `json:"max_blocks"`
}
type GetBlockTransactionsByNamespaceArgs struct {
Height uint64 `json:"height"`
Namespace string `json:"namespace"`
}
func (j *JSONRPCServer) GetBlockHeadersByHeight(req *http.Request, args *GetBlockHeadersByHeightArgs, reply *BlockHeadersResponse) error {
Prev := BlockInfo{}
if args.Height > 1 {
prevBlkId, success := j.idsByHeight.Get(args.Height - 1)
if success {
blk, found := j.headers.Get(prevBlkId.String())
if !found {
return errors.New("Could not find Block")
}
//tmp := blk.Tmstmp / 1000
Prev = BlockInfo{
BlockId: prevBlkId.String(),
Timestamp: blk.Tmstmp,
L1Head: uint64(blk.L1Head),
Height: blk.Hght,
}
}
}
blocks := make([]BlockInfo, 0)
Next := BlockInfo{}
j.idsByHeight.Ascend(args.Height, func(heightKey uint64, id ids.ID) bool {
// Does heightKey match the given block's height for the id
blk, found := j.headers.Get(id.String())
if !found {
return false
}
//tmp := blk.Tmstmp / 1000
if blk.Tmstmp >= args.End {
Next = BlockInfo{
BlockId: id.String(),
Timestamp: blk.Tmstmp,
L1Head: uint64(blk.L1Head),
Height: blk.Hght,
}
return false
}
blocks = append(blocks, BlockInfo{
BlockId: id.String(),
Timestamp: blk.Tmstmp,
L1Head: uint64(blk.L1Head),
Height: blk.Hght,
})
return true
})
reply.From = args.Height
reply.Blocks = blocks
reply.Prev = Prev
reply.Next = Next
return nil
}
func (j *JSONRPCServer) GetBlockHeadersID(req *http.Request, args *GetBlockHeadersIDArgs, reply *BlockHeadersResponse) error {
// Parse query parameters
var firstBlock uint64
//var prevBlkId ids.ID
if args.ID != "" {
id, err := ids.FromString(args.ID)
if err != nil {
return err
}
// TODO make this into the response
block, found := j.headers.Get(id.String())
if !found {
return errors.New("Could not find Block")
}
firstBlock = block.Hght
// Handle hash parameter
// ...
} else {
firstBlock = 1
// Handle error or default case
// TODO add error potentially
// http.Error(writer, "Invalid parameters", http.StatusBadRequest)
//TODO used to return nil but changed
//return nil
}
//prevBlkId, success := j.idsByHeight.Get(firstBlock - 1)
Prev := BlockInfo{}
if firstBlock > 1 {
// j.idsByHeight.Descend(firstBlock, func(heightKey uint64, id ids.ID) bool {
// prevBlkId = id
// return false
// })
prevBlkId, success := j.idsByHeight.Get(firstBlock - 1)
if success {
blk, found := j.headers.Get(prevBlkId.String())
if !found {
return errors.New("Could not find Previous Block")
}
Prev = BlockInfo{
BlockId: prevBlkId.String(),
Timestamp: blk.Tmstmp,
L1Head: uint64(blk.L1Head),
Height: blk.Hght,
}
} else {
return errors.New("Could not find Previous Block")
}
}
blocks := make([]BlockInfo, 0)
Next := BlockInfo{}
j.idsByHeight.Ascend(firstBlock, func(heightKey uint64, id ids.ID) bool {
// Does heightKey match the given block's height for the id
blk, found := j.headers.Get(id.String())
if !found {
return false
}
if blk.Tmstmp >= args.End {
//tmp := blk.Tmstmp / 1000
Next = BlockInfo{
BlockId: id.String(),
Timestamp: blk.Tmstmp,
L1Head: uint64(blk.L1Head),
Height: blk.Hght,
}
return false
}
if blk.Hght == heightKey {
//tmp := blk.Tmstmp / 1000
blocks = append(blocks, BlockInfo{
BlockId: id.String(),
Timestamp: blk.Tmstmp,
L1Head: uint64(blk.L1Head),
Height: blk.Hght,
})
}
return true
})
// res := BlockHeadersResponse{From: firstBlock, Blocks: blocks, Prev: Prev, Next: Next}
// reply = &res
reply.From = firstBlock
reply.Blocks = blocks
reply.Prev = Prev
reply.Next = Next
// TODO add blocks to the list of blocks contained in this time window
// Marshal res to JSON and send the response
return nil
}
func (j *JSONRPCServer) GetBlockHeadersByStart(req *http.Request, args *GetBlockHeadersByStartArgs, reply *BlockHeadersResponse) error {
// Parse query parameters
var firstBlock uint64
j.blocks.Ascend(args.Start, func(tmstp int64, height uint64) bool {
firstBlock = height
return false
})
Prev := BlockInfo{}
if firstBlock > 1 {
prevBlkId, success := j.idsByHeight.Get(firstBlock - 1)
if success {
blk, found := j.headers.Get(prevBlkId.String())
if !found {
return fmt.Errorf("Could not find Previous Block: %d ", firstBlock)
}
//tmp := blk.Tmstmp / 1000
Prev = BlockInfo{
BlockId: prevBlkId.String(),
Timestamp: blk.Tmstmp,
L1Head: uint64(blk.L1Head),
Height: blk.Hght,
}
} else {
return fmt.Errorf("Could not find Previous Block: %d, idsByHeight height %d, blocks height %d ", firstBlock, j.idsByHeight.Len(), j.blocks.Len())
}
}
blocks := make([]BlockInfo, 0)
Next := BlockInfo{}
j.idsByHeight.Ascend(firstBlock, func(heightKey uint64, id ids.ID) bool {
// Does heightKey match the given block's height for the id
blk, found := j.headers.Get(id.String())
if !found {
return false
}
if blk.Tmstmp >= args.End {
//tmp := blk.Tmstmp / 1000
Next = BlockInfo{
BlockId: id.String(),
Timestamp: blk.Tmstmp,
L1Head: uint64(blk.L1Head),
Height: blk.Hght,
}
return false
}
//tmp := blk.Tmstmp / 1000
blocks = append(blocks, BlockInfo{
BlockId: id.String(),
Timestamp: blk.Tmstmp,
L1Head: uint64(blk.L1Head),
Height: blk.Hght,
})
// if blk.Hght == heightKey {
// tmp := blk.Tmstmp / 1000
// blocks = append(blocks, BlockInfo{
// BlockId: id.String(),
// Timestamp: tmp,
// L1Head: l1Head.Uint64(),
// Height: blk.Hght,
// })
// fmt.Println("Match Found")
// fmt.Println("Blocks Length After Append:", len(blocks))
// }
return true
})
// Marshal res to JSON and send the response
reply.From = firstBlock
reply.Blocks = blocks
reply.Prev = Prev
reply.Next = Next
return nil
}
func (j *JSONRPCServer) GetBlockTransactions(req *http.Request, args *GetBlockTransactionsArgs, reply *TransactionResponse) error {
// Parse query parameters
// TODO either the firstBlock height is equal to height or use the hash to get it or if none of the above work then use the btree to get it
if args.ID != "" {
return nil
}
// id, err := ids.FromString(args.ID)
// if err != nil {
// return err
// }
block, success := j.headers.Get(args.ID)
if !success {
return errors.New("Txs Not Found")
}
reply.Txs = block.Txs
reply.BlockId = args.ID
return nil
}
func (j *JSONRPCServer) GetCommitmentBlocks(req *http.Request, args *GetBlockCommitmentArgs, reply *SequencerWarpBlockResponse) error {
// Parse query parameters
// TODO either the firstBlock height is equal to height or use the hash to get it or if none of the above work then use the btree to get it
if args.First < 1 {
return nil
}
blocks := make([]SequencerWarpBlock, 0)
j.idsByHeight.Ascend(args.First, func(heightKey uint64, id ids.ID) bool {
// Does heightKey match the given block's height for the id
if len(blocks) >= args.MaxBlocks {
return false
}
blockTemp, success := j.headers.Get(id.String())
if !success {
return success
}
header := &types.Header{
Height: blockTemp.Hght,
Timestamp: uint64(blockTemp.Tmstmp),
L1Head: uint64(blockTemp.L1Head),
TransactionsRoot: types.NmtRoot{
Root: id[:],
},
}
comm := header.Commit()
//TODO swapped these 2 functions so now it exits earlier. Need to test
if blockTemp.Hght >= args.CurrentHeight {
// root := types.NewU256().SetBytes(blockTemp.StateRoot)
// bigRoot := root.Int
parentRoot := types.NewU256().SetBytes(blockTemp.Prnt)
bigParentRoot := parentRoot.Int
blocks = append(blocks, SequencerWarpBlock{
BlockId: id.String(),
Timestamp: blockTemp.Tmstmp,
L1Head: uint64(blockTemp.L1Head),
Height: big.NewInt(int64(blockTemp.Hght)),
BlockRoot: &comm.Uint256().Int,
ParentRoot: &bigParentRoot,
})
return false
}
if blockTemp.Hght == heightKey {
// root := types.NewU256().SetBytes(blockTemp.StateRoot)
// bigRoot := root.Int
parentRoot := types.NewU256().SetBytes(blockTemp.Prnt)
bigParentRoot := parentRoot.Int
blocks = append(blocks, SequencerWarpBlock{
BlockId: id.String(),
Timestamp: blockTemp.Tmstmp,
L1Head: uint64(blockTemp.L1Head),
Height: big.NewInt(int64(blockTemp.Hght)),
BlockRoot: &comm.Uint256().Int,
ParentRoot: &bigParentRoot,
})
}
return true
})
reply.Blocks = blocks
return nil
}
func (j *JSONRPCServer) GetBlockTransactionsByNamespace(req *http.Request, args *GetBlockTransactionsByNamespaceArgs, reply *SEQTransactionResponse) error {
BlkId, success := j.idsByHeight.Get(args.Height)
if !success {
return errors.New("Txs Not Found For Namespace")
}
block, found := j.blocksWithValidTxs.Get(BlkId.String())
if !found {
return fmt.Errorf("Could not find Block: %s ", BlkId.String())
}
txs := block.Txs[args.Namespace]
reply.Txs = txs
reply.BlockId = BlkId.String()
return nil
}
func (j *JSONRPCServer) AcceptBlock(blk *chain.StatelessBlock) error {
ctx := context.Background()
msg, err := rpc.PackBlockMessage(blk)
if err != nil {
return err
}
parser := j.ServerParser(ctx, 1, ids.Empty)
block, results, _, id, err := rpc.UnpackBlockMessage(msg, parser)
//TODO I should experiment with TTL
j.headers.Put(id.String(), block)
// j.headers[id.String()] = block
j.idsByHeight.Set(block.Hght, *id)
j.blocks.Set(block.Tmstmp, block.Hght)
// TODO I need to call CommitmentManager.AcceptBlock here because otherwise the unpacking will be a pain
seq_txs := make(map[string][]*types.SEQTransaction)
for i, tx := range blk.Txs {
result := results[i]
if result.Success {
switch action := tx.Action.(type) {
case *actions.SequencerMsg:
hx := hex.EncodeToString(action.ChainId)
if seq_txs[hx] == nil {
seq_txs[hx] = make([]*types.SEQTransaction, 0)
}
new_tx := types.SEQTransaction{
Namespace: hx,
Tx_id: tx.ID().String(),
Transaction: action.Data,
Index: uint64(i),
}
seq_txs[hx] = append(seq_txs[hx], &new_tx)
}
}
}
sequencerBlock := &types.SequencerBlock{
StateRoot: blk.StateRoot,
Prnt: blk.Prnt,
Tmstmp: blk.Tmstmp,
Hght: blk.Hght,
Txs: seq_txs,
}
// TODO need to fix this
j.blocksWithValidTxs.Put(id.String(), sequencerBlock)
return nil
}
var _ chain.Parser = (*ServerParser)(nil)
type ServerParser struct {
networkID uint32
chainID ids.ID
genesis *genesis.Genesis
}
func (p *ServerParser) ChainID() ids.ID {
return p.chainID
}
func (p *ServerParser) Rules(t int64) chain.Rules {
return p.genesis.Rules(t, p.networkID, p.chainID)
}
func (*ServerParser) Registry() (chain.ActionRegistry, chain.AuthRegistry) {
return seqconsts.ActionRegistry, seqconsts.AuthRegistry
}
func (j *JSONRPCServer) ServerParser(ctx context.Context, networkId uint32, chainId ids.ID) chain.Parser {
g := j.c.Genesis()
// The only thing this is using is the ActionRegistry and AuthRegistry so this should be fine
return &Parser{networkId, chainId, g}
}
func (j *JSONRPCServer) GetAcceptedBlockWindow(req *http.Request, _ *struct{}, reply *int) error {
*reply = j.c.GetAcceptedBlockWindow()
return nil
}