utils

package
v0.0.0-...-26275c3 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AmountToFloat64

func AmountToFloat64(amount uint64, decimals uint8) float64

AmountToFloat64 converts amount lamports to float64 with given decimals.

func AmountToString

func AmountToString(amount uint64, decimals uint8) string

AmountToString converts amount lamports to string with given decimals.

func AmountToUint64

func AmountToUint64(amount float64, decimals uint8) uint64

AmountToUint64 converts amount from float64 to uint64 with given decimals.

func Base58ToBytes

func Base58ToBytes(s string) ([]byte, error)

Base58ToBytes converts base58 string to bytes.

func Base64ToBytes

func Base64ToBytes(s string) ([]byte, error)

Base64ToBytes converts base64 string to bytes.

func BytesToBase64

func BytesToBase64(b []byte) string

BytesToBase64 converts bytes to base64 string.

func DecodeTransaction

func DecodeTransaction(base64Tx string) (types.Transaction, error)

DecodeTransaction returns a transaction from a base64 encoded transaction.

func EncodeTransaction

func EncodeTransaction(tx types.Transaction) (string, error)

EncodeTransaction returns a base64 encoded transaction.

func Float64ToString

func Float64ToString(amount float64) string

Float64ToString converts float64 to string with minimum number of decimals. For example, 1.000000000 will be converted to "1", 1.100000000 will be converted to "1.1".

func GetFileTypeByURI

func GetFileTypeByURI(uri string) string

GetFileTypeByURI returns the file type of the given URI

func GetVarType

func GetVarType(v interface{}) string

GetVarType returns the type of the given variable as a string.

func IntAmountToFloat64

func IntAmountToFloat64(amount int64, decimals uint8) float64

IntAmountToFloat64 converts int64 amount lamports to float64 with given decimals.

func MapToStruct

func MapToStruct(m map[string]interface{}, s interface{}) error

MapToStruct converts a map to a struct.

func Pointer

func Pointer[T any](i T) *T

Pointer converts any type to a pointer. This is useful for passing a value to a function that expects a pointer.

func PrettyPrint

func PrettyPrint(s interface{})

PrettyPrint returns a pretty-printed string representation of a struct or a map.

func PrettyString

func PrettyString(s interface{}) string

PrettyString returns a pretty-printed string representation of a struct or a map.

func StackErrors

func StackErrors(errs ...error) error

StackErrors wraps multiple errors into a single error.

func TrimRightZeros

func TrimRightZeros(str string) string

TrimRightZeros trims trailing zeros from string.

func TrimStringBetween

func TrimStringBetween(str, start, end string) string

Trim string between two substrings and return the string without it and substrings.

func WrapError

func WrapError(errs ...error) error

WrapError wraps the rpc.JsonRpcError to a standard error.

Types

type StakedError

type StakedError struct {
	// contains filtered or unexported fields
}

StakedError is a struct that holds multiple errors and returns them as a single error.

func NewStakedError

func NewStakedError(errs ...error) *StakedError

NewStakedError creates a new StakedError instance.

func (*StakedError) As

func (e *StakedError) As(target interface{}) bool

As returns the first error that matches target.

func (*StakedError) Error

func (e *StakedError) Error() string

Error returns the error message. Implements the error interface.

func (*StakedError) Is

func (e *StakedError) Is(target error) bool

Is returns true if the error is equal to target.

func (*StakedError) Unwrap

func (e *StakedError) Unwrap() error

Unwrap returns the underlying error. Implements the errors.Unwrap interface.

Jump to

Keyboard shortcuts

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