common

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NativeToken = sdk.DefaultBondDenom
	TestToken   = "xxb"
)

const

View Source
const (
	// common error
	ErrorMissingRequiredParam errorCodeV2 = 60001
	ErrorInvalidParam         errorCodeV2 = 60002
	ErrorServerException      errorCodeV2 = 60003
	ErrorDataNotExist         errorCodeV2 = 60004
	ErrorCodecFails           errorCodeV2 = 60005
	ErrorABCIQueryFails       errorCodeV2 = 60006
	ErrorArgsWithLimit        errorCodeV2 = 60007

	// account error
	ErrorInvalidAddress errorCodeV2 = 61001

	// order error
	ErrorOrderNotExist        errorCodeV2 = 62001
	ErrorInvalidCurrency      errorCodeV2 = 62002
	ErrorEmptyInstrumentID    errorCodeV2 = 62003
	ErrorInstrumentIDNotExist errorCodeV2 = 62004

	// staking error
	ErrorInvalidValidatorAddress errorCodeV2 = 63001
	ErrorInvalidDelegatorAddress errorCodeV2 = 63002
)

const

Variables

This section is empty.

Functions

func BlackHoleAddress

func BlackHoleAddress() sdk.AccAddress

BlackHoleAddress returns the black hole address

func BytesToInt64

func BytesToInt64(buf []byte) int64

BytesToInt64 converts bytes to int64

func GetErrorResponseJSON

func GetErrorResponseJSON(code int, msg, detailMsg string) []byte

GetErrorResponseJSON marshals the base response into JSON bytes

func GetPage

func GetPage(page, perPage int) (offset, limit int)

GetPage returns the offset and limit for data query

func HandleErrorMsg

func HandleErrorMsg(w http.ResponseWriter, cliCtx context.CLIContext, msg string)

HandleErrorMsg handles the error msg

func HandleErrorResponseV2

func HandleErrorResponseV2(w http.ResponseWriter, statusCode int, errCode errorCodeV2)

HandleErrorResponseV2 is the handler of error response with V2 standard

func HandleResponseV2

func HandleResponseV2(w http.ResponseWriter, data []byte, err error)

HandleResponseV2 handles the response of V2 standard

func HandleSuccessResponseV2

func HandleSuccessResponseV2(w http.ResponseWriter, data []byte)

HandleSuccessResponseV2 is the handler of successful response with V2 standard

func HasSufficientCoins

func HasSufficientCoins(addr sdk.AccAddress, availableCoins, amt sdk.Coins) (err error)

HasSufficientCoins checks whether the account has sufficient coins

func Int64ToBytes

func Int64ToBytes(i int64) []byte

Int64ToBytes converts int64 to bytes

func JSONMarshalV2

func JSONMarshalV2(v interface{}) ([]byte, error)

JSONMarshalV2 marshals info into JSON based on V2 standard

func JSONUnmarshalV2

func JSONUnmarshalV2(data []byte, v interface{}) error

JSONUnmarshalV2 unmarshals JSON bytes based on V2 standard

func MulAndQuo

func MulAndQuo(a, b, c sdk.Dec) sdk.Dec

mulAndQuo returns a * b / c

func Paginate

func Paginate(pageStr, perPageStr string) (page int, perPage int, err error)

Paginate converts page params for a paginated query,

func SkipSysTestChecker

func SkipSysTestChecker(t *testing.T)

SkipSysTestChecker is supported to used in System Unit Test (described in http://gitlab.okcoin-inc.com/dex/okexchain/issues/472) if System environment variables "SYS_TEST_ALL" is set to 1, all of the system test will be enable. \n if System environment variables "ORM_MYSQL_SYS_TEST" is set to 1,

all of the system test in orm_mysql_sys_test.go will be enble.

Types

type BaseResponse

type BaseResponse struct {
	Code      int         `json:"code"`
	Msg       string      `json:"msg"`
	DetailMsg string      `json:"detail_msg"`
	Data      interface{} `json:"data"`
}

BaseResponse is the main frame of response

func GetBaseResponse

func GetBaseResponse(data interface{}) *BaseResponse

GetBaseResponse gets a default base response

func GetErrorResponse

func GetErrorResponse(code int, msg, detailMsg string) *BaseResponse

GetErrorResponse creates an error base response

type ListDataRes

type ListDataRes struct {
	Data      interface{} `json:"data"`
	ParamPage ParamPage   `json:"param_page"`
}

ListDataRes is the struct of list data result

type ListResponse

type ListResponse struct {
	Code      int         `json:"code"`
	Msg       string      `json:"msg"`
	DetailMsg string      `json:"detail_msg"`
	Data      ListDataRes `json:"data"`
}

ListResponse is the frame of list response

func GetEmptyListResponse

func GetEmptyListResponse(total, page, perPage int) *ListResponse

GetEmptyListResponse returns an empty list response

func GetListResponse

func GetListResponse(total, page, perPage int, data interface{}) *ListResponse

GetListResponse returns a list response

type ParamPage

type ParamPage struct {
	Page    int `json:"page"`
	PerPage int `json:"per_page"`
	Total   int `json:"total"`
}

ParamPage is the struct of params page

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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