xutil

package
v0.0.0-...-1df5c7e Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: MIT Imports: 45 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToFloat64

func BytesToFloat64(bytes []byte) float64

func BytesToInt64

func BytesToInt64(data []byte) int64

func ChainIdGetTokenType

func ChainIdGetTokenType(chainId string) string

func ChainIdToChainName

func ChainIdToChainName(chainId string) string

func ChainNameToChainID

func ChainNameToChainID(chainName string) string

func CombineShares

func CombineShares(shares [][]byte) ([]byte, error)

CombineShares shamir合并私钥

func CompleteNPeriodsBetween

func CompleteNPeriodsBetween(start time.Time, end time.Time, N float64) float64

CompleteNPeriodsBetween 计算两个时间戳相差的N倍数

func ETHToTronAddress

func ETHToTronAddress(addr string) string

func EcdsaPrivateKeyGetSolPrivateKey

func EcdsaPrivateKeyGetSolPrivateKey(privateKeyECDSA *ecdsa.PrivateKey) (key ed25519.PrivateKey, address string, err error)

func Erc20SingAndSend

func Erc20SingAndSend(client *ethclient.Client, privateKey *ecdsa.PrivateKey, contract, toAddress common.Address, amount *big.Int) (string, error)

func EthAddrToTronAddr

func EthAddrToTronAddr(ethAddr string) (tronAddr string)

func EthBalanceAtAndOf

func EthBalanceAtAndOf(address, contract, tokenDecimals string, ethClient *ethclient.Client) (bAt, bOf decimal.Decimal, err error)

func EthUrlConnTest

func EthUrlConnTest(client *rpc.Client) (time.Duration, error)

func EthZeroAddress

func EthZeroAddress() string

func ExternalIP

func ExternalIP() net.IP

func FindDifference

func FindDifference(slice1 []string, slice2 []string) []string

切片差集

func Float64ToBytes

func Float64ToBytes(f float64) []byte

func GenMnemonic

func GenMnemonic(lang int) (string, error)

GenMnemonic 生成12、24个的助记词;默认生成12个

func GenerateRandomDigits

func GenerateRandomDigits(length int) string

func GenerateRandomKey

func GenerateRandomKey(seed int64, length int) string

GenerateRandomKey 生成随机字符串

func GenerateRandomString

func GenerateRandomString(length int) string

GenerateRandomString 生成指定长度的字符串

func GenerateSeed

func GenerateSeed(dividend int64) int64

GenerateSeed 生成种子

func GetAccount

func GetAccount(ctx context.Context) (account string)

func GetIpFromAddr

func GetIpFromAddr(addr net.Addr) net.IP

func GetKaiId

func GetKaiId(ctx context.Context) (kaiId int64)

GetKaiId 获取kai-id

func GetNationByIp

func GetNationByIp(ip string) (record *geoip2.City, err error)

GetNationByIp 根据ip获取国家信息

func GetRandStr

func GetRandStr(strSize int) string

GetRandStr 获取A-Z-16位随机字符串

func GetRandomID

func GetRandomID() uint32

func GetToken

func GetToken(secretKey, account string, iat, seconds, uid, kaiId int64) (string, error)

func GetUid

func GetUid(ctx context.Context) int64

func GetUserIp

func GetUserIp(r *http.Request) string

GetUserIp 获取客户端IP

func HexToDec

func HexToDec(hexStr string) uint64

func InArray

func InArray[T comparable](element T, array []T) bool

func Int64ToBytes

func Int64ToBytes(n int64) []byte

func Int64ToTime

func Int64ToTime(t int64) (timeStr string)

Int64ToTime int64转时间格式

func IsEthAddress

func IsEthAddress(address string) bool

func IsHttpURL

func IsHttpURL(url string) bool

func IsSolAddress

func IsSolAddress(address string) bool

IsSolAddress 判断是否为合法的 SOL 地址

func IsTronAddress

func IsTronAddress(addr string) bool

func IsTronNativeAsset

func IsTronNativeAsset(asset string) bool

func IsValidAddress

func IsValidAddress(iaddress interface{}) bool

IsValidAddress validate hex address

func IsValidMnemonic

func IsValidMnemonic(mnemonic string) bool

IsValidMnemonic 判断助记词是否有效

func IsZeroAddress

func IsZeroAddress(iaddress interface{}) bool

IsZeroAddress validate if it's a 0 address

func MnemonicGetEthAddress

func MnemonicGetEthAddress(mnemonic string, path string) (address string, err error)

func MnemonicGetSolAddress

func MnemonicGetSolAddress(mnemonic string, path string) (address string, err error)

func MnemonicGetTronAddress

func MnemonicGetTronAddress(mnemonic string, path string) (address string, err error)

func MnemonicToPrivateKey

func MnemonicToPrivateKey(mnemonic, salt, pathStr string) (*ecdsa.PrivateKey, error)

MnemonicToPrivateKey 助记词转私钥

func PrivateECDSAToSolEd25519

func PrivateECDSAToSolEd25519(privateKeyECDSA *ecdsa.PrivateKey) (edPrivate ed25519.PrivateKey, err error)

func PrivateKeyGetEthAddress

func PrivateKeyGetEthAddress(privateKeyECDSA *ecdsa.PrivateKey) (address string, err error)

func PrivateKeyGetSolAddress

func PrivateKeyGetSolAddress(privateKeyECDSA *ecdsa.PrivateKey) (address string, err error)

func PrivateKeyGetTronAddress

func PrivateKeyGetTronAddress(privateKeyECDSA *ecdsa.PrivateKey) (address string, err error)

func PublicKeyToEthAddress

func PublicKeyToEthAddress(publicKey string) (string, error)

func ReverseRandomKey

func ReverseRandomKey(partialStr string) int64

func SolBalanceAtAndOf

func SolBalanceAtAndOf(address, contract, tokenDecimals string, solC *SolClient.Client) (bAt, bOf decimal.Decimal, err error)

func SolIsTransactionSuccessful

func SolIsTransactionSuccessful(txHash string, solClient *client.Client) (bool, error)

func SplitNumber

func SplitNumber(num int64) (string, string, error)

func SplitToShares

func SplitToShares(privateKey string, minimumShares int, totalShares int) ([][]byte, error)

func StringToInt64

func StringToInt64(str string) (int64, error)

func StringToInt64Must

func StringToInt64Must(str string) int64

func StructToMap

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

func ToBool

func ToBool(val interface{}) bool

func ToDecimal

func ToDecimal(ivalue interface{}, decimals int) decimal.Decimal

ToDecimal wei to decimals

func ToInt64

func ToInt64(value interface{}) (int64, error)

func ToInt64Must

func ToInt64Must(value interface{}) int64

func ToLocalDateByMilliSecond

func ToLocalDateByMilliSecond(milliSecond int64, local string) string

func ToLocalDateBySecond

func ToLocalDateBySecond(second int64, local string) string

func ToString

func ToString(val interface{}) string

func ToWei

func ToWei(value interface{}, decimals int) *big.Int

ToWei decimals to wei

func TronAddrToEthAddr

func TronAddrToEthAddr(tronAddr string) (ethAddr string)

func TronNativeAssetDecimals

func TronNativeAssetDecimals() uint8

func TronToEthAddress

func TronToEthAddress(addr string) (common.Address, error)

func TronZeroAddress

func TronZeroAddress(asset string) string

func TrxBalanceAtAndOf

func TrxBalanceAtAndOf(address, contract, tokenDecimals string, trxClient *tron.TronClient) (bAt, bOf decimal.Decimal, err error)

func TrxIsTransactionSuccessful

func TrxIsTransactionSuccessful(client *tron.TronClient, txHash common.Hash) (bool, uint64)

func VerifyToken

func VerifyToken(token, secret string) (*jwt.Token, error)

Types

type Address

type Address struct {
	City        string `json:"city"`
	Country     string `json:"country"`
	CountryCode string `json:"country_code"`
	State       string `json:"state"`
}

type Erc20Transfer

type Erc20Transfer struct {
	Client     *ethclient.Client
	PrivateKey *ecdsa.PrivateKey
	Contract   *common.Address
}

func NewErc20Transfer

func NewErc20Transfer(client *ethclient.Client, privateKey *ecdsa.PrivateKey, contract common.Address) *Erc20Transfer

func (*Erc20Transfer) Close

func (e *Erc20Transfer) Close()

func (*Erc20Transfer) SenToErc20

func (e *Erc20Transfer) SenToErc20(toAddress common.Address, amount *big.Int) (string, error)

type JwtParam

type JwtParam struct {
	Token  string `json:"token"`
	Secret string `json:"secret"`
}

func NewJwtService

func NewJwtService(token, secret string) *JwtParam

func (*JwtParam) GetExp

func (j *JwtParam) GetExp() (exp int64, err error)

GetExp 获取过期时间

func (*JwtParam) GetUid

func (j *JwtParam) GetUid() (uid int64, err error)

GetUid 获取uid

func (*JwtParam) ParseToken

func (j *JwtParam) ParseToken() (auth *jwt.Token, err error)

ParseToken 解析token

type Resp

type Resp struct {
	Address Address `json:"address"`
}

func GetAddress

func GetAddress(latitude, longitude string) (data Resp, err error)

GetAddress 根据经纬度获取国家信息

Jump to

Keyboard shortcuts

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