11package abci
22
33import (
4- tmbytes "github.com/tendermint/tendermint /libs/bytes"
5- tmproto "github.com/tendermint/tendermint /proto/tendermint/types"
6- tmversion "github.com/tendermint/tendermint /proto/tendermint/version"
7- tmtypes "github.com/tendermint/tendermint /types"
4+ cmbytes "github.com/cometbft/cometbft /libs/bytes"
5+ cmproto "github.com/cometbft/cometbft /proto/tendermint/types"
6+ cmversion "github.com/cometbft/cometbft /proto/tendermint/version"
7+ cmtypes "github.com/cometbft/cometbft /types"
88
99 "github.com/rollkit/rollkit/types"
1010)
1111
1212// ToABCIHeaderPB converts Rollkit header to Header format defined in ABCI.
1313// Caller should fill all the fields that are not available in Rollkit header (like ChainID).
14- func ToABCIHeaderPB (header * types.Header ) (tmproto .Header , error ) {
15- return tmproto .Header {
16- Version : tmversion .Consensus {
14+ func ToABCIHeaderPB (header * types.Header ) (cmproto .Header , error ) {
15+ return cmproto .Header {
16+ Version : cmversion .Consensus {
1717 Block : header .Version .Block ,
1818 App : header .Version .App ,
1919 },
2020 Height : int64 (header .Height ()),
2121 Time : header .Time (),
22- LastBlockId : tmproto .BlockID {
22+ LastBlockId : cmproto .BlockID {
2323 Hash : header .LastHeaderHash [:],
24- PartSetHeader : tmproto .PartSetHeader {
24+ PartSetHeader : cmproto .PartSetHeader {
2525 Total : 0 ,
2626 Hash : nil ,
2727 },
2828 },
29- LastCommitHash : header .LastCommitHash [:],
29+ LastCommitHash : header .LastHeaderHash [:],
3030 DataHash : header .DataHash [:],
3131 ValidatorsHash : header .AggregatorsHash [:],
3232 NextValidatorsHash : nil ,
3333 ConsensusHash : header .ConsensusHash [:],
3434 AppHash : header .AppHash [:],
3535 LastResultsHash : header .LastResultsHash [:],
36- EvidenceHash : new (tmtypes .EvidenceData ).Hash (),
36+ EvidenceHash : new (cmtypes .EvidenceData ).Hash (),
3737 ProposerAddress : header .ProposerAddress ,
3838 ChainID : header .ChainID (),
3939 }, nil
4040}
4141
4242// ToABCIHeader converts Rollkit header to Header format defined in ABCI.
4343// Caller should fill all the fields that are not available in Rollkit header (like ChainID).
44- func ToABCIHeader (header * types.Header ) (tmtypes .Header , error ) {
45- return tmtypes .Header {
46- Version : tmversion .Consensus {
44+ func ToABCIHeader (header * types.Header ) (cmtypes .Header , error ) {
45+ return cmtypes .Header {
46+ Version : cmversion .Consensus {
4747 Block : header .Version .Block ,
4848 App : header .Version .App ,
4949 },
5050 Height : int64 (header .Height ()),
5151 Time : header .Time (),
52- LastBlockID : tmtypes .BlockID {
53- Hash : tmbytes .HexBytes (header .LastHeaderHash ),
54- PartSetHeader : tmtypes .PartSetHeader {
52+ LastBlockID : cmtypes .BlockID {
53+ Hash : cmbytes .HexBytes (header .LastHeaderHash [:] ),
54+ PartSetHeader : cmtypes .PartSetHeader {
5555 Total : 0 ,
5656 Hash : nil ,
5757 },
5858 },
59- LastCommitHash : tmbytes .HexBytes (header .LastCommitHash ),
60- DataHash : tmbytes .HexBytes (header .DataHash ),
61- ValidatorsHash : tmbytes .HexBytes (header .AggregatorsHash ),
59+ LastCommitHash : cmbytes .HexBytes (header .LastCommitHash ),
60+ DataHash : cmbytes .HexBytes (header .DataHash ),
61+ ValidatorsHash : cmbytes .HexBytes (header .AggregatorsHash ),
6262 NextValidatorsHash : nil ,
63- ConsensusHash : tmbytes .HexBytes (header .ConsensusHash ),
64- AppHash : tmbytes .HexBytes (header .AppHash ),
65- LastResultsHash : tmbytes .HexBytes (header .LastResultsHash ),
66- EvidenceHash : new (tmtypes .EvidenceData ).Hash (),
63+ ConsensusHash : cmbytes .HexBytes (header .ConsensusHash ),
64+ AppHash : cmbytes .HexBytes (header .AppHash ),
65+ LastResultsHash : cmbytes .HexBytes (header .LastResultsHash ),
66+ EvidenceHash : new (cmtypes .EvidenceData ).Hash (),
6767 ProposerAddress : header .ProposerAddress ,
6868 ChainID : header .ChainID (),
6969 }, nil
7070}
7171
7272// ToABCIBlock converts Rolkit block into block format defined by ABCI.
7373// Returned block should pass `ValidateBasic`.
74- func ToABCIBlock (block * types.Block ) (* tmtypes .Block , error ) {
74+ func ToABCIBlock (block * types.Block ) (* cmtypes .Block , error ) {
7575 abciHeader , err := ToABCIHeader (& block .SignedHeader .Header )
7676 if err != nil {
7777 return nil , err
@@ -81,34 +81,34 @@ func ToABCIBlock(block *types.Block) (*tmtypes.Block, error) {
8181 if len (abciCommit .Signatures ) == 1 {
8282 abciCommit .Signatures [0 ].ValidatorAddress = block .SignedHeader .Header .ProposerAddress
8383 }
84- abciBlock := tmtypes .Block {
84+ abciBlock := cmtypes .Block {
8585 Header : abciHeader ,
86- Evidence : tmtypes .EvidenceData {
86+ Evidence : cmtypes .EvidenceData {
8787 Evidence : nil ,
8888 },
8989 LastCommit : abciCommit ,
9090 }
91- abciBlock .Data .Txs = make ([]tmtypes .Tx , len (block .Data .Txs ))
91+ abciBlock .Data .Txs = make ([]cmtypes .Tx , len (block .Data .Txs ))
9292 for i := range block .Data .Txs {
93- abciBlock .Data .Txs [i ] = tmtypes .Tx (block .Data .Txs [i ])
93+ abciBlock .Data .Txs [i ] = cmtypes .Tx (block .Data .Txs [i ])
9494 }
95- abciBlock .Header .DataHash = tmbytes .HexBytes (block .SignedHeader .Header .DataHash )
95+ abciBlock .Header .DataHash = cmbytes .HexBytes (block .SignedHeader .Header .DataHash )
9696
9797 return & abciBlock , nil
9898}
9999
100100// ToABCIBlockMeta converts Rollkit block into BlockMeta format defined by ABCI
101- func ToABCIBlockMeta (block * types.Block ) (* tmtypes .BlockMeta , error ) {
102- tmblock , err := ToABCIBlock (block )
101+ func ToABCIBlockMeta (block * types.Block ) (* cmtypes .BlockMeta , error ) {
102+ cmblock , err := ToABCIBlock (block )
103103 if err != nil {
104104 return nil , err
105105 }
106- blockID := tmtypes .BlockID {Hash : tmblock .Hash ()}
106+ blockID := cmtypes .BlockID {Hash : cmblock .Hash ()}
107107
108- return & tmtypes .BlockMeta {
108+ return & cmtypes .BlockMeta {
109109 BlockID : blockID ,
110- BlockSize : tmblock .Size (),
111- Header : tmblock .Header ,
112- NumTxs : len (tmblock .Txs ),
110+ BlockSize : cmblock .Size (),
111+ Header : cmblock .Header ,
112+ NumTxs : len (cmblock .Txs ),
113113 }, nil
114114}
0 commit comments