utils

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: AGPL-3.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTP_RETRY_ATTEMPTS = 3
	HTTP_RETRY_INTERVAL = 5
)
View Source
const (
	TransferEventSignature      = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
	OrderCreatedEventSignature  = "0x40ccd1ceb111a3c186ef9911e1b876dc1f789ed331b86097b3b8851055b6a137"
	OrderSettledEventSignature  = "0x98ece21e01a01cbe1d1c0dad3b053c8fbd368f99be78be958fcf1d1d13fd249a"
	OrderRefundedEventSignature = "0x0736fe428e1747ca8d387c2e6fa1a31a0cde62d3a167c40a46ade59a3cdc828e"
)

Event signatures for Gateway and token contract events

Variables

This section is empty.

Functions

func APIResponse

func APIResponse(ctx *gin.Context, httpCode int, status string, message string, data interface{})

APIResponse is a helper function to return an API response

func AbsPercentageDeviation

func AbsPercentageDeviation(trueValue, measuredValue decimal.Decimal) decimal.Decimal

AbsPercentageDeviation returns the absolute percentage deviation between two values

func BigMin

func BigMin(x, y *big.Int) *big.Int

BigMin returns the minimum value between two big numbers

func Byte32ToString

func Byte32ToString(b [32]byte) string

Byte32ToString converts [32]byte to string

func CalculatePaymentOrderAmountInUSD added in v0.1.1

func CalculatePaymentOrderAmountInUSD(amount decimal.Decimal, token *ent.Token, institution *ent.Institution) decimal.Decimal

CalculatePaymentOrderAmountInUSD calculates the amount in USD for a payment order

func CallProviderWithHMAC added in v0.0.2

func CallProviderWithHMAC(ctx context.Context, providerID, method, path string, payload map[string]interface{}) (map[string]interface{}, error)

CallProviderWithHMAC makes an authenticated HTTP request to a provider with HMAC signature Returns the parsed JSON response data and error

func ContainsString

func ContainsString(slice []string, item string) bool

ContainsString returns true if the slice contains the given string

func DecodeOrderCreatedEvent

func DecodeOrderCreatedEvent(log types.Log) (map[string]interface{}, error)

DecodeOrderCreatedEvent decodes an OrderCreated event from RPC log

func DecodeOrderRefundedEvent

func DecodeOrderRefundedEvent(log types.Log) (map[string]interface{}, error)

DecodeOrderRefundedEvent decodes an OrderRefunded event from RPC log

func DecodeOrderSettledEvent

func DecodeOrderSettledEvent(log types.Log) (map[string]interface{}, error)

DecodeOrderSettledEvent decodes an OrderSettled event from RPC log

func DecodeTransferEvent

func DecodeTransferEvent(log types.Log) (map[string]interface{}, error)

DecodeTransferEvent decodes a Transfer event from RPC log

func Difference

func Difference(a, b []string) []string

Difference returns the elements in `a` that aren't in `b`.

func FormatTimestampToGMT1

func FormatTimestampToGMT1(timestamp time.Time) (string, error)

FormatTimestampToGMT1 formats the timestamp to GMT+1 (Africa/Lagos time zone) and returns a formatted string.

func FromSubunit

func FromSubunit(amountInSubunit *big.Int, decimals int8) decimal.Decimal

FromSubunit converts an amount in subunits represented as a *big.Int back to its decimal representation with the given number of decimal places (decimals). It returns the amount as a decimal.Decimal.

func GetErrorData

func GetErrorData(err error) []types.ErrorData

GetErrorData returns a list of error data

func GetErrorMsg

func GetErrorMsg(fe validator.FieldError) string

GetErrorMsg returns a list of meaningful error messages from binding tags. Reference: https://blog.logrocket.com/gin-binding-in-go-a-tutorial-with-examples/

func GetInstitutionByCode

func GetInstitutionByCode(ctx context.Context, institutionCode string, enabledFiatCurrency bool) (*ent.Institution, error)

GetInstitutionByCode returns the institution for a given institution code

func GetPaymasterAccount

func GetPaymasterAccount(chainId int64) (string, error)

GetPaymasterAccount returns the paymaster account for the given chain ID

func GetTokenRateFromQueue

func GetTokenRateFromQueue(tokenSymbol string, orderAmount decimal.Decimal, fiatCurrency string, marketRate decimal.Decimal) (decimal.Decimal, error)

GetTokenRateFromQueue gets the rate of a token from the priority queue

func GetUserOperationByReceipt

func GetUserOperationByReceipt(userOpHash string, chainId int64) (map[string]interface{}, error)

GetUserOperationByReceipt fetches the user operation by hash

func GetUserOperationStatus

func GetUserOperationStatus(userOpHash string, chainId int64) (bool, error)

GetUserOperationStatus returns the status of the user operation

func HexToDecimal

func HexToDecimal(hexStr string) decimal.Decimal

HexToDecimal converts a hex string to a decimal.Decimal

func InitializeUserOperation

func InitializeUserOperation(ctx context.Context, client types.RPCClient, rpcUrl, sender, salt string) (*userop.UserOperation, error)

Initialize user operation with defaults

func IsBase64

func IsBase64(s string) bool

IsBase64 checks if a string is a valid Base64 encoded string

func IsURL

func IsURL(s string) bool

IsURL checks if a string is a valid URL

func IsValidEthereumAddress

func IsValidEthereumAddress(address string) bool

IsValidEthereumAddress checks if a string is a valid Ethereum address

func IsValidFileURL

func IsValidFileURL(url string) bool
IsValidFileURL checks if a URL is a valid file URL

(supports only file urls ending with .jpg, .jpeg, .png, or .pdf)

func IsValidHttpsUrl

func IsValidHttpsUrl(urlStr string) bool

Helper function to validate HTTPS URL

func IsValidMobileNumber

func IsValidMobileNumber(number string) bool

IsValidMobileNumber checks if a string is a valid mobile number

func IsValidTronAddress

func IsValidTronAddress(address string) bool

IsValidTronAddress checks if a string is a valid Tron address

func MapToStruct

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

func Median

func Median(data []decimal.Decimal) decimal.Decimal

Median returns the median value of a decimal slice

func Paginate

func Paginate(ctx *gin.Context) (page int, offset int, limit int)

Paginate parses the pagination query params and returns the offset(page) and limit(pageSize)

func ParseJSONResponse

func ParseJSONResponse(res *http.Response) (map[string]interface{}, error)

ParseJSONResponse parses a JSON response

func ParseTopicToBigInt

func ParseTopicToBigInt(paddedHexString string) *big.Int

ParseTopicToBigInt converts a padded hex string to a big.Int

func ParseTopicToByte32

func ParseTopicToByte32(paddedHexString string) [32]byte

ParseTopicToByte32 converts a padded hex string to a [32]byte

func ParseTopicToByte32Flexible added in v0.1.0

func ParseTopicToByte32Flexible(topic interface{}) [32]byte

ParseTopicToByte32Flexible handles both string and [32]uint8 inputs for compatibility

func ParseTopicToTronAddress

func ParseTopicToTronAddress(paddedHexString string) string

ParseTopicToTronAddress converts a padded hex string to a Tron address

func PersonalSign

func PersonalSign(message string, privateKey *ecdsa.PrivateKey) ([]byte, error)

PersonalSign is an equivalent of ethers.personal_sign for signing ethereum messages Ref: https://github.com/etaaa/Golang-Ethereum-Personal-Sign/blob/main/main.go

func ProcessRPCEvents

func ProcessRPCEvents(events []interface{}, eventSignature string) error

ProcessRPCEvents processes RPC events and converts them to the same format as Thirdweb Insight

func ProcessRPCEventsBySignature

func ProcessRPCEventsBySignature(events []interface{}) error

ProcessRPCEventsBySignature processes RPC events and automatically detects their signature for decoding

func Retry

func Retry(attempts int, sleep time.Duration, fn func() error) error

Retry is a function that attempts to execute a given function multiple times until it succeeds or the maximum number of attempts is reached. It sleeps for a specified duration between each attempt. Parameters: - attempts: The maximum number of attempts to execute the function. - sleep: The duration to sleep between each attempt. - fn: The function to be executed. Returns: - error: The error returned by the function, if any.

func SendPaymentOrderWebhook

func SendPaymentOrderWebhook(ctx context.Context, paymentOrder *ent.PaymentOrder) error

SendPaymentOrderWebhook notifies a sender when the status of a payment order changes

func SendUserOperation

func SendUserOperation(userOp *userop.UserOperation, chainId int64) (string, string, int64, error)

SendUserOperation sends the user operation

func SignUserOperation

func SignUserOperation(userOperation *userop.UserOperation, chainId int64) error

SignUserOperation signs the user operation

func SponsorUserOperation

func SponsorUserOperation(userOp *userop.UserOperation, mode string, token string, chainId int64) error

SponsorUserOperation sponsors the user operation with different AA services

func StringToByte32

func StringToByte32(s string) [32]byte

StringToByte32 converts string to [32]byte

func StructToMap

func StructToMap(input interface{}) map[string]interface{}

StructToMap converts a struct to a map[string]interface{}

func ToSubunit

func ToSubunit(amount decimal.Decimal, decimals int8) *big.Int

ToSubunit converts a decimal amount to the smallest subunit representation. It takes the amount and the number of decimal places (decimals) and returns the amount in subunits as a *big.Int.

func UnpackEventData

func UnpackEventData(paddedHexString, contractABI, eventName string) ([]interface{}, error)

UnpackEventData unpacks the data from a padded hex string using the ABI

func ValidateAccount added in v0.0.2

func ValidateAccount(ctx context.Context, institutionCode, accountIdentifier string) (string, error)

ValidateAccount validates if an account exists for the given institution and account identifier Returns the account name if verification is successful, or an error if verification fails

func ValidateRate added in v0.0.2

func ValidateRate(ctx context.Context, token *ent.Token, currency *ent.FiatCurrency, amount decimal.Decimal, providerID, networkFilter string) (decimal.Decimal, error)

ValidateRate validates if a provided rate is achievable for the given parameters

Types

type BucketData added in v0.0.2

type BucketData struct {
	Currency  string
	MinAmount decimal.Decimal
	MaxAmount decimal.Decimal
}

parseBucketKey parses and validates bucket key format

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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