types

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2019 License: Apache-2.0 Imports: 14 Imported by: 3

Documentation

Index

Constants

View Source
const (
	Qos         = int64(1e8)
	BlockReward = int64(0 * Qos)
)
View Source
const (
	Precision = 18

	// bytes required to represent the above precision
	// Ceiling[Log2[999 999 999 999 999 999]]
	DecimalPrecisionBits = 60
)

number of decimal places

Variables

View Source
var (
	DefaultCLIHome  = os.ExpandEnv("$HOME/.qoscli")
	DefaultNodeHome = os.ExpandEnv("$HOME/.qosd")
)

Functions

func DecEq added in v0.0.4

func DecEq(t *testing.T, exp, got Dec) (*testing.T, bool, string, string, string)

intended to be used with require/assert: require.True(DecEq(...))

func DecsEqual added in v0.0.4

func DecsEqual(d1s, d2s []Dec) bool

test if two decimal arrays are equal

func GetDefaultChainId added in v0.0.2

func GetDefaultChainId() (string, error)

Get default chain-id.

func ProtoQOSAccount added in v0.0.4

func ProtoQOSAccount() account.Account

func RegisterCodec added in v0.0.4

func RegisterCodec(cdc *go_amino.Codec)

为包内定义结构注册codec

Types

type Dec added in v0.0.4

type Dec struct {
	*big.Int `json:"int"`
}

NOTE: never use new(Dec) or else we will panic unmarshalling into the nil embedded big.Int

func MaxDec added in v0.0.4

func MaxDec(d1, d2 Dec) Dec

maximum decimal between two

func MinDec added in v0.0.4

func MinDec(d1, d2 Dec) Dec

minimum decimal between two

func MustNewDecFromStr added in v0.0.4

func MustNewDecFromStr(s string) Dec

Decimal from string, panic on error

func NewDec added in v0.0.4

func NewDec(i int64) Dec

create a new Dec from integer assuming whole number

func NewDecFromBigInt added in v0.0.4

func NewDecFromBigInt(i *big.Int) Dec

create a new Dec from big integer assuming whole numbers CONTRACT: prec <= Precision

func NewDecFromBigIntWithPrec added in v0.0.4

func NewDecFromBigIntWithPrec(i *big.Int, prec int64) Dec

create a new Dec from big integer assuming whole numbers CONTRACT: prec <= Precision

func NewDecFromInt added in v0.0.4

func NewDecFromInt(i btypes.BigInt) Dec

create a new Dec from big integer assuming whole numbers CONTRACT: prec <= Precision

func NewDecFromIntWithPrec added in v0.0.4

func NewDecFromIntWithPrec(i btypes.BigInt, prec int64) Dec

create a new Dec from big integer with decimal place at prec CONTRACT: prec <= Precision

func NewDecFromStr added in v0.0.4

func NewDecFromStr(str string) (d Dec, err error)

create a decimal from an input decimal string. valid must come in the form:

(-) whole integers (.) decimal integers

examples of acceptable input include:

-123.456
456.7890
345
-456789

NOTE - An error will return if more decimal places are provided in the string than the constant Precision.

CONTRACT - This function does not mutate the input str.

func NewDecWithPrec added in v0.0.4

func NewDecWithPrec(i, prec int64) Dec

create a new Dec from integer with decimal place at prec CONTRACT: prec <= Precision

func OneDec added in v0.0.4

func OneDec() Dec

func ZeroDec added in v0.0.4

func ZeroDec() Dec

nolint - common values

func (Dec) Abs added in v0.0.4

func (d Dec) Abs() Dec

func (Dec) Add added in v0.0.4

func (d Dec) Add(d2 Dec) Dec

addition

func (Dec) Ceil added in v0.0.4

func (d Dec) Ceil() Dec

Ceil returns the smallest interger value (as a decimal) that is greater than or equal to the given decimal.

func (Dec) Equal added in v0.0.4

func (d Dec) Equal(d2 Dec) bool

func (Dec) Format added in v0.0.4

func (d Dec) Format(s fmt.State, verb rune)

format decimal state

func (Dec) GT added in v0.0.4

func (d Dec) GT(d2 Dec) bool

func (Dec) GTE added in v0.0.4

func (d Dec) GTE(d2 Dec) bool

func (Dec) IsInteger added in v0.0.4

func (d Dec) IsInteger() bool

is integer, e.g. decimals are zero

func (Dec) IsNegative added in v0.0.4

func (d Dec) IsNegative() bool

func (Dec) IsNil added in v0.0.4

func (d Dec) IsNil() bool

______________________________________________________________________________________________ nolint

func (Dec) IsPositive added in v0.0.4

func (d Dec) IsPositive() bool

func (Dec) IsZero added in v0.0.4

func (d Dec) IsZero() bool

func (Dec) LT added in v0.0.4

func (d Dec) LT(d2 Dec) bool

func (Dec) LTE added in v0.0.4

func (d Dec) LTE(d2 Dec) bool

func (Dec) MarshalAmino added in v0.0.4

func (d Dec) MarshalAmino() (string, error)

wraps d.MarshalText()

func (Dec) MarshalJSON added in v0.0.4

func (d Dec) MarshalJSON() ([]byte, error)

MarshalJSON marshals the decimal

func (Dec) Mul added in v0.0.4

func (d Dec) Mul(d2 Dec) Dec

multiplication

func (Dec) MulInt added in v0.0.4

func (d Dec) MulInt(i btypes.BigInt) Dec

multiplication

func (Dec) MulTruncate added in v0.0.4

func (d Dec) MulTruncate(d2 Dec) Dec

multiplication truncate

func (Dec) Neg added in v0.0.4

func (d Dec) Neg() Dec

func (Dec) Quo added in v0.0.4

func (d Dec) Quo(d2 Dec) Dec

quotient

func (Dec) QuoInt added in v0.0.4

func (d Dec) QuoInt(i btypes.BigInt) Dec

quotient

func (Dec) QuoTruncate added in v0.0.4

func (d Dec) QuoTruncate(d2 Dec) Dec

quotient truncate

func (Dec) RoundInt added in v0.0.4

func (d Dec) RoundInt() btypes.BigInt

RoundInt round the decimal using bankers rounding

func (Dec) RoundInt64 added in v0.0.4

func (d Dec) RoundInt64() int64

RoundInt64 rounds the decimal using bankers rounding

func (Dec) String added in v0.0.4

func (d Dec) String() string

func (Dec) Sub added in v0.0.4

func (d Dec) Sub(d2 Dec) Dec

subtraction

func (Dec) TruncateDec added in v0.0.4

func (d Dec) TruncateDec() Dec

TruncateDec truncates the decimals from the number and returns a Dec

func (Dec) TruncateInt added in v0.0.4

func (d Dec) TruncateInt() btypes.BigInt

TruncateInt truncates the decimals from the number and returns an Int

func (Dec) TruncateInt64 added in v0.0.4

func (d Dec) TruncateInt64() int64

TruncateInt64 truncates the decimals from the number and returns an int64

func (*Dec) UnmarshalAmino added in v0.0.4

func (d *Dec) UnmarshalAmino(text string) (err error)

requires a valid JSON string - strings quotes and calls UnmarshalText

func (*Dec) UnmarshalJSON added in v0.0.4

func (d *Dec) UnmarshalJSON(bz []byte) error

UnmarshalJSON defines custom decoding scheme

type Fraction added in v0.0.4

type Fraction struct {
	Value Dec `json:"value"`
}

func NewFraction added in v0.0.4

func NewFraction(numer, denomin int64) Fraction

func NewFractionFromBigInt added in v0.0.4

func NewFractionFromBigInt(numer, denomin btypes.BigInt) Fraction

func OneFraction added in v0.0.4

func OneFraction() Fraction

func ZeroFraction added in v0.0.4

func ZeroFraction() Fraction

func (Fraction) Add added in v0.0.4

func (frac Fraction) Add(f1 Fraction) Fraction

func (Fraction) Equal added in v0.0.4

func (frac Fraction) Equal(f1 Fraction) bool

func (Fraction) Mul added in v0.0.4

func (frac Fraction) Mul(f1 Fraction) Fraction

func (Fraction) MultiBigInt added in v0.0.4

func (frac Fraction) MultiBigInt(t btypes.BigInt) btypes.BigInt

func (Fraction) MultiInt64 added in v0.0.4

func (frac Fraction) MultiInt64(t int64) btypes.BigInt

func (Fraction) Sub added in v0.0.4

func (frac Fraction) Sub(f1 Fraction) Fraction

type QOSAccount added in v0.0.4

type QOSAccount struct {
	account.BaseAccount `json:"base_account"` // inherits BaseAccount
	QOS                 btypes.BigInt         `json:"qos"`  // coins in public chain
	QSCs                QSCs                  `json:"qscs"` // varied QSCs
}

func NewQOSAccount added in v0.0.4

func NewQOSAccount(addr btypes.Address, qos btypes.BigInt, qscs QSCs) *QOSAccount

func NewQOSAccountWithAddress added in v0.0.4

func NewQOSAccountWithAddress(addr btypes.Address) *QOSAccount

func NewQOSAccountZero added in v0.0.4

func NewQOSAccountZero() *QOSAccount

func ParseAccounts added in v0.0.4

func ParseAccounts(str string) ([]*QOSAccount, error)

Parse accounts from string address16lwp3kykkjdc2gdknpjy6u9uhfpa9q4vj78ytd,1000000qos,1000000qstars. Multiple accounts separated by ';'

func (*QOSAccount) EnoughOf added in v0.0.4

func (account *QOSAccount) EnoughOf(qos btypes.BigInt, qscs QSCs) bool

func (*QOSAccount) EnoughOfQOS added in v0.0.4

func (account *QOSAccount) EnoughOfQOS(qos btypes.BigInt) bool

是否有足够QOS

func (*QOSAccount) EnoughOfQSC added in v0.0.4

func (account *QOSAccount) EnoughOfQSC(qsc QSC) bool

是否有足够QSC

func (*QOSAccount) EnoughOfQSCs added in v0.0.4

func (account *QOSAccount) EnoughOfQSCs(qscs QSCs) bool

是否有足够QSCs

func (*QOSAccount) GetQOS added in v0.0.4

func (account *QOSAccount) GetQOS() btypes.BigInt

func (*QOSAccount) GetQSC added in v0.0.4

func (account *QOSAccount) GetQSC(qscName string) (qsc QSC, exists bool)

返回指定币种币值

func (*QOSAccount) GetQSCs added in v0.0.4

func (account *QOSAccount) GetQSCs() QSCs

func (*QOSAccount) Minus added in v0.0.4

func (account *QOSAccount) Minus(qos btypes.BigInt, qscs QSCs) error

减少QOS,QSCs

func (*QOSAccount) MinusQOS added in v0.0.4

func (account *QOSAccount) MinusQOS(qos btypes.BigInt) error

减少QOS,减少量小于0或结果小于0时返回错误

func (*QOSAccount) MinusQSC added in v0.0.4

func (account *QOSAccount) MinusQSC(qsc QSC) error

减少QSC

func (*QOSAccount) MinusQSCs added in v0.0.4

func (account *QOSAccount) MinusQSCs(qscs QSCs) error

减少QSCs

func (*QOSAccount) MustMinus added in v0.0.4

func (account *QOSAccount) MustMinus(qos btypes.BigInt, qscs QSCs)

func (*QOSAccount) MustMinusQOS added in v0.0.4

func (account *QOSAccount) MustMinusQOS(qos btypes.BigInt)

减少QOS,返回错误panic

func (*QOSAccount) MustMinusQSC added in v0.0.4

func (account *QOSAccount) MustMinusQSC(qsc QSC)

func (*QOSAccount) MustMinusQSCs added in v0.0.4

func (account *QOSAccount) MustMinusQSCs(qscs QSCs)

func (*QOSAccount) MustPlus added in v0.0.4

func (account *QOSAccount) MustPlus(qos btypes.BigInt, qscs QSCs)

func (*QOSAccount) MustPlusQOS added in v0.0.4

func (account *QOSAccount) MustPlusQOS(qos btypes.BigInt)

增加QOS,返回错误时panic

func (*QOSAccount) MustPlusQSC added in v0.0.4

func (account *QOSAccount) MustPlusQSC(qsc QSC)

func (*QOSAccount) MustPlusQSCs added in v0.0.4

func (account *QOSAccount) MustPlusQSCs(qscs QSCs)

func (*QOSAccount) Plus added in v0.0.4

func (account *QOSAccount) Plus(qos btypes.BigInt, qscs QSCs) error

增加QOS,QSCs

func (*QOSAccount) PlusQOS added in v0.0.4

func (account *QOSAccount) PlusQOS(qos btypes.BigInt) error

增加QOS,增加量小于0时返回错误

func (*QOSAccount) PlusQSC added in v0.0.4

func (account *QOSAccount) PlusQSC(qsc QSC) error

增加QSC

func (*QOSAccount) PlusQSCs added in v0.0.4

func (account *QOSAccount) PlusQSCs(qscs QSCs) error

增加QSCs

func (*QOSAccount) RemoveQSC added in v0.0.4

func (account *QOSAccount) RemoveQSC(qscName string)

移除QSC

func (*QOSAccount) SetQOS added in v0.0.4

func (account *QOSAccount) SetQOS(qos btypes.BigInt) error

设置QOS,币值必须大于等于0

func (*QOSAccount) SetQSC added in v0.0.4

func (account *QOSAccount) SetQSC(qsc QSC) error

设置币种币值

type QSC

type QSC = types.BaseCoin

func NewQSC

func NewQSC(name string, amount types.BigInt) *QSC

type QSCs

type QSCs = types.BaseCoins

func ParseCoins added in v0.0.2

func ParseCoins(str string) (btypes.BigInt, QSCs, error)

Parse QOS and QSCs from string str example : 100qos,100qstar

Jump to

Keyboard shortcuts

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