common

package
v0.0.0-...-8ae4d99 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCalldata = errors.New("invalid calldata")
	ErrNotTransfer     = errors.New("not a transfer")
)

Functions

func Body

func Body(w http.ResponseWriter, body any, meta any) error

func BodyMultiple

func BodyMultiple(w http.ResponseWriter, body any, meta any) error

func ChecksumAddress

func ChecksumAddress(addr string) string

func Decrypt

func Decrypt(encryptedValue string, key []byte) (string, error)

func Encrypt

func Encrypt(secretValue string, key []byte) (string, error)

func Filter

func Filter[T any](slice []T, f func(T) bool) []T

func GenerateKey

func GenerateKey() ([]byte, error)

func GetContextAddress

func GetContextAddress(ctx context.Context) (string, bool)

GetContextAddress returns the indexer.ContextKeyAddress from the context

func HexToBigInt

func HexToBigInt(hex string) *big.Int

func HexToPrivateKey

func HexToPrivateKey(privateKeyHex string) (*ecdsa.PrivateKey, error)

func IsSameHexAddress

func IsSameHexAddress(a, b string) bool

func JSONRPCBody

func JSONRPCBody(w http.ResponseWriter, id int, body any, meta any) error

func JSONRPCMultiBody

func JSONRPCMultiBody(w http.ResponseWriter, ids []int, bodies []any, meta any) error

func ParseERC20Transfer

func ParseERC20Transfer(calldata []byte) (common.Address, common.Address, *big.Int, error)

ParseERC20Transfer parses the calldata of an ERC20 transfer from a smart contract Execute function

func Remove

func Remove[T any](slice []T, index int) []T

func ShortenName

func ShortenName(s string, length int) string

func StreamedBody

func StreamedBody(w http.ResponseWriter, body string) error

Types

type AddressResponse

type AddressResponse struct {
	Address string `json:"address"`
}

type ImageFormat

type ImageFormat string
const (
	JPG  ImageFormat = "jpg"
	JPEG ImageFormat = "jpeg"
	PNG  ImageFormat = "png"
	GIF  ImageFormat = "gif"
	WEBP ImageFormat = "webp"
)

type Nonce

type Nonce struct {
	Seq uint64
	Key *big.Int
}

func NewNonce

func NewNonce() (*Nonce, error)

GenerateNonce generates a nonce which is a unique number that can only be used once. This nonce is a uint256 composed of a uint64 and a uint192. The uin192 contains an epoch timestamp in the last 10 digits

func ParseNonce

func ParseNonce(nonce *big.Int) *Nonce

ParseNonce parses a nonce from a big.Int containing a uint256 with the first 64 bits being the key and the last 192 bits being the seq.

func (*Nonce) BigInt

func (n *Nonce) BigInt() *big.Int

func (*Nonce) String

func (n *Nonce) String() string

type Pagination

type Pagination struct {
	Limit  int `json:"limit"`
	Offset int `json:"offset"`
	Total  int `json:"total"`
}

type Response

type Response struct {
	// The response type
	// in: body
	ResponseType ResponseType `json:"response_type"`
	Object       any          `json:"object,omitempty"`
	Array        any          `json:"array,omitempty"`
	Meta         any          `json:"meta,omitempty"`
}

Response is the default response object swagger:response defaultResponse

type ResponseType

type ResponseType string
const (
	ResponseTypeObject ResponseType = "object"
	ResponseTypeArray  ResponseType = "array"
	ResponseTypeSecure ResponseType = "secure"
)

type SizedImages

type SizedImages struct {
	Big    []byte
	Medium []byte
	Small  []byte
}

func ParseImage

func ParseImage(file multipart.File) (*SizedImages, error)

Jump to

Keyboard shortcuts

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