common

package
v1.18.0-RC8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2024 License: MIT Imports: 10 Imported by: 4

Documentation

Overview

Provides the data structures and methods to work with the common data structures.

Index

Constants

View Source
const (
	ZCNExponent = 10
	// TokenUnit represents the minimum token unit (sas)
	TokenUnit = 1e10
)

Variables

View Source
var (
	// ErrNegativeValue is returned if a float value is a negative number
	ErrNegativeValue = errors.New("negative coin value")
	// ErrTooManyDecimals is returned if a value has more than 10 decimal places
	ErrTooManyDecimals = errors.New("too many decimal places")
	// ErrTooLarge is returned if a value is greater than math.MaxInt64
	ErrTooLarge = errors.New("value is too large")
	// ErrUint64OverflowsFloat64 is returned if when converting a uint64 to a float64 overflow float64
	ErrUint64OverflowsFloat64 = errors.New("uint64 overflows float64")
	// ErrUint64AddOverflow is returned if when adding uint64 values overflow uint64
	ErrUint64AddOverflow = errors.New("uint64 addition overflow")
)
View Source
var ErrInvalidTime = errors.New("invalid time")

Functions

func AutoFormatBalance added in v1.2.86

func AutoFormatBalance(b Balance) (string, error)

AutoFormatBalance returns a string representation of the balance with the most

func AutoFormatStatic added in v1.2.88

func AutoFormatStatic(amount int64) (string, error)

func FormatBalance added in v1.2.86

func FormatBalance(b Balance, unit BalanceUnit) (string, error)

FormatBalance returns a string representation of the balance with the given unit.

func FormatStatic added in v1.2.88

func FormatStatic(amount int64, unit string) (string, error)

func GetPathFields added in v1.8.6

func GetPathFields(p string) ([]string, error)

func MustAddInt added in v1.8.10

func MustAddInt(a, b int) int

func ParseBalanceStatic added in v1.2.88

func ParseBalanceStatic(str string) (int64, error)

func ParseTime added in v1.7.7

func ParseTime(now time.Time, input string) (*time.Time, error)

ParseTime parse a time string with 4 formats

+1h5m : now (local timezone) + 1h5m
+3900 : now (local timezone) +3900s
1647858200 : Unix timestamp
2022-03-21 10:21:38 : parse UTC date string with YYYY-MM-dd HH:mm:ss

Parameters

  • now is the current time
  • input is the time string to parse

func TryAddInt added in v1.8.10

func TryAddInt(a, b int) (int, error)

Types

type Balance

type Balance uint64

Balance represents client's balance in Züs native token fractions (SAS = 10^-10 ZCN).

func AddBalance added in v1.8.13

func AddBalance(c, b Balance) (Balance, error)

AddBalance adds c and b, returning an error if the values overflow

func ParseBalance added in v1.2.86

func ParseBalance(str string) (Balance, error)

func ToBalance

func ToBalance(token float64) (Balance, error)

ToBalance converts ZCN tokens to Balance.

  • token amount of ZCN tokens.

func (Balance) AutoFormat added in v1.2.86

func (b Balance) AutoFormat() (string, error)

AutoFormat returns a string representation of the balance with the most

func (Balance) Format added in v1.2.86

func (b Balance) Format(unit BalanceUnit) (string, error)

Format returns a string representation of the balance with the given unit.

  • unit is the balance unit.

func (Balance) String

func (b Balance) String() string

String implements fmt.Stringer interface.

func (Balance) ToToken

func (b Balance) ToToken() (float64, error)

ToToken converts Balance to ZCN tokens.

type BalanceUnit added in v1.2.86

type BalanceUnit byte
const (
	SAS BalanceUnit = iota
	UZCN
	MZCN
	ZCN
)

func (*BalanceUnit) Parse added in v1.2.86

func (unit *BalanceUnit) Parse(s string) error

func (BalanceUnit) String added in v1.2.86

func (unit BalanceUnit) String() string

type Key

type Key string

A Key represents an identifier. It can be a pool ID, client ID, smart contract address, etc.

type Size

type Size int64

A Size represents a size in bytes.

func (Size) String

func (s Size) String() string

String implements fmt.Stringer interface

type Timestamp

type Timestamp int64

Timestamp represents Unix time (e.g. in seconds)

func Now

func Now() Timestamp

Now current datetime

func (Timestamp) ToTime

func (t Timestamp) ToTime() time.Time

ToTime converts the Timestamp to standard time.Time

func (Timestamp) Within

func (t Timestamp) Within(seconds Timestamp) bool

Within ensures a given timestamp is within certain number of seconds

Directories

Path Synopsis
errors module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL