github.com/okex/exchain@v1.8.0/libs/tendermint/rpc/core/ibc_utils.go (about) 1 package core 2 3 import ( 4 "github.com/okex/exchain/libs/tendermint/proto/version" 5 coretypes "github.com/okex/exchain/libs/tendermint/rpc/core/types" 6 "github.com/okex/exchain/libs/tendermint/types" 7 ) 8 9 func ConvBlock2CM40Block(r *types.Block) *types.CM40Block { 10 ret := &types.CM40Block{ 11 IBCHeader: *ConvHeadersToIbcHeader(&r.Header), 12 Data: r.Data, 13 Evidence: r.Evidence, 14 LastCommit: ConvCommitToIBCCommit(&r.Header, r.LastCommit), 15 } 16 return ret 17 } 18 19 func ConvBlockID2CM40BlockID(r types.BlockID) types.IBCBlockID { 20 return types.IBCBlockID{ 21 Hash: r.Hash, 22 PartSetHeader: types.IBCPartSetHeader{ 23 Total: uint32(r.PartsHeader.Total), 24 Hash: r.PartsHeader.Hash, 25 }, 26 } 27 } 28 29 func ConvResultCommitTOIBC(r *coretypes.ResultCommit) *coretypes.IBCResultCommit { 30 v := ConvSignheaderToIBCSignHeader(&r.SignedHeader) 31 ret := &coretypes.IBCResultCommit{ 32 IBCSignedHeader: *v, 33 CanonicalCommit: r.CanonicalCommit, 34 } 35 return ret 36 } 37 38 func ConvSignheaderToIBCSignHeader(h *types.SignedHeader) *types.IBCSignedHeader { 39 ret := &types.IBCSignedHeader{ 40 IBCHeader: ConvHeadersToIbcHeader(h.Header), 41 Commit: ConvCommitToIBCCommit(h.Header, h.Commit), 42 } 43 44 return ret 45 } 46 func ConvHeadersToIbcHeader(h *types.Header) *types.IBCHeader { 47 ret := &types.IBCHeader{ 48 Version: version.Consensus{ 49 Block: uint64(h.Version.Block), 50 App: uint64(h.Version.App), 51 }, 52 ChainID: h.ChainID, 53 Height: h.Height, 54 Time: h.Time, 55 LastBlockID: types.IBCBlockID{ 56 // TODO 57 Hash: h.LastBlockID.Hash, 58 PartSetHeader: types.IBCPartSetHeader{ 59 Total: uint32(h.LastBlockID.PartsHeader.Total), 60 Hash: h.LastBlockID.PartsHeader.Hash, 61 }, 62 }, 63 LastCommitHash: h.LastCommitHash, 64 DataHash: h.DataHash, 65 ValidatorsHash: h.ValidatorsHash, 66 NextValidatorsHash: h.NextValidatorsHash, 67 ConsensusHash: h.ConsensusHash, 68 AppHash: h.AppHash, 69 LastResultsHash: h.LastResultsHash, 70 EvidenceHash: h.EvidenceHash, 71 ProposerAddress: h.ProposerAddress, 72 } 73 74 return ret 75 } 76 77 func ConvCommitToIBCCommit(hh *types.Header, h *types.Commit) *types.IBCCommit { 78 ret := &types.IBCCommit{ 79 Height: h.Height, 80 Round: int32(h.Round), 81 BlockID: types.IBCBlockID{ 82 Hash: h.BlockID.Hash, 83 PartSetHeader: types.IBCPartSetHeader{ 84 Total: uint32(h.BlockID.PartsHeader.Total), 85 Hash: h.BlockID.PartsHeader.Hash, 86 }, 87 }, 88 Signatures: h.Signatures, 89 } 90 91 return ret 92 } 93 94 func ConvEventBlock2CM40Event(block types.EventDataNewBlock) types.CM40EventDataNewBlock { 95 ret := types.CM40EventDataNewBlock{} 96 ret.Block = ConvBlock2CM40Block(block.Block) 97 ret.ResultBeginBlock = block.ResultBeginBlock 98 ret.ResultEndBlock = block.ResultEndBlock 99 return ret 100 }