@@ -5,95 +5,98 @@ import (
55
66 "github.com/NethermindEth/juno/core"
77 "github.com/NethermindEth/juno/core/felt"
8- "github.com/NethermindEth/juno/p2p/gen"
98 "github.com/NethermindEth/juno/utils"
9+ "github.com/starknet-io/starknet-p2pspecs/p2p/proto/common"
10+ synccommon "github.com/starknet-io/starknet-p2pspecs/p2p/proto/sync/common"
11+ "github.com/starknet-io/starknet-p2pspecs/p2p/proto/sync/event"
12+ "github.com/starknet-io/starknet-p2pspecs/p2p/proto/sync/header"
1013)
1114
12- func AdaptBlockID (header * core.Header ) * gen .BlockID {
15+ func AdaptBlockID (header * core.Header ) * common .BlockID {
1316 if header == nil {
1417 return nil
1518 }
1619
17- return & gen .BlockID {
20+ return & common .BlockID {
1821 Number : header .Number ,
1922 Header : AdaptHash (header .Hash ),
2023 }
2124}
2225
23- func adaptSignature (sig []* felt.Felt ) * gen .ConsensusSignature {
24- return & gen .ConsensusSignature {
26+ func adaptSignature (sig []* felt.Felt ) * common .ConsensusSignature {
27+ return & common .ConsensusSignature {
2528 R : AdaptFelt (sig [0 ]),
2629 S : AdaptFelt (sig [1 ]),
2730 }
2831}
2932
30- func AdaptHeader (header * core.Header , commitments * core.BlockCommitments ,
33+ func AdaptHeader (blockHeader * core.Header , commitments * core.BlockCommitments ,
3134 stateDiffCommitment * felt.Felt , stateDiffLength uint64 ,
32- ) * gen .SignedBlockHeader {
35+ ) * header .SignedBlockHeader {
3336 var l1DataGasPriceFri , l1DataGasPriceWei , l2GasPriceFri , l2GasPriceWei * felt.Felt
34- if l1DataGasPrice := header .L1DataGasPrice ; l1DataGasPrice != nil {
37+ if l1DataGasPrice := blockHeader .L1DataGasPrice ; l1DataGasPrice != nil {
3538 l1DataGasPriceFri = l1DataGasPrice .PriceInFri
3639 l1DataGasPriceWei = l1DataGasPrice .PriceInWei
3740 } else {
3841 l1DataGasPriceFri = & felt .Zero
3942 l1DataGasPriceWei = & felt .Zero
4043 }
41- if l2GasPrice := header .L2GasPrice ; l2GasPrice != nil {
44+ if l2GasPrice := blockHeader .L2GasPrice ; l2GasPrice != nil {
4245 l2GasPriceFri = l2GasPrice .PriceInFri
4346 l2GasPriceWei = l2GasPrice .PriceInWei
4447 } else {
4548 l2GasPriceFri = & felt .Zero
4649 l2GasPriceWei = & felt .Zero
4750 }
48- return & gen .SignedBlockHeader {
49- BlockHash : AdaptHash (header .Hash ),
50- ParentHash : AdaptHash (header .ParentHash ),
51- Number : header .Number ,
52- Time : header .Timestamp ,
53- SequencerAddress : AdaptAddress (header .SequencerAddress ),
54- StateRoot : AdaptHash (header .GlobalStateRoot ),
55- Transactions : & gen .Patricia {
56- NLeaves : header .TransactionCount ,
51+ return & header .SignedBlockHeader {
52+ BlockHash : AdaptHash (blockHeader .Hash ),
53+ ParentHash : AdaptHash (blockHeader .ParentHash ),
54+ Number : blockHeader .Number ,
55+ Time : blockHeader .Timestamp ,
56+ SequencerAddress : AdaptAddress (blockHeader .SequencerAddress ),
57+ StateRoot : AdaptHash (blockHeader .GlobalStateRoot ),
58+ Transactions : & common .Patricia {
59+ NLeaves : blockHeader .TransactionCount ,
5760 Root : AdaptHash (commitments .TransactionCommitment ),
5861 },
59- Events : & gen .Patricia {
60- NLeaves : header .EventCount ,
62+ Events : & common .Patricia {
63+ NLeaves : blockHeader .EventCount ,
6164 Root : AdaptHash (commitments .EventCommitment ),
6265 },
6366 Receipts : AdaptHash (commitments .ReceiptCommitment ),
64- ProtocolVersion : header .ProtocolVersion ,
65- L1GasPriceFri : AdaptUint128 (header .L1GasPriceSTRK ),
66- Signatures : utils .Map (header .Signatures , adaptSignature ),
67- StateDiffCommitment : & gen .StateDiffCommitment {
67+ ProtocolVersion : blockHeader .ProtocolVersion ,
68+ L1GasPriceFri : AdaptUint128 (blockHeader .L1GasPriceSTRK ),
69+ Signatures : utils .Map (blockHeader .Signatures , adaptSignature ),
70+ StateDiffCommitment : & synccommon .StateDiffCommitment {
6871 StateDiffLength : stateDiffLength ,
6972 Root : AdaptHash (stateDiffCommitment ),
7073 },
71- L1GasPriceWei : AdaptUint128 (header .L1GasPriceETH ),
74+ L1GasPriceWei : AdaptUint128 (blockHeader .L1GasPriceETH ),
7275 L1DataGasPriceFri : AdaptUint128 (l1DataGasPriceFri ),
7376 L1DataGasPriceWei : AdaptUint128 (l1DataGasPriceWei ),
74- L1DataAvailabilityMode : adaptL1DA (header .L1DAMode ),
77+ L1DataAvailabilityMode : adaptL1DA (blockHeader .L1DAMode ),
7578 L2GasPriceFri : AdaptUint128 (l2GasPriceFri ),
7679 L2GasPriceWei : AdaptUint128 (l2GasPriceWei ),
7780 }
7881}
7982
80- func adaptL1DA (da core.L1DAMode ) gen .L1DataAvailabilityMode {
83+ func adaptL1DA (da core.L1DAMode ) common .L1DataAvailabilityMode {
8184 switch da {
8285 case core .Calldata :
83- return gen .L1DataAvailabilityMode_Calldata
86+ return common .L1DataAvailabilityMode_Calldata
8487 case core .Blob :
85- return gen .L1DataAvailabilityMode_Blob
88+ return common .L1DataAvailabilityMode_Blob
8689 default :
8790 panic (fmt .Errorf ("unknown L1DAMode %v" , da ))
8891 }
8992}
9093
91- func AdaptEvent (e * core.Event , txH * felt.Felt ) * gen .Event {
94+ func AdaptEvent (e * core.Event , txH * felt.Felt ) * event .Event {
9295 if e == nil {
9396 return nil
9497 }
9598
96- return & gen .Event {
99+ return & event .Event {
97100 TransactionHash : AdaptHash (txH ),
98101 FromAddress : AdaptFelt (e .From ),
99102 Keys : utils .Map (e .Keys , AdaptFelt ),
0 commit comments