utils

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BatchCreateUserOpsCounts = 864
	AccountTreeDepth         = 28
	AssetCounts              = 350
	RedisLockKey             = "prover_mutex_key"
	R1csBatchSize            = 1000000
)
View Source
const (
	LockExpiryTime = 10 // seconds
	RetryInterval  = 500 * time.Millisecond
	MaxRetryTimes  = 3
)

Variables

View Source
var (
	ZeroBigInt                    = new(big.Int).SetInt64(0)
	Uint64MaxValueBigInt, _       = new(big.Int).SetString("18446744073709551616", 10)
	Uint64MaxValueBigIntSquare, _ = new(big.Int).SetString("340282366920938463463374607431768211456", 10)
	Uint64MaxValueFr              = new(fr.Element).SetBigInt(Uint64MaxValueBigInt)
	Uint64MaxValueFrSquare        = new(fr.Element).SetBigInt(Uint64MaxValueBigIntSquare)
	AssetTypeForTwoDigits         = map[string]bool{
		"BTTC":  true,
		"SHIB":  true,
		"LUNC":  true,
		"XEC":   true,
		"WIN":   true,
		"BIDR":  true,
		"SPELL": true,
		"HOT":   true,
		"DOGE":  true,
		"PEPE":  true,
	}
)
View Source
var (
	DbErrSqlOperation  = errors.New("unknown sql operation error")
	DbErrNotFound      = errors.New("sql: no rows in result set")
	GetRedisLockFailed = errors.New("get lock failed")
)
View Source
var (
	NilAccountHash []byte
)

Functions

func AccountInfoToHash

func AccountInfoToHash(account *AccountInfo, hasher *hash.Hash) []byte

func ComputeCexAssetsCommitment

func ComputeCexAssetsCommitment(cexAssetsInfo []CexAssetInfo) []byte

func ComputeUserAssetsCommitment

func ComputeUserAssetsCommitment(hasher *hash.Hash, assets []AccountAsset) []byte

func ConvertAssetInfoToBytes

func ConvertAssetInfoToBytes(value any) []byte

func ConvertFloatStrToUint64

func ConvertFloatStrToUint64(f string, multiplier int64) (uint64, error)

func GetMysqlSource added in v1.0.2

func GetMysqlSource(source string, secretId string) (string, error)

user name can't include ":"

func GetRedisLockByKey

func GetRedisLockByKey(conn *redis.Redis, keyLock string) (redisLock *redis.RedisLock)

func GetSecretFromAws

func GetSecretFromAws(secretId string) (string, error)

func NewAccountTree

func NewAccountTree(driver string, addr string) (accountTree bsmt.SparseMerkleTree, err error)

func ParseUserDataSet

func ParseUserDataSet(dirname string) ([]AccountInfo, []CexAssetInfo, error)

func ReadUserDataFromCsvFile

func ReadUserDataFromCsvFile(name string) ([]AccountInfo, []CexAssetInfo, error)

func SafeAdd

func SafeAdd(a uint64, b uint64) (c uint64)

func SelectAssetValue

func SelectAssetValue(expectAssetIndex int, flag int, currentAssetPosition int, assets []AccountAsset) (*big.Int, bool)

func TryAcquireLock

func TryAcquireLock(redisLock *redis.RedisLock) (err error)

func VerifyMerkleProof

func VerifyMerkleProof(root []byte, accountIndex uint32, proof [][]byte, node []byte) bool

Types

type AccountAsset

type AccountAsset struct {
	Index  uint16
	Equity uint64
	Debt   uint64
}

type AccountInfo

type AccountInfo struct {
	AccountIndex uint32
	AccountId    []byte
	TotalEquity  *big.Int
	TotalDebt    *big.Int
	Assets       []AccountAsset
}

type BatchCreateUserWitness

type BatchCreateUserWitness struct {
	BatchCommitment           []byte
	BeforeAccountTreeRoot     []byte
	AfterAccountTreeRoot      []byte
	BeforeCEXAssetsCommitment []byte
	AfterCEXAssetsCommitment  []byte

	BeforeCexAssets []CexAssetInfo
	CreateUserOps   []CreateUserOperation
}

func DecodeBatchWitness

func DecodeBatchWitness(data string) *BatchCreateUserWitness

type CexAssetInfo

type CexAssetInfo struct {
	TotalEquity uint64
	TotalDebt   uint64
	BasePrice   uint64
	Symbol      string
	Index       uint32
}

func RecoverAfterCexAssets

func RecoverAfterCexAssets(witness *BatchCreateUserWitness) []CexAssetInfo

type CreateUserOperation

type CreateUserOperation struct {
	BeforeAccountTreeRoot []byte
	AfterAccountTreeRoot  []byte
	Assets                []AccountAsset
	AccountIndex          uint32
	AccountIdHash         []byte
	AccountProof          [AccountTreeDepth][]byte
}

Jump to

Keyboard shortcuts

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