types

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//1 iris = 10^3 iris-milli
	Milli = "milli"

	//1 iris = 10^6 iris-micro
	Micro = "micro"

	//1 iris = 10^9 iris-nano
	Nano = "nano"

	//1 iris = 10^12 iris-pico
	Pico = "pico"

	//1 iris = 10^15 iris-femto
	Femto = "femto"

	//1 iris = 10^18 iris-atto
	Atto = "atto"

	Native     Origin = 0x01
	External   Origin = 0x02
	UserIssued Origin = 0x03
)

Variables

View Source
var (
	MainUnit = func(coinName string) Unit {
		return NewUnit(coinName, 0)
	}

	MilliUnit = func(coinName string) Unit {
		denom := fmt.Sprintf("%s-%s", coinName, Milli)
		return NewUnit(denom, 3)
	}

	MicroUnit = func(coinName string) Unit {
		denom := fmt.Sprintf("%s-%s", coinName, Micro)
		return NewUnit(denom, 6)
	}

	NanoUnit = func(coinName string) Unit {
		denom := fmt.Sprintf("%s-%s", coinName, Nano)
		return NewUnit(denom, 9)
	}

	PicoUnit = func(coinName string) Unit {
		denom := fmt.Sprintf("%s-%s", coinName, Pico)
		return NewUnit(denom, 12)
	}

	FemtoUnit = func(coinName string) Unit {
		denom := fmt.Sprintf("%s-%s", coinName, Femto)
		return NewUnit(denom, 15)
	}

	AttoUnit = func(coinName string) Unit {
		denom := fmt.Sprintf("%s-%s", coinName, Atto)
		return NewUnit(denom, 18)
	}
)

Functions

func CoinTypeKey

func CoinTypeKey(coinName string) string

TODO currently only iris token is supported

func GetCoin

func GetCoin(coinStr string) (denom, amount string, err error)

func GetCoinName

func GetCoinName(coinStr string) (coinName string, err error)

func RatEq added in v0.7.0

func RatEq(t *testing.T, exp, got Rat) (*testing.T, bool, string, Rat, Rat)

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

func RatsEqual added in v0.7.0

func RatsEqual(r1s, r2s []Rat) bool

test if two rat arrays are equal

Types

type AnteHandler

type AnteHandler func(ctx sdk.Context, tx sdk.Tx) (newCtx sdk.Context, result sdk.Result, abort bool)

AnteHandler authenticates transactions, before their internal messages are handled. If newCtx.IsZero(), ctx is used instead.

type CoinType

type CoinType struct {
	Name    string `json:"name"`
	MinUnit Unit   `json:"min_unit"`
	Units   Units  `json:"units"`
	Origin  Origin `json:"origin"`
	Desc    string `json:"desc"`
}

func NewDefaultCoinType

func NewDefaultCoinType(name string) CoinType

func (CoinType) Convert

func (ct CoinType) Convert(orgCoinStr string, denom string) (destCoinStr string, err error)

func (CoinType) ConvertToMinCoin

func (ct CoinType) ConvertToMinCoin(coinStr string) (coin sdk.Coin, err error)

func (CoinType) GetMainUnit

func (ct CoinType) GetMainUnit() (unit Unit)

func (CoinType) GetMinUnit

func (ct CoinType) GetMinUnit() (unit Unit)

func (CoinType) GetUnit

func (ct CoinType) GetUnit(denom string) (u Unit, err error)

func (CoinType) String

func (ct CoinType) String() string

type FeePreprocessHandler

type FeePreprocessHandler func(ctx sdk.Context, tx sdk.Tx) error

type FeeRefundHandler

type FeeRefundHandler func(ctx sdk.Context, tx sdk.Tx, result sdk.Result) (sdk.Coin, error)

type Handler

type Handler func(ctx sdk.Context, msg sdk.Msg) sdk.Result

Handler defines the core of the state transition function of an application.

type Origin

type Origin = byte

func ToOrigin

func ToOrigin(origin string) (og Origin, err error)

type Rat

type Rat struct {
	*big.Rat `json:"rat"`
}

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

func MinRat added in v0.7.0

func MinRat(r1, r2 Rat) Rat

minimum rational between two

func NewRat

func NewRat(Numerator int64, Denominator ...int64) Rat

New - create a new Rat from integers

func NewRatFromBigInt added in v0.7.0

func NewRatFromBigInt(num *big.Int, denom ...*big.Int) Rat

NewRatFromBigInt constructs Rat from big.Int

func NewRatFromDecimal added in v0.7.0

func NewRatFromDecimal(decimalStr string, prec int) (f Rat, err sdk.Error)

create a rational from decimal string or integer string precision is the number of values after the decimal point which should be read

func NewRatFromInt added in v0.7.0

func NewRatFromInt(num sdk.Int, denom ...sdk.Int) Rat

NewRatFromInt constructs Rat from Int

func OneRat added in v0.7.0

func OneRat() Rat

func ZeroRat added in v0.7.0

func ZeroRat() Rat

nolint - common values

func (Rat) Add added in v0.7.0

func (r Rat) Add(r2 Rat) Rat

func (Rat) DecimalString

func (r Rat) DecimalString(prec int) string

DecimalString

func (Rat) Denom added in v0.7.0

func (r Rat) Denom() sdk.Int

func (Rat) Equal added in v0.7.0

func (r Rat) Equal(r2 Rat) bool

func (Rat) EvaluateBig added in v0.7.0

func (r Rat) EvaluateBig() *big.Int

evaluate the rational using bankers rounding

func (Rat) FloatString added in v0.7.0

func (r Rat) FloatString() string

func (Rat) GT added in v0.7.0

func (r Rat) GT(r2 Rat) bool

func (Rat) GTE added in v0.7.0

func (r Rat) GTE(r2 Rat) bool

func (Rat) IsZero added in v0.7.0

func (r Rat) IsZero() bool

func (Rat) LT added in v0.7.0

func (r Rat) LT(r2 Rat) bool

func (Rat) LTE added in v0.7.0

func (r Rat) LTE(r2 Rat) bool

func (Rat) MarshalAmino added in v0.7.0

func (r Rat) MarshalAmino() (string, error)

Wraps r.MarshalText().

func (Rat) Mul added in v0.7.0

func (r Rat) Mul(r2 Rat) Rat

func (Rat) Num added in v0.7.0

func (r Rat) Num() sdk.Int

nolint

func (Rat) Quo added in v0.7.0

func (r Rat) Quo(r2 Rat) Rat

func (Rat) Round added in v0.7.0

func (r Rat) Round(precisionFactor int64) Rat

round Rat with the provided precisionFactor

func (Rat) RoundInt added in v0.7.0

func (r Rat) RoundInt() sdk.Int

RoundInt round the rational using bankers rounding

func (Rat) RoundInt64 added in v0.7.0

func (r Rat) RoundInt64() int64

RoundInt64 rounds the rational using bankers rounding

func (Rat) String added in v0.7.0

func (r Rat) String() string

func (Rat) Sub added in v0.7.0

func (r Rat) Sub(r2 Rat) Rat

func (Rat) ToLeftPadded added in v0.7.0

func (r Rat) ToLeftPadded(totalDigits int8) string

TODO panic if negative or if totalDigits < len(initStr)??? evaluate as an integer and return left padded string

func (*Rat) UnmarshalAmino added in v0.7.0

func (r *Rat) UnmarshalAmino(text string) (err error)

Requires a valid JSON string - strings quotes and calls UnmarshalText

type Unit

type Unit struct {
	Denom   string `json:"denom"`
	Decimal int    `json:"decimal"`
}

func NewUnit

func NewUnit(denom string, decimal int) Unit

func (Unit) GetPrecision

func (u Unit) GetPrecision() sdk.Int

type Units

type Units = []Unit

func GetDefaultUnits

func GetDefaultUnits(coin string) Units

Jump to

Keyboard shortcuts

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