common

package
v0.17.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2023 License: Apache-2.0 Imports: 14 Imported by: 2

README

x/common

The x/common directory holds helper and utility functions to be utilized by other x/ cosmos-sdk modules.

Documentation

Index

Constants

View Source
const (
	DenomNIBI = "unibi"
	DenomUSDC = "uusdc"
	DenomNUSD = "unusd"
	DenomBTC  = "ubtc"
	DenomETH  = "ueth"

	ModuleName = "common"

	TreasuryPoolModuleAccount = "treasury_pool"

	PairSeparator = ":"
)

Variables

View Source
var (
	Pair_NIBI_NUSD = AssetPair{Token0: DenomNIBI, Token1: DenomNUSD}
	Pair_USDC_NUSD = AssetPair{Token0: DenomUSDC, Token1: DenomNUSD}
	Pair_BTC_NUSD  = AssetPair{Token0: DenomBTC, Token1: DenomNUSD}
	Pair_ETH_NUSD  = AssetPair{Token0: DenomETH, Token1: DenomNUSD}

	ErrInvalidTokenPair = sdkerrors.Register(ModuleName, 1, "invalid token pair")
	APrecision          = uint256.NewInt().SetUint64(1)

	// Precision for int representation in sdk.Int objects
	Precision = int64(1_000_000)

	BigIntPrecision = int64(18)
)
View Source
var (
	ErrInvalidLengthCommon        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowCommon          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupCommon = fmt.Errorf("proto: unexpected end of group")
)
View Source
var AssetPairKeyEncoder collections.KeyEncoder[AssetPair] = assetPairKeyEncoder{}

Functions

func AddrsToStrings added in v0.5.2

func AddrsToStrings(addrs ...sdk.AccAddress) []string

func CombineErrors added in v0.17.0

func CombineErrors(errs ...error) (outErr error)

Combines errors into single error. Error descriptions are ordered the same way they're passed to the function.

func CombineErrorsFromStrings added in v0.17.0

func CombineErrorsFromStrings(strs ...string) (err error)

func CombineErrorsGeneric added in v0.17.0

func CombineErrorsGeneric(errAnySlice any) (out error, ok bool)

func StringsToAddrs added in v0.5.2

func StringsToAddrs(strs ...string) []sdk.AccAddress

func ToError added in v0.17.0

func ToError(v any) (out error, ok bool)

ToError converts a value to an error type if it: (1) is a string, (2) has a String() function (3) is already an error. (4) or is a slice of these cases I.e., the types supported are: string, []string, error, []error, fmt.Stringer, []fmt.Stringer

The type is inferred from try catch blocks at runtime.

func TryCatch added in v0.17.0

func TryCatch(callback func()) func() error

TryCatch is an implementation of the try-catch block from languages like C++ and JS. Given a 'callback' function, TryCatch defers and recovers from any panics or errors, allowing one to safely handle multiple panics in succession.

Typically, you'll write something like: `err := TryCatch(aRiskyFunction)()`

Usage example:

var calmPanic error = TryCatch(func() {
  panic("something crazy")
})()
fmt.Println(calmPanic.Error()) // prints "something crazy"

Note that TryCatch doesn't return an error. It returns a function that returns an error. Only when you call the output of TryCatch will it "feel" like a try-catch block from other languages.

This means that TryCatch can be used to restart go routines that panic as well.

Types

type AssetPair

type AssetPair struct {
	Token0 string `protobuf:"bytes,1,opt,name=token0,proto3" json:"token0,omitempty"`
	Token1 string `protobuf:"bytes,2,opt,name=token1,proto3" json:"token1,omitempty"`
}

func MustNewAssetPair added in v0.5.2

func MustNewAssetPair(pair string) AssetPair

MustNewAssetPair returns a new asset pair. It will panic if 'pair' is invalid. The form, "token0:token1", is expected for 'pair'.

func NewAssetPair added in v0.5.2

func NewAssetPair(pair string) (AssetPair, error)

NewAssetPair returns a new asset pair instance if the pair is valid. The form, "token0:token1", is expected for 'pair'. Use this function to return an error instead of panicking.

func (AssetPair) BaseDenom added in v0.11.0

func (pair AssetPair) BaseDenom() string

func (*AssetPair) Descriptor added in v0.5.2

func (*AssetPair) Descriptor() ([]byte, []int)

func (*AssetPair) Equal added in v0.5.2

func (this *AssetPair) Equal(that interface{}) bool

func (AssetPair) Inverse

func (pair AssetPair) Inverse() AssetPair

func (*AssetPair) Marshal added in v0.5.2

func (m *AssetPair) Marshal() (dAtA []byte, err error)

func (*AssetPair) MarshalTo added in v0.5.2

func (m *AssetPair) MarshalTo(dAtA []byte) (int, error)

func (*AssetPair) MarshalToSizedBuffer added in v0.5.2

func (m *AssetPair) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*AssetPair) ProtoMessage added in v0.5.2

func (*AssetPair) ProtoMessage()

func (AssetPair) QuoteDenom added in v0.11.0

func (pair AssetPair) QuoteDenom() string

func (*AssetPair) Reset added in v0.5.2

func (m *AssetPair) Reset()

func (*AssetPair) Size added in v0.5.2

func (m *AssetPair) Size() (n int)

func (AssetPair) String

func (pair AssetPair) String() string

String returns the string representation of the asset pair.

Note that this differs from the output of the proto-generated 'String' method.

func (*AssetPair) Unmarshal added in v0.5.2

func (m *AssetPair) Unmarshal(dAtA []byte) error

func (AssetPair) Validate added in v0.5.2

func (pair AssetPair) Validate() error

Validate performs a basic validation of the market params

func (*AssetPair) VerboseEqual added in v0.5.2

func (this *AssetPair) VerboseEqual(that interface{}) error

func (*AssetPair) XXX_DiscardUnknown added in v0.5.2

func (m *AssetPair) XXX_DiscardUnknown()

func (*AssetPair) XXX_Marshal added in v0.5.2

func (m *AssetPair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*AssetPair) XXX_Merge added in v0.5.2

func (m *AssetPair) XXX_Merge(src proto.Message)

func (*AssetPair) XXX_Size added in v0.5.2

func (m *AssetPair) XXX_Size() int

func (*AssetPair) XXX_Unmarshal added in v0.5.2

func (m *AssetPair) XXX_Unmarshal(b []byte) error

type AssetPairs added in v0.5.2

type AssetPairs []AssetPair

AssetPairs is a set of AssetPair, one per pair.

func NewAssetPairs added in v0.5.2

func NewAssetPairs(pairStrings ...string) (pairs AssetPairs)

NewAssetPairs constructs a new asset pair set. A panic will occur if one of the provided pair names is invalid.

func (AssetPairs) Contains added in v0.5.2

func (haystack AssetPairs) Contains(needle AssetPair) bool

Contains checks if a token pair is contained within 'Pairs'

func (AssetPairs) MarshalJSON added in v0.5.2

func (pairs AssetPairs) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom JSON marshaller for the AssetPairs type to allow nil AssetPairs to be encoded as empty

func (AssetPairs) Strings added in v0.5.2

func (pairs AssetPairs) Strings() []string

func (AssetPairs) Validate added in v0.5.2

func (pairs AssetPairs) Validate() error

type StringSet added in v0.17.0

type StringSet map[string]struct{}

func NewStringSet added in v0.17.0

func NewStringSet(strs ...string) StringSet

func (StringSet) Add added in v0.17.0

func (set StringSet) Add(s string)

func (StringSet) Has added in v0.17.0

func (set StringSet) Has(s string) bool

func (StringSet) Len added in v0.17.0

func (set StringSet) Len() int

func (StringSet) Remove added in v0.17.0

func (set StringSet) Remove(s string)

func (StringSet) ToSlice added in v0.17.0

func (set StringSet) ToSlice() []string

Jump to

Keyboard shortcuts

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