common

package
v0.19.2-rc2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: Apache-2.0 Imports: 4 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 (
	TreasuryPoolModuleAccount = "treasury_pool"
	// Precision for int representation in sdk.Int objects
	Precision = int64(1_000_000)
)

Variables

This section is empty.

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

This section is empty.

Directories

Path Synopsis
Package nullify provides methods to init nil values structs for test assertion.
Package nullify provides methods to init nil values structs for test assertion.
cli
Package network implements and exposes a fully operational in-process Tendermint test network that consists of at least one or potentially many validators.
Package network implements and exposes a fully operational in-process Tendermint test network that consists of at least one or potentially many validators.
mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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