github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/version/version.go (about)

     1  package version
     2  
     3  import (
     4  	"fmt"
     5  	"math/big"
     6  
     7  	"github.com/unicornultrafoundation/go-u2u/params"
     8  )
     9  
    10  func init() {
    11  	params.VersionMajor = 1     // Major version component of the current release
    12  	params.VersionMinor = 1     // Minor version component of the current release
    13  	params.VersionPatch = 0     // Patch version component of the current release
    14  	params.VersionMeta = "rc.1" // Version metadata to append to the version string
    15  }
    16  
    17  func BigToString(b *big.Int) string {
    18  	if len(b.Bytes()) > 8 {
    19  		return "_malformed_version_"
    20  	}
    21  	return U64ToString(b.Uint64())
    22  }
    23  
    24  func AsString() string {
    25  	return ToString(uint16(params.VersionMajor), uint16(params.VersionMinor), uint16(params.VersionPatch))
    26  }
    27  
    28  func AsU64() uint64 {
    29  	return ToU64(uint16(params.VersionMajor), uint16(params.VersionMinor), uint16(params.VersionPatch))
    30  }
    31  
    32  func AsBigInt() *big.Int {
    33  	return new(big.Int).SetUint64(AsU64())
    34  }
    35  
    36  func ToU64(vMajor, vMinor, vPatch uint16) uint64 {
    37  	return uint64(vMajor)*1e12 + uint64(vMinor)*1e6 + uint64(vPatch)
    38  }
    39  
    40  func ToString(major, minor, patch uint16) string {
    41  	return fmt.Sprintf("%d.%d.%d", major, minor, patch)
    42  }
    43  
    44  func U64ToString(v uint64) string {
    45  	return ToString(uint16((v/1e12)%1e6), uint16((v/1e6)%1e6), uint16(v%1e6))
    46  }