common

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

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

const

View Source
const (
	DefaultCodespace = "common"

	CodeInternalError              uint32 = 60100
	CodeInvalidPaginateParam       uint32 = 60101
	CodeCreateAddrFromBech32Failed uint32 = 60102
	CodeMarshalJSONFailed          uint32 = 60103
	CodeUnMarshalJSONFailed        uint32 = 60104 //"incorrectly formatted request data", err.Error()
	CodeStrconvFailed              uint32 = 60105
	CodeUnknownProposalType        uint32 = 60106
	CodeInsufficientCoins          uint32 = 60107
	CodeMissingRequiredParam       uint32 = 60108
	CodeInvalidParam               uint32 = 60109
	CodeServerException            uint32 = 60110
	CodeDataNotExist               uint32 = 60111
	CodeCodecFails                 uint32 = 60112
	CodeABCIQueryFails             uint32 = 60113
	CodeArgsWithLimit              uint32 = 60114
)

const uint32

View Source
const (
	// common error
	ErrorMissingRequiredParam errorCodeV2 = 60108
	ErrorInvalidParam         errorCodeV2 = 60109
	ErrorServerException      errorCodeV2 = 60110
	ErrorDataNotExist         errorCodeV2 = 60111
	ErrorCodecFails           errorCodeV2 = 60112
	ErrorABCIQueryFails       errorCodeV2 = 60113
	ErrorArgsWithLimit        errorCodeV2 = 60114

	// account error
	ErrorInvalidAddress errorCodeV2 = 60007

	// order error
	ErrorOrderNotExist        errorCodeV2 = 60300
	ErrorInvalidCurrency      errorCodeV2 = 60301
	ErrorEmptyInstrumentID    errorCodeV2 = 60302
	ErrorInstrumentIDNotExist errorCodeV2 = 60303

	// staking error
	ErrorInvalidValidatorAddress errorCodeV2 = 60700
	ErrorInvalidDelegatorAddress errorCodeV2 = 60701
)

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 CheckSignerAddress

func CheckSignerAddress(signers, delegators []sdk.AccAddress) bool

CheckSignerAddress delegators must be the same as to the signers and amount only one

func ErrCreateAddrFromBech32Failed

func ErrCreateAddrFromBech32Failed(addr string, msg string) sdk.EnvelopedErr

invalid address

func ErrInsufficientCoins

func ErrInsufficientCoins(codespace string, msg string) sdk.EnvelopedErr

func ErrInvalidPaginateParam

func ErrInvalidPaginateParam(page int, perPage int) sdk.EnvelopedErr

invalid paginate param

func ErrInvalidParam

func ErrInvalidParam(msg string) sdk.EnvelopedErr

func ErrMarshalJSONFailed

func ErrMarshalJSONFailed(msg string) sdk.EnvelopedErr

could not marshal result to JSON

func ErrStrconvFailed

func ErrStrconvFailed(msg string) sdk.EnvelopedErr

func ErrUnMarshalJSONFailed

func ErrUnMarshalJSONFailed(msg string) sdk.EnvelopedErr

could not unmarshal result to origin

func ErrUnknownProposalType

func ErrUnknownProposalType(codespace string, msg string) sdk.EnvelopedErr

func GetErrorResponseJSON

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

GetErrorResponseJSON marshals the base response into JSON bytes

func GetFixedLengthRandomString

func GetFixedLengthRandomString(n int) string

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, code uint32, 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 InitConfig

func InitConfig()

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 PanicTrace

func PanicTrace(kb int)

func SanityCheckHandler

func SanityCheckHandler(res *sdk.Result, err error)

func SkipSysTestChecker

func SkipSysTestChecker(t *testing.T)

SkipSysTestChecker is supported to used in System Unit Test (described in http://gitlab.okcoin-inc.com/dex/brczero/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.

func ValidateBool

func ValidateBool(param string) subspace.ValueValidatorFn

func ValidateConsensusType

func ValidateConsensusType(param string) subspace.ValueValidatorFn

func ValidateDecNotNeg

func ValidateDecNotNeg(param string) subspace.ValueValidatorFn

func ValidateDecPositive

func ValidateDecPositive(param string) subspace.ValueValidatorFn

func ValidateDenom

func ValidateDenom(param string) subspace.ValueValidatorFn

func ValidateDurationPositive

func ValidateDurationPositive(param string) subspace.ValueValidatorFn

func ValidateInt64Positive

func ValidateInt64Positive(param string) subspace.ValueValidatorFn

func ValidateRateNotNeg

func ValidateRateNotNeg(param string) subspace.ValueValidatorFn

func ValidateSysCoin

func ValidateSysCoin(param string) subspace.ValueValidatorFn

func ValidateSysCoins

func ValidateSysCoins(param string) subspace.ValueValidatorFn

func ValidateUint16Positive

func ValidateUint16Positive(param string) subspace.ValueValidatorFn

func ValidateUint64Positive

func ValidateUint64Positive(param string) subspace.ValueValidatorFn

Types

type BaseResponse

type BaseResponse struct {
	Code      uint32      `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 uint32, msg, detailMsg string) *BaseResponse

GetErrorResponse creates an error base response

type ConsensusType

type ConsensusType string
const (
	PoA  ConsensusType = "poa"
	DPoS ConsensusType = "dpos"
)

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

type SDKError

type SDKError struct {
	Codespace string `json:"codespace"`
	Code      uint32 `json:"code"`
	Message   string `json:"message"`
}

func ParseSDKError

func ParseSDKError(errMsg string) SDKError

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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