github.com/okex/exchain@v1.8.0/libs/tendermint/types/ibc.go (about)

     1  package types
     2  
     3  import (
     4  	"github.com/okex/exchain/libs/tendermint/libs/protoio"
     5  	tmproto "github.com/okex/exchain/libs/tendermint/proto/types"
     6  )
     7  
     8  // CanonicalizeVote transforms the given Proposal to a CanonicalProposal.
     9  func IBCCanonicalizeProposal(chainID string, proposal *Proposal) tmproto.CanonicalProposal {
    10  	return tmproto.CanonicalProposal{
    11  		Type:      tmproto.ProposalType,
    12  		Height:    proposal.Height,       // encoded as sfixed64
    13  		Round:     int64(proposal.Round), // encoded as sfixed64
    14  		POLRound:  int64(proposal.POLRound),
    15  		BlockID:   IBCCanonicalizeBlockID(&proposal.BlockID),
    16  		Timestamp: proposal.Timestamp,
    17  		ChainID:   chainID,
    18  	}
    19  }
    20  
    21  func IBCCanonicalizeBlockID(rbid *BlockID) *tmproto.CanonicalBlockID {
    22  	var cbid *tmproto.CanonicalBlockID
    23  	if rbid == nil || rbid.IsZero() {
    24  		cbid = nil
    25  	} else {
    26  		cbid = &tmproto.CanonicalBlockID{
    27  			Hash:          rbid.Hash,
    28  			PartSetHeader: IBCCanonicalizePartSetHeader(rbid.PartsHeader),
    29  		}
    30  	}
    31  
    32  	return cbid
    33  }
    34  
    35  // CanonicalizeVote transforms the given PartSetHeader to a CanonicalPartSetHeader.
    36  func IBCCanonicalizePartSetHeader(psh PartSetHeader) tmproto.CanonicalPartSetHeader {
    37  	pp := psh.ToIBCProto()
    38  	return tmproto.CanonicalPartSetHeader{
    39  		Total: uint32(pp.Total),
    40  		Hash:  pp.Hash,
    41  	}
    42  }
    43  func ProposalSignBytes(chainID string, p *Proposal) []byte {
    44  	pb := IBCCanonicalizeProposal(chainID, p)
    45  	bz, err := protoio.MarshalDelimited(&pb)
    46  	if err != nil {
    47  		panic(err)
    48  	}
    49  
    50  	return bz
    51  }
    52  func VoteSignBytes(chainID string, vote *Vote) []byte {
    53  	pb := IBCCanonicalizeVote(chainID, vote)
    54  	bz, err := protoio.MarshalDelimited(&pb)
    55  	if err != nil {
    56  		panic(err)
    57  	}
    58  	return bz
    59  }
    60  func IBCCanonicalizeVote(chainID string, vote *Vote) tmproto.CanonicalVote {
    61  	return tmproto.CanonicalVote{
    62  		Type:      tmproto.SignedMsgType(vote.Type),
    63  		Height:    vote.Height,       // encoded as sfixed64
    64  		Round:     int64(vote.Round), // encoded as sfixed64
    65  		BlockID:   IBCCanonicalizeBlockID(&vote.BlockID),
    66  		Timestamp: vote.Timestamp,
    67  		ChainID:   chainID,
    68  	}
    69  }