utils

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PngMimeType = "image/png"

	TextRegex = `^[a-zA-Z0-9 +.,;:?!'’"\-_/()\[\]~&#$—%]+$`
)

Variables

View Source
var (
	ErrInvalidURL            = errors.New("invalid url")
	ErrInvalidGithubRawURL   = errors.New("invalid github raw url")
	ErrInvalidText           = fmt.Errorf("invalid text format, doesn't conform to regex %s", TextRegex)
	ErrTextTooLong           = errors.New("text should be less than 500 characters")
	ErrEmptyText             = errors.New("text is empty")
	ErrInvalidImageExtension = errors.New(
		"invalid image extension. only " + strings.Join(ImageExtensions, ",") + " is supported",
	)
	ErrInvalidImageMimeType     = errors.New("invalid image mime-type. only png is supported")
	ErrInvalidURLLength         = errors.New("url length should be no larger than 1024 character")
	ErrURLPointingToLocalServer = errors.New("url should not point to local server")
	ErrEmptyURL                 = errors.New("url is empty")
	ErrInvalidTwitterURLRegex   = errors.New(
		"invalid twitter url, it should be of the format https://twitter.com/<username> or https://x.com/<username>",
	)
	ErrResponseTooLarge = errors.New("response too large, allowed size is 1 MB")
)
View Source
var (
	// ImageExtensions List of common image file extensions
	// Only support PNG for now to reduce surface area of image validation
	// We do NOT want to support formats like SVG since they can be used for javascript injection
	// If we get pushback on only supporting png, we can support jpg, jpeg, gif, etc. later
	ImageExtensions = []string{".png"}
)

Functions

func CreateTxMgrByKeyFile

func CreateTxMgrByKeyFile(
	privateKey *ecdsa.PrivateKey,
	rpcClient eth.Client,
	chainID *big.Int,
	logger log.Logger,
) (txmgr.TxManager, error)

func DecodeJSONFromFile

func DecodeJSONFromFile(filepath string, data any) error

func LogSubError

func LogSubError(lg log.Logger, err error)

func TypedErr

func TypedErr(e interface{}) error

func WrapError

func WrapError(mainErr interface{}, subErr interface{}) error

func WriteJSONToFile

func WriteJSONToFile(filepath string, data any) error

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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