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

     1  package version
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/tendermint/go-amino"
     7  )
     8  
     9  var (
    10  	// GitCommit is the current HEAD set using ldflags.
    11  	GitCommit string
    12  
    13  	// Version is the built softwares version.
    14  	Version = TMCoreSemVer
    15  )
    16  
    17  func init() {
    18  	if GitCommit != "" {
    19  		Version += "-" + GitCommit
    20  	}
    21  }
    22  
    23  const (
    24  	// TMCoreSemVer is the current version of Tendermint Core.
    25  	// It's the Semantic Version of the software.
    26  	// Must be a string because scripts like dist.sh read this file.
    27  	// XXX: Don't change the name of this variable or you will break
    28  	// automation :)
    29  
    30  	TMCoreSemVer = "0.33.9"
    31  
    32  	// ABCISemVer is the semantic version of the ABCI library
    33  	ABCISemVer  = "0.16.2"
    34  	ABCIVersion = ABCISemVer
    35  )
    36  
    37  // Protocol is used for implementation agnostic versioning.
    38  type Protocol uint64
    39  
    40  // Uint64 returns the Protocol version as a uint64,
    41  // eg. for compatibility with ABCI types.
    42  func (p Protocol) Uint64() uint64 {
    43  	return uint64(p)
    44  }
    45  
    46  var (
    47  	// P2PProtocol versions all p2p behaviour and msgs.
    48  	// This includes proposer selection.
    49  	P2PProtocol Protocol = 7
    50  
    51  	// BlockProtocol versions all block data structures and processing.
    52  	// This includes validity of blocks and state updates.
    53  	BlockProtocol Protocol = 10
    54  )
    55  
    56  var (
    57  	IBCP2PProtocol   Protocol = 8
    58  	IBCBlockProtocol Protocol = 11
    59  )
    60  
    61  //------------------------------------------------------------------------
    62  // Version types
    63  
    64  // App includes the protocol and software version for the application.
    65  // This information is included in ResponseInfo. The App.Protocol can be
    66  // updated in ResponseEndBlock.
    67  type App struct {
    68  	Protocol Protocol `json:"protocol"`
    69  	Software string   `json:"software"`
    70  }
    71  
    72  // Consensus captures the consensus rules for processing a block in the blockchain,
    73  // including all blockchain data structures and the rules of the application's
    74  // state transition machine.
    75  type Consensus struct {
    76  	Block Protocol `json:"block"`
    77  	App   Protocol `json:"app"`
    78  }
    79  
    80  func (c Consensus) AminoSize() int {
    81  	var size int
    82  	if c.Block != 0 {
    83  		size += 1 + amino.UvarintSize(uint64(c.Block))
    84  	}
    85  	if c.App != 0 {
    86  		size += 1 + amino.UvarintSize(uint64(c.App))
    87  	}
    88  	return size
    89  }
    90  
    91  func (c *Consensus) UnmarshalFromAmino(_ *amino.Codec, data []byte) error {
    92  	var dataLen uint64 = 0
    93  
    94  	for {
    95  		data = data[dataLen:]
    96  
    97  		if len(data) == 0 {
    98  			break
    99  		}
   100  
   101  		pos, aminoType, err := amino.ParseProtoPosAndTypeMustOneByte(data[0])
   102  		if err != nil {
   103  			return err
   104  		}
   105  		data = data[1:]
   106  
   107  		if aminoType != amino.Typ3_Varint {
   108  			return fmt.Errorf("expected Varint, got %v", aminoType)
   109  		}
   110  
   111  		switch pos {
   112  		case 1:
   113  			var n int
   114  			var uvint uint64
   115  			uvint, n, err = amino.DecodeUvarint(data)
   116  			if err != nil {
   117  				return err
   118  			}
   119  			c.Block = Protocol(uvint)
   120  			dataLen = uint64(n)
   121  		case 2:
   122  			var n int
   123  			var uvint uint64
   124  			uvint, n, err = amino.DecodeUvarint(data)
   125  			if err != nil {
   126  				return err
   127  			}
   128  			c.App = Protocol(uvint)
   129  			dataLen = uint64(n)
   130  		default:
   131  			return fmt.Errorf("unexpect feild num %d", pos)
   132  		}
   133  	}
   134  	return nil
   135  }