types

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FungibleAssetType        = 1
	NftAssetType             = 2
	CollectionNonceAssetType = 3

	BuyOfferType  = 0
	SellOfferType = 1
)
View Source
const (
	EmptyNonce               = 0
	EmptyCollectionNonce     = 0
	EmptyAccountAssetInfo    = "{}"
	EmptyAccountIndex        = int64(0)
	EmptyNftContentHash      = "0"
	EmptyAccountNameHash     = "0"
	EmptyTxHash              = "0"
	EmptyL1TokenId           = "0"
	EmptyL1Address           = "0"
	EmptyCreatorTreasuryRate = 0

	NilAccountName     = ""
	NilNftIndex        = int64(-1)
	NilAccountIndex    = int64(-1)
	NilBlockHeight     = -1
	NilAssetId         = -1
	NilAccountOrder    = -1
	NilNonce           = -1
	NilCollectionNonce = -1
	NilExpiredAt       = math.MaxInt64
	NilAssetAmount     = "0"

	GasAccount  = int64(1)
	BNBAssetId  = 0
	BUSDAssetId = 1
)
View Source
const (
	TreasuryAccountIndex    = "TreasuryAccountIndex"
	GasAccountIndex         = "GasAccountIndex"
	BscTestNetworkRpc       = "BscTestNetworkRpc"
	LocalTestNetworkRpc     = "LocalTestNetworkRpc"
	SysGasFee               = "SysGasFee"
	ZkBNBContract           = "ZkBNBContract"
	GovernanceContract      = "GovernanceContract"
	AssetGovernanceContract = "AssetGovernanceContract"
	Validators              = "Validators"

	Governor       = "Governor"
	ZnsPriceOracle = "ZnsPriceOracle"

	AccountNameSuffix = ".legend"
)
View Source
const (
	TxTypeEmpty = iota
	TxTypeRegisterZns
	TxTypeDeposit
	TxTypeDepositNft
	TxTypeTransfer
	TxTypeWithdraw
	TxTypeCreateCollection
	TxTypeMintNft
	TxTypeTransferNft
	TxTypeAtomicMatch
	TxTypeCancelOffer
	TxTypeWithdrawNft
	TxTypeFullExit
	TxTypeFullExitNft
	TxTypeOffer
)
View Source
const (
	TxTypeBytesSize          = 1
	AddressBytesSize         = 20
	AccountIndexBytesSize    = 4
	AccountNameBytesSize     = 32
	AccountNameHashBytesSize = 32
	PubkeyBytesSize          = 32
	AssetIdBytesSize         = 2
	StateAmountBytesSize     = 16
	NftIndexBytesSize        = 5
	NftTokenIdBytesSize      = 32
	NftContentHashBytesSize  = 32
	FeeRateBytesSize         = 2
	CollectionIdBytesSize    = 2

	RegisterZnsPubDataSize = TxTypeBytesSize + AccountIndexBytesSize + AccountNameBytesSize +
		AccountNameHashBytesSize + PubkeyBytesSize + PubkeyBytesSize
	DepositPubDataSize = TxTypeBytesSize + AccountIndexBytesSize +
		AccountNameHashBytesSize + AssetIdBytesSize + StateAmountBytesSize
	DepositNftPubDataSize = TxTypeBytesSize + AccountIndexBytesSize + NftIndexBytesSize + AddressBytesSize +
		AccountIndexBytesSize + FeeRateBytesSize + NftContentHashBytesSize + NftTokenIdBytesSize +
		AccountNameHashBytesSize + CollectionIdBytesSize
	FullExitPubDataSize = TxTypeBytesSize + AccountIndexBytesSize +
		AccountNameHashBytesSize + AssetIdBytesSize + StateAmountBytesSize
	FullExitNftPubDataSize = TxTypeBytesSize + AccountIndexBytesSize + AccountIndexBytesSize + FeeRateBytesSize +
		NftIndexBytesSize + CollectionIdBytesSize + AddressBytesSize +
		AccountNameHashBytesSize + AccountNameHashBytesSize +
		NftContentHashBytesSize + NftTokenIdBytesSize
)
View Source
const (
	TypeAccountIndex = iota
	TypeAssetId
	TypeAccountName
	TypeAccountNameOmitSpace
	TypeAccountPk
	TypeLimit
	TypeOffset
	TypeHash
	TypeBlockHeight
	TypeTxType
	TypeChainId
	TypeAssetAmount
	TypeBoolean
	TypeGasFee
)
View Source
const (
	AddressSize       = 20
	EmptyStringKeccak = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
)

Variables

View Source
var (
	DbErrNotFound                    = sqlx.ErrNotFound
	DbErrSqlOperation                = errors.New("unknown sql operation error")
	DbErrFailToCreateBlock           = errors.New("fail to create block")
	DbErrFailToUpdateBlock           = errors.New("fail to update block")
	DbErrFailToUpdateTx              = errors.New("fail to update tx")
	DbErrFailToCreateCompressedBlock = errors.New("fail to create compressed block")
	DbErrFailToCreateProof           = errors.New("fail to create proof")
	DbErrFailToUpdateProof           = errors.New("fail to update proof")
	DbErrFailToCreateSysConfig       = errors.New("fail to create system config")
	DbErrFailToUpdateSysConfig       = errors.New("fail to update system config")
	DbErrFailToCreateAsset           = errors.New("fail to create asset")
	DbErrFailToUpdateAsset           = errors.New("fail to update asset")
	DbErrFailToCreateAccount         = errors.New("fail to create account")
	DbErrFailToUpdateAccount         = errors.New("fail to update account")
	DbErrFailToCreateAccountHistory  = errors.New("fail to create account history")
	DbErrFailToCreateL1RollupTx      = errors.New("fail to create l1 rollup tx")
	DbErrFailToDeleteL1RollupTx      = errors.New("fail to delete l1 rollup tx")
	DbErrFailToL1SyncedBlock         = errors.New("fail to create l1 synced block")
	DbErrFailToCreatePoolTx          = errors.New("fail to create pool tx")
	DbErrFailToUpdatePoolTx          = errors.New("fail to update pool tx")
	DbErrFailToDeletePoolTx          = errors.New("fail to delete pool tx")
	DbErrFailToCreateNft             = errors.New("fail to create nft")
	DbErrFailToUpdateNft             = errors.New("fail to update nft")
	DbErrFailToCreateNftHistory      = errors.New("fail to create nft history")
	DbErrFailToCreatePriorityRequest = errors.New("fail to create priority request")
	DbErrFailToUpdatePriorityRequest = errors.New("fail to update priority request")

	JsonErrUnmarshal = errors.New("json.Unmarshal err")
	JsonErrMarshal   = errors.New("json.Marshal err")

	HttpErrFailToRequest = errors.New("http.NewRequest err")
	HttpErrClientDo      = errors.New("http.Client.Do err")

	IoErrFailToRead = errors.New("ioutil.ReadAll err")

	CmcNotListedErr = errors.New("cmc not listed")

	AppErrInvalidParam   = New(20001, "invalid param: ")
	AppErrInvalidTxField = New(20002, "invalid tx field: ")

	AppErrInvalidExpireTime   = New(21000, "invalid expired time")
	AppErrInvalidGasFeeAmount = New(21001, "invalid gas fee amount")
	AppErrBalanceNotEnough    = New(21002, "balance is not enough")
	AppErrInvalidTreasuryRate = New(21003, "invalid treasury rate")
	AppErrInvalidCallDataHash = New(21004, "invalid calldata hash")
	AppErrInvalidToAddress    = New(21005, "invalid toAddress")

	// Account
	AppErrAccountNotFound              = New(21100, "account not found")
	AppErrAccountNonceNotFound         = New(21101, "account nonce not found")
	AppErrInvalidAccountIndex          = New(21102, "invalid account index")
	AppErrInvalidNonce                 = New(21103, "invalid nonce")
	AppErrInvalidGasFeeAccount         = New(21104, "invalid gas fee account")
	AppErrInvalidToAccountNameHash     = New(21105, "invalid ToAccountNameHash")
	AppErrAccountNameAlreadyRegistered = New(21106, "invalid account name, already registered")

	// Asset
	AppErrAssetNotFound      = New(21200, "asset not found")
	AppErrInvalidAssetId     = New(21201, "invalid asset id")
	AppErrInvalidGasFeeAsset = New(21202, "invalid gas fee asset")
	AppErrInvalidAssetAmount = New(21203, "invalid asset amount")

	// Block
	AppErrBlockNotFound      = New(21300, "block not found")
	AppErrInvalidBlockHeight = New(21301, "invalid block height")

	// Tx
	AppErrPoolTxNotFound = New(21400, "pool tx not found")
	AppErrInvalidTxInfo  = New(21401, "invalid tx info")

	// Offer
	AppErrInvalidOfferType           = New(21500, "invalid offer type")
	AppErrInvalidOfferState          = New(21501, "invalid offer state, already canceled or finalized")
	AppErrInvalidOfferId             = New(21502, "invalid offer id")
	AppErrInvalidListTime            = New(21503, "invalid listed time")
	AppErrInvalidBuyOffer            = New(21504, "invalid buy offer")
	AppErrInvalidSellOffer           = New(21505, "invalid sell offer")
	AppErrSameBuyerAndSeller         = New(21506, "same buyer and seller")
	AppErrBuyOfferMismatchSellOffer  = New(21506, "buy offer mismatches sell offer")
	AppErrInvalidBuyOfferExpireTime  = New(21507, "invalid BuyOffer.ExpiredAt")
	AppErrInvalidSellOfferExpireTime = New(21508, "invalid SellOffer.ExpiredAt")
	AppErrSellerBalanceNotEnough     = New(21508, "seller balance is not enough")
	AppErrBuyerBalanceNotEnough      = New(21509, "buyer balance is not enough")
	AppErrSellerNotOwner             = New(21510, "seller is not owner")
	AppErrInvalidSellOfferState      = New(21511, "invalid sell offer state, already canceled or finalized")
	AppErrInvalidBuyOfferState       = New(21512, "invalid buy offer state, already canceled or finalized")
	AppErrInvalidAssetOfOffer        = New(21513, "invalid asset of offer")

	// Nft
	AppErrNftAlreadyExist       = New(21600, "invalid nft index, already exist")
	AppErrInvalidNftContenthash = New(21601, "invalid nft content hash")
	AppErrNotNftOwner           = New(21602, "account is not owner of the nft")
	AppErrInvalidNftIndex       = New(21603, "invalid nft index")
	AppErrNftNotFound           = New(21604, "nft not found")

	// Collection
	AppErrInvalidCollectionId   = New(21700, "invalid collection id")
	AppErrInvalidCollectionName = New(21701, "invalid collection name")
	AppErrInvalidIntroduction   = New(21702, "invalid introduction")

	AppErrInvalidGasAsset = New(25003, "invalid gas asset")
	AppErrInvalidTxType   = New(25004, "invalid tx type")
	AppErrTooManyTxs      = New(25005, "too many pending txs")
	AppErrNotFound        = New(29404, "not found")
	AppErrInternal        = New(29500, "internal server error")
)
View Source
var (
	EmptyOfferCanceledOrFinalized = big.NewInt(0)
	GasAssets                     = [2]int64{0, 1}
)
View Source
var (
	ZeroBigInt          = big.NewInt(0)
	EmptyAccountAssetId = int64(0)
)

Functions

func IsL2Tx

func IsL2Tx(txType int64) bool

func IsPriorityOperationTx added in v0.0.4

func IsPriorityOperationTx(txType int64) bool

func ParseAtomicMatchTxInfo

func ParseAtomicMatchTxInfo(txInfoStr string) (txInfo *txtypes.AtomicMatchTxInfo, err error)

func ParseCancelOfferTxInfo

func ParseCancelOfferTxInfo(txInfoStr string) (txInfo *txtypes.CancelOfferTxInfo, err error)

func ParseCreateCollectionTxInfo

func ParseCreateCollectionTxInfo(txInfoStr string) (txInfo *txtypes.CreateCollectionTxInfo, err error)

func ParseDepositNftTxInfo

func ParseDepositNftTxInfo(txInfoStr string) (txInfo *txtypes.DepositNftTxInfo, err error)

func ParseDepositTxInfo

func ParseDepositTxInfo(txInfoStr string) (txInfo *txtypes.DepositTxInfo, err error)

func ParseFullExitNftTxInfo

func ParseFullExitNftTxInfo(txInfoStr string) (txInfo *txtypes.FullExitNftTxInfo, err error)

func ParseFullExitTxInfo

func ParseFullExitTxInfo(txInfoStr string) (txInfo *txtypes.FullExitTxInfo, err error)

func ParseMintNftTxInfo

func ParseMintNftTxInfo(txInfoStr string) (txInfo *txtypes.MintNftTxInfo, err error)

func ParseRegisterZnsTxInfo

func ParseRegisterZnsTxInfo(txInfoStr string) (txInfo *txtypes.RegisterZnsTxInfo, err error)

func ParseTransferNftTxInfo

func ParseTransferNftTxInfo(txInfoStr string) (txInfo *txtypes.TransferNftTxInfo, err error)

func ParseTransferTxInfo

func ParseTransferTxInfo(txInfoStr string) (txInfo *txtypes.TransferTxInfo, err error)

func ParseWithdrawNftTxInfo

func ParseWithdrawNftTxInfo(txInfoStr string) (txInfo *txtypes.WithdrawNftTxInfo, err error)

func ParseWithdrawTxInfo

func ParseWithdrawTxInfo(txInfoStr string) (txInfo *txtypes.WithdrawTxInfo, err error)

Types

type AccountAsset

type AccountAsset struct {
	AssetId                  int64
	Balance                  *big.Int
	OfferCanceledOrFinalized *big.Int
}

func ConstructAccountAsset

func ConstructAccountAsset(assetId int64, balance *big.Int, offerCanceledOrFinalized *big.Int) *AccountAsset

func ParseAccountAsset

func ParseAccountAsset(balance string) (asset *AccountAsset, err error)

func (*AccountAsset) DeepCopy

func (asset *AccountAsset) DeepCopy() *AccountAsset

func (*AccountAsset) String

func (asset *AccountAsset) String() (info string)

type AccountInfo

type AccountInfo struct {
	AccountId       uint
	AccountIndex    int64
	AccountName     string
	PublicKey       string
	AccountNameHash string
	L1Address       string
	Nonce           int64
	CollectionNonce int64
	AssetInfo       map[int64]*AccountAsset // key: index, value: balance
	AssetRoot       string
	Status          int
}

func (*AccountInfo) DeepCopy

func (ai *AccountInfo) DeepCopy() *AccountInfo

type Error

type Error interface {
	Error() string
	Code() int32
	RefineError(err ...interface{}) Error
}

func New

func New(code int32, msg string) Error

type NftInfo

type NftInfo struct {
	NftIndex            int64
	CreatorAccountIndex int64
	OwnerAccountIndex   int64
	NftContentHash      string
	NftL1TokenId        string
	NftL1Address        string
	CreatorTreasuryRate int64
	CollectionId        int64
}

func ConstructNftInfo

func ConstructNftInfo(
	NftIndex int64,
	CreatorAccountIndex int64,
	OwnerAccountIndex int64,
	NftContentHash string,
	NftL1TokenId string,
	NftL1Address string,
	creatorTreasuryRate int64,
	collectionId int64,
) (nftInfo *NftInfo)

func EmptyNftInfo

func EmptyNftInfo(nftIndex int64) (info *NftInfo)

func ParseNftInfo

func ParseNftInfo(infoStr string) (info *NftInfo, err error)

func (*NftInfo) IsEmptyNft

func (info *NftInfo) IsEmptyNft() bool

func (*NftInfo) String

func (info *NftInfo) String() string

Jump to

Keyboard shortcuts

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