util

package
v0.0.0-...-2c8c8f7 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddressFromEcdsaPrivateKey

func AddressFromEcdsaPrivateKey(privateKey *ecdsa.PrivateKey) (common.Address, error)

func AddressFromEcdsaPrivateKeyString

func AddressFromEcdsaPrivateKeyString(privateKeyStr string) (common.Address, error)

func BuildApiKey

func BuildApiKey(appContract string, consumerPrivateKeyText string) (string, error)

BuildApiKey utility function to help build API key with specified APP contract address and consumer private key text.

func BuildBillingKey

func BuildBillingKey(appContract string, ownerPrivateKeyText string) (string, error)

BuildBillingKey utility function to help build billing key with specified APP contract address and its owner private key text.

func BuildPersonalSignMessage

func BuildPersonalSignMessage(message string) string

func EcdsaPrivateKeyFromString

func EcdsaPrivateKeyFromString(privateKeyStr string) (*ecdsa.PrivateKey, error)

func GetAddrByApiAuthKey

func GetAddrByApiAuthKey(contract string, apiKey *types.ApiAuthKey) (common.Address, error)

func GetAddrByApiKey

func GetAddrByApiKey(contract, apiKey string) (common.Address, error)

func GetAddrByBillingAuthKey

func GetAddrByBillingAuthKey(billingKey *types.BillingAuthKey) (common.Address, error)

func GetAddrByBillingKey

func GetAddrByBillingKey(billingKey string) (common.Address, error)

func GracefulShutdown

func GracefulShutdown(wg *sync.WaitGroup, cancel context.CancelFunc)

GracefulShutdown supports to clean up goroutines after termination signal captured.

func IsInterfaceValNil

func IsInterfaceValNil(i interface{}) bool

Helper function to check if interface value is nil, since "i == nil" checks nil interface case only. Refer to https://mangatmodi.medium.com/go-check-nil-interface-the-right-way-d142776edef1 for more details.

func IsZeroAddress

func IsZeroAddress(iaddress interface{}) bool

IsZeroAddress validate if it's a 0 address

func KLock

func KLock(key MutexKey)

func KUnlock

func KUnlock(key MutexKey)

func MustNewEthClientFromViper

func MustNewEthClientFromViper(customOpt ...func(*web3go.ClientOption)) *web3go.Client

func ParseApiKey

func ParseApiKey(apiKey string) (*types.ApiAuthKey, error)

func ParseBillingKey

func ParseBillingKey(billingKey string) (*types.BillingAuthKey, error)

func PersonalSign

func PersonalSign(message string, privateKey *ecdsa.PrivateKey) (string, common.Hash, error)

Returns a signature string

func RecoverAddress

func RecoverAddress(message string, signature string) (string, error)

func StartAndGracefulShutdown

func StartAndGracefulShutdown(run func(ctx context.Context, wg *sync.WaitGroup))

StartAndGracefulShutdown starts to run the specified task in a goroutine and wait for termination signal to shutdown gracefully.

Note, this method is not suitable for any non-blocking task that release resources in defer way.

Types

type AuthKeyManager

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

func NewAuthKeyManager

func NewAuthKeyManager() *AuthKeyManager

func (*AuthKeyManager) GetAddrByApiAuthKey

func (m *AuthKeyManager) GetAddrByApiAuthKey(contract string, apiKey *types.ApiAuthKey) (common.Address, error)

func (*AuthKeyManager) GetAddrByBillingAuthKey

func (m *AuthKeyManager) GetAddrByBillingAuthKey(billingKey *types.BillingAuthKey) (common.Address, error)

type ExpirableLruCache

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

ExpirableLruCache naive implementation of LRU cache with fixed TTL expiration duration. This cache uses a lazy eviction policy, by which the expired entry will be purged when it's being looked up.

func NewExpirableLruCache

func NewExpirableLruCache(size int, ttl time.Duration) (*ExpirableLruCache, error)

func (*ExpirableLruCache) Add

func (c *ExpirableLruCache) Add(key, value interface{}) bool

Add adds a value to the cache. Returns true if an eviction occurred.

func (*ExpirableLruCache) Get

func (c *ExpirableLruCache) Get(key interface{}) (interface{}, bool)

Get looks up a key's value from the cache. Will purge the entry and return nil if the entry expired.

type KMutex

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

KMutex key based multiple mutex, which is used to help improve locking performance by preventing a giant time-consuming locking.

func NewKMutex

func NewKMutex() *KMutex

func (*KMutex) Lock

func (km *KMutex) Lock(key MutexKey)

Lock locks by key

func (*KMutex) Unlock

func (km *KMutex) Unlock(key MutexKey)

Unlock unlocks by key

type MutexKey

type MutexKey string // mutex key used to identify different mutexes

Jump to

Keyboard shortcuts

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