types

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2019 License: Apache-2.0 Imports: 30 Imported by: 3

Documentation

Index

Constants

View Source
const (
	Decimal        = 4     //4位精度
	TotalQOSAmount = 100e8 //100亿
)
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

View Source
const (
	QOSCoinName = "QOS"
)

Variables

View Source
var (
	UnitQOS                     = math.Pow(10, Decimal)           // QOS unit
	DefaultTotalUnitQOSQuantity = int64(TotalQOSAmount * UnitQOS) // total QOS amount

	DefaultBlockInterval = int64(5)   // 5 seconds
	UnitQOSGas           = int64(100) // 1 QOS = 100 gas
)
View Source
var (
	DefaultCLIHome  = os.ExpandEnv("$HOME/.qoscli")
	DefaultNodeHome = os.ExpandEnv("$HOME/.qosd")
)
View Source
var (
	// event type for invariant checking
	EventTypeInvariantCheck = "invariant_check"
)

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 FileMD5 added in v0.0.6

func FileMD5(filepath string) (string, error)

func FormatInvariant added in v0.0.6

func FormatInvariant(module, name, msg string, coins types.BaseCoins, broken bool) (string, types.BaseCoins, bool)

FormatInvariant returns a standardized invariant message along with a boolean indicating whether the invariant has been broken.

func GetDefaultChainId added in v0.0.2

func GetDefaultChainId() (string, error)

Get default chain-id.

func GetIntFromFlag added in v0.0.8

func GetIntFromFlag(flag string, allowZero bool) (amount btypes.BigInt, err error)

从flag中解析Int值

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

func Uint64ToBigEndian added in v0.0.6

func Uint64ToBigEndian(i uint64) []byte

Uint64ToBigEndian - marshals uint64 to a bigendian byte slice so it can be sorted

Types

type AppModule added in v0.0.6

type AppModule interface {
	AppModuleGenesis

	// registers
	RegisterInvariants(InvariantRegistry)
	RegisterQuerier(QueryRegistry)

	BeginBlock(context.Context, abci.RequestBeginBlock)
	EndBlock(context.Context, abci.RequestEndBlock) []abci.ValidatorUpdate
}

AppModule is the standard form for an application module

func NewGenesisOnlyAppModule added in v0.0.6

func NewGenesisOnlyAppModule(amg AppModuleGenesis) AppModule

NewGenesisOnlyAppModule creates a new GenesisOnlyAppModule object

type AppModuleBasic added in v0.0.6

type AppModuleBasic interface {
	Name() string
	RegisterCodec(*amino.Codec)

	// genesis
	DefaultGenesis() json.RawMessage
	ValidateGenesis(json.RawMessage) error

	// mapper and hooks
	GetMapperAndHooks() MapperWithHooks

	// client functionality
	GetTxCmds(*amino.Codec) []*cobra.Command
	GetQueryCmds(*amino.Codec) []*cobra.Command

	RegisterRestRoutes(ctx cliContext.CLIContext, routes *mux.Router)
}

type AppModuleGenesis added in v0.0.6

type AppModuleGenesis interface {
	AppModuleBasic
	InitGenesis(context.Context, *baseabci.BaseApp, json.RawMessage) []abci.ValidatorUpdate
	ExportGenesis(context.Context) json.RawMessage
}

_________________________________________________________ AppModuleGenesis is the standard form for an application module genesis functions

type BasicManager added in v0.0.6

type BasicManager map[string]AppModuleBasic

collections of AppModuleBasic

func NewBasicManager added in v0.0.6

func NewBasicManager(modules ...AppModuleBasic) BasicManager

func (BasicManager) AddQueryCommands added in v0.0.6

func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command, cdc *amino.Codec)

add all query commands to the rootQueryCmd

func (BasicManager) AddTxCommands added in v0.0.6

func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command, cdc *amino.Codec)

add all tx commands to the rootTxCmd

func (BasicManager) DefaultGenesis added in v0.0.6

func (bm BasicManager) DefaultGenesis() map[string]json.RawMessage

Provided default genesis information for all modules

func (BasicManager) RegisterCodec added in v0.0.6

func (bm BasicManager) RegisterCodec(cdc *amino.Codec)

RegisterCodecs registers all module codecs

func (BasicManager) RegisterRoutes added in v0.0.8

func (bm BasicManager) RegisterRoutes(ctx cliContext.CLIContext, routes *mux.Router)

func (BasicManager) ValidateGenesis added in v0.0.6

func (bm BasicManager) ValidateGenesis(genesis map[string]json.RawMessage) error

Provided default genesis information for all modules

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 GenesisOnlyAppModule added in v0.0.6

type GenesisOnlyAppModule struct {
	AppModuleGenesis
}

___________________________ app module

func (GenesisOnlyAppModule) BeginBlock added in v0.0.6

func (gam GenesisOnlyAppModule) BeginBlock(ctx context.Context, req abci.RequestBeginBlock)

module begin-block

func (GenesisOnlyAppModule) EndBlock added in v0.0.6

module end-block

func (GenesisOnlyAppModule) RegisterInvariants added in v0.0.6

func (GenesisOnlyAppModule) RegisterInvariants(_ InvariantRegistry)

register invariants

func (GenesisOnlyAppModule) RegisterQuerier added in v0.0.6

func (GenesisOnlyAppModule) RegisterQuerier(_ QueryRegistry)

register querier

type GenesisState added in v0.0.6

type GenesisState map[string]json.RawMessage

func (GenesisState) UnmarshalModuleState added in v0.0.6

func (gs GenesisState) UnmarshalModuleState(cdc *amino.Codec, module string, state interface{}) interface{}

type Hooks added in v0.0.6

type Hooks interface {
	// return mapper name who use this hooks
	HookMapper() string
}

hooks for mappers

type HooksMapper added in v0.0.6

type HooksMapper interface {
	SetHooks(hooks Hooks)
}

type HooksMapperRegistry added in v0.0.6

type HooksMapperRegistry interface {
	RegisterHooksMapper(map[string]MapperWithHooks)
}

type InvarRoute added in v0.0.6

type InvarRoute struct {
	ModuleName string
	Route      string
	Invar      Invariant
}

invariant route

func NewInvarRoute added in v0.0.6

func NewInvarRoute(moduleName, route string, invar Invariant) InvarRoute

NewInvarRoute - create an InvarRoute object

func (InvarRoute) FullRoute added in v0.0.6

func (i InvarRoute) FullRoute() string

get the full invariance route

type Invariant added in v0.0.6

type Invariant func(ctx context.Context) (string, types.BaseCoins, bool)

An Invariant is a function which tests a particular invariant. The invariant returns a descriptive message about what happened and total tokens, the mint module always return a negative value and a boolean indicating whether the invariant has been broken. The simulator will then halt and print the logs.

type InvariantRegistry added in v0.0.6

type InvariantRegistry interface {
	RegisterInvarRoute(moduleName, route string, invar Invariant)
}

expected interface for registering invariants

type Invariants added in v0.0.6

type Invariants []Invariant

Invariants defines a group of invariants

type KeyValuePair added in v0.0.7

type KeyValuePair struct {
	Key   []byte
	Value interface{}
}

type KeyValuePairs added in v0.0.7

type KeyValuePairs []KeyValuePair

type Manager added in v0.0.6

type Manager struct {
	Modules            map[string]AppModule
	OrderInitGenesis   []string
	OrderExportGenesis []string
	OrderBeginBlockers []string
	OrderEndBlockers   []string
}

____________________________________________________________________________ module manager provides the high level utility for managing and executing operations for a group of modules

func NewManager added in v0.0.6

func NewManager(modules ...AppModule) *Manager

NewModuleManager creates a new Manager object

func (*Manager) BeginBlock added in v0.0.6

BeginBlock performs begin block functionality for all modules. It creates a child context with an event manager to aggregate events emitted from all modules.

func (*Manager) EndBlock added in v0.0.6

EndBlock performs end block functionality for all modules. It creates a child context with an event manager to aggregate events emitted from all modules.

func (*Manager) ExportGenesis added in v0.0.6

func (m *Manager) ExportGenesis(ctx context.Context) map[string]json.RawMessage

perform export genesis functionality for modules

func (*Manager) InitGenesis added in v0.0.6

func (m *Manager) InitGenesis(ctx context.Context, bapp *baseabci.BaseApp, genesisData map[string]json.RawMessage) abci.ResponseInitChain

perform init genesis functionality for modules

func (*Manager) RegisterInvariants added in v0.0.6

func (m *Manager) RegisterInvariants(ir InvariantRegistry)

register all module routes and module invariant routes

func (*Manager) RegisterMapperAndHooks added in v0.0.6

func (m *Manager) RegisterMapperAndHooks(hmr HooksMapperRegistry, paramsInitializerModule string, ps ...ParamSet)

register all module mapper and hooks routes

func (*Manager) RegisterQueriers added in v0.0.6

func (m *Manager) RegisterQueriers(qr QueryRegistry)

register all module querier routes

func (*Manager) SetOrderBeginBlockers added in v0.0.6

func (m *Manager) SetOrderBeginBlockers(moduleNames ...string)

set the order of set begin-blocker calls

func (*Manager) SetOrderEndBlockers added in v0.0.6

func (m *Manager) SetOrderEndBlockers(moduleNames ...string)

set the order of set end-blocker calls

func (*Manager) SetOrderExportGenesis added in v0.0.6

func (m *Manager) SetOrderExportGenesis(moduleNames ...string)

set the order of export genesis calls

func (*Manager) SetOrderInitGenesis added in v0.0.6

func (m *Manager) SetOrderInitGenesis(moduleNames ...string)

set the order of init genesis calls

type MapperWithHooks added in v0.0.6

type MapperWithHooks struct {
	Mapper mapper.IMapper
	Hooks  Hooks
}

mapper for db

func NewMapperWithHooks added in v0.0.6

func NewMapperWithHooks(mapper mapper.IMapper, hooks Hooks) MapperWithHooks

func (*MapperWithHooks) IsNil added in v0.0.6

func (mh *MapperWithHooks) IsNil() bool

type MetricsMapper added in v0.0.8

type MetricsMapper interface {
	SetUpMetrics(cfg *config.InstrumentationConfig)
}

type ParamSet added in v0.0.7

type ParamSet interface {
	// 参数键值对
	KeyValuePairs() KeyValuePairs

	// 单个参数类型和值校验
	ValidateKeyValue(key string, value string) (interface{}, btypes.Error)

	// 参数所属模块名
	GetParamSpace() string

	// 参数校验
	Validate() btypes.Error

	// 设置单个参数
	SetKeyValue(key string, value interface{}) btypes.Error
}

参数接口,不同模块参数结构必须实现该接口并注册到params模块才能正常使用params提供的参数管理方法。

type ParamsInitializer added in v0.0.7

type ParamsInitializer interface {
	RegisterParamSet(ps ...ParamSet)
}

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.AccAddress, qos btypes.BigInt, qscs QSCs) *QOSAccount

func NewQOSAccountWithAddress added in v0.0.4

func NewQOSAccountWithAddress(addr btypes.AccAddress) *QOSAccount

func NewQOSAccountZero added in v0.0.4

func NewQOSAccountZero() *QOSAccount

func ParseAccounts added in v0.0.4

func ParseAccounts(str, clientHome 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) MarshalJSON added in v0.0.8

func (account *QOSAccount) MarshalJSON() ([]byte, error)

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

设置币种币值

func (*QOSAccount) UnmarshalJSON added in v0.0.8

func (account *QOSAccount) UnmarshalJSON(bz []byte) 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

type Querier added in v0.0.6

type Querier = func(ctx context.Context, path []string, req abci.RequestQuery) (res []byte, err btypes.Error)

type QueryRegistry added in v0.0.6

type QueryRegistry interface {
	RegisterQueryRoute(module string, query Querier)
}

Jump to

Keyboard shortcuts

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