executor

package
v1.67.4 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: BSD-3-Clause Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 存款
	ListZkDeposit = 1
	// 提款
	ListZkWithdraw = 2
	// 现货撮合
	ListSpotMatch = 1001
)
View Source
const (
	//KeyPrefixStateDB state db key必须前缀
	KeyPrefixStateDB = "mavl-zksync-"
	//KeyPrefixLocalDB local db的key必须前缀
	KeyPrefixLocalDB = "LODB-zksync"
)

Variables

This section is empty.

Functions

func AddNewLeaf

func AddNewLeaf(statedb dbm.KV, localdb dbm.KV, info *TreeUpdateInfo, ethAddress string, tokenId uint64, amount string, chain33Addr string) ([]*types.KeyValue, []*types.KeyValue, error)

func CalLeafProof

func CalLeafProof(statedb dbm.KV, leaf *zt.Leaf, info *TreeUpdateInfo) (*zt.MerkleTreeProof, error)

func CalTokenProof

func CalTokenProof(statedb dbm.KV, leaf *zt.Leaf, token *zt.TokenBalance, info *TreeUpdateInfo) (*zt.MerkleTreeProof, error)

func GetAccountIdPrimaryKey

func GetAccountIdPrimaryKey(accountId uint64) []byte

func GetAccountTreeKey

func GetAccountTreeKey() []byte

func GetAllRoots

func GetAllRoots(db dbm.KV, endIndex uint64, info *TreeUpdateInfo) ([]*zt.RootInfo, error)

func GetChain33EthPrimaryKey

func GetChain33EthPrimaryKey(chain33Addr string, ethAddr string) []byte

func GetHistoryAccountProof added in v1.67.4

func GetHistoryAccountProof(historyAccountInfo *zt.HistoryAccountProofInfo, targetAccountId, targetTokenId uint64) (*zt.ZkProofWitness, error)

func GetLeafByAccountId

func GetLeafByAccountId(db dbm.KV, accountId uint64, info *TreeUpdateInfo) (*zt.Leaf, error)

func GetLeafByChain33Address

func GetLeafByChain33Address(db dbm.KV, chain33Addr string) ([]*zt.Leaf, error)

func GetLeafByChain33AndEthAddress

func GetLeafByChain33AndEthAddress(db dbm.KV, chain33Addr, ethAddress string, info *TreeUpdateInfo) (*zt.Leaf, error)

func GetLeafByEthAddress

func GetLeafByEthAddress(db dbm.KV, ethAddress string) ([]*zt.Leaf, error)

func GetLeavesByStartAndEndIndex

func GetLeavesByStartAndEndIndex(db dbm.KV, startIndex uint64, endIndex uint64, info *TreeUpdateInfo) ([]*zt.Leaf, error)

func GetLocalChain33EthPrimaryKey

func GetLocalChain33EthPrimaryKey(chain33Addr string, ethAddr string) []byte

func GetNFTHashPrimaryKey added in v1.67.4

func GetNFTHashPrimaryKey(nftHash string) []byte

func GetNFTIdPrimaryKey added in v1.67.4

func GetNFTIdPrimaryKey(nftTokenId uint64) []byte

func GetName

func GetName() string

GetName get driver name

func GetRootByStartIndex

func GetRootByStartIndex(db dbm.KV, index uint64, info *TreeUpdateInfo) (*zt.RootInfo, error)

func GetRootIndexPrimaryKey

func GetRootIndexPrimaryKey(rootIndex uint64) []byte

func GetSpotMatch added in v1.67.4

func GetSpotMatch(receipt *types.Receipt) *types.Receipt

func GetTokenByAccountIdAndTokenId

func GetTokenByAccountIdAndTokenId(db dbm.KV, accountId uint64, tokenId uint64, info *TreeUpdateInfo) (*zt.TokenBalance, error)

func GetTokenByAccountIdAndTokenIdInDB

func GetTokenByAccountIdAndTokenIdInDB(db dbm.KV, accountId uint64, tokenId uint64) (*zt.TokenBalance, error)

func GetTokenPrimaryKey

func GetTokenPrimaryKey(accountId uint64, tokenId uint64) []byte

func GetTokenSymbolIdKey added in v1.67.4

func GetTokenSymbolIdKey(symbol string) []byte

GetTokenSymbolIdKey token symbol 对应id

func GetTokenSymbolKey added in v1.67.4

func GetTokenSymbolKey(tokenId string) []byte

GetTokenSymbolKey tokenId 对应symbol

func Init

func Init(name string, cfg *types.Chain33Config, sub []byte)

Init register dapp

func InitExecType

func InitExecType()

InitExecType Init Exec Type

func NewAccountTree

func NewAccountTree(localDb dbm.KVDB, ethFeeAddr, chain33FeeAddr string) ([]*types.KeyValue, *table.Table)

NewAccountTree 生成账户树,同时生成1号账户

func NewAccountTreeTable

func NewAccountTreeTable(kvdb db.KV) *table.Table

NewAccountTreeTable ...

func NewCommitProofTable

func NewCommitProofTable(kvdb db.KV) *table.Table

NewCommitProofTable ...

func NewHistoryAccountTreeTable

func NewHistoryAccountTreeTable(kvdb db.KV) *table.Table

NewHistoryAccountTreeTable ...

func NewTxInfo added in v1.67.4

func NewTxInfo(tx *types.Transaction, index int) *et.TxInfo

NewTxInfo ...

func NewZkSpotDex added in v1.67.4

func NewZkSpotDex(e *zksync, tx *types.Transaction, index int) *zkSpotDex

NewZkSpotDex ...

func NewZksync

func NewZksync() drivers.Driver

NewExchange ...

func NewZksyncInfoTable

func NewZksyncInfoTable(kvdb db.KV) *table.Table

NewZksyncInfoTable ...

func SpotCheckTx added in v1.67.4

func SpotCheckTx(cfg *types.Chain33Config, tx *types.Transaction, index int) error

CheckTx 实现自定义检验交易接口,供框架调用

func UpdateLeaf

func UpdateLeaf(statedb dbm.KV, localdb dbm.KV, info *TreeUpdateInfo, accountId uint64, tokenId uint64, amount string, option int32) ([]*types.KeyValue, []*types.KeyValue, error)

UpdateLeaf 更新叶子结点:1、如果在当前树的叶子中,直接更新 2、如果在归档的树中,需要找到归档的root,重新生成root

func UpdatePubKey

func UpdatePubKey(statedb dbm.KV, localdb dbm.KV, info *TreeUpdateInfo, pubKeyTy uint64, pubKey *zt.ZkPubKey, accountId uint64) ([]*types.KeyValue, []*types.KeyValue, error)

Types

type AccountTreeRow

type AccountTreeRow struct {
	*zt.Leaf
}

AccountTreeRow table meta 结构

func NewAccountTreeRow

func NewAccountTreeRow() *AccountTreeRow

func (*AccountTreeRow) CreateRow

func (r *AccountTreeRow) CreateRow() *table.Row

CreateRow 新建数据行

func (*AccountTreeRow) Get

func (r *AccountTreeRow) Get(key string) ([]byte, error)

Get 按照indexName 查询 indexValue

func (*AccountTreeRow) SetPayload

func (r *AccountTreeRow) SetPayload(data types.Message) error

SetPayload 设置数据

type Action

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

Action action struct

func NewAction

func NewAction(z *zksync, tx *types.Transaction, index int) *Action

NewAction ...

func (*Action) AssetMatch added in v1.67.4

func (a *Action) AssetMatch(payload *et.SpotAssetLimitOrder, list *types.Receipt) (*types.Receipt, error)

func (*Action) AssetTransfer added in v1.67.4

func (a *Action) AssetTransfer(transfer *types.AssetsTransfer, tx *types.Transaction, index int) (*types.Receipt, error)

func (*Action) AssetTransferToExec added in v1.67.4

func (a *Action) AssetTransferToExec(transfer *types.AssetsTransferToExec, tx *types.Transaction, index int) (*types.Receipt, error)

func (*Action) AssetWithdraw added in v1.67.4

func (a *Action) AssetWithdraw(withdraw *types.AssetsWithdraw, tx *types.Transaction, index int) (*types.Receipt, error)

func (*Action) ContractToTree

func (a *Action) ContractToTree(payload *zt.ZkContractToTree) (*types.Receipt, error)

ContractToTree 用户从L2转入到合约账户的资产转回到L2,amount为实际到账金额,fee额外从用户账户扣除 也就是用户实际资产total>=amount+fee, 如果小于则提取不成功 contract2tree的输入amount和fee精度统一是chain33合约精度,比如1e8,在二层再根据具体token精度做适配

func (*Action) ContractToTreeAcctIdProc added in v1.67.4

func (a *Action) ContractToTreeAcctIdProc(payload *zt.ZkContractToTree, token *zt.ZkTokenSymbol) (*types.Receipt, error)

func (*Action) Deposit

func (a *Action) Deposit(payload *zt.ZkDeposit) (*types.Receipt, error)

func (*Action) FullExit

func (a *Action) FullExit(payload *zt.ZkFullExit) (*types.Receipt, error)

FullExit 为了避免L2不打包某些用户的从L2向L1的提款交易,fullExit是从L1发起的,强制L2打包提款的交易,L1会在证明中校验,当前没支持此类交易

func (*Action) GetIndex

func (a *Action) GetIndex() int64

GetIndex get index

func (*Action) MakeFeeLog

func (a *Action) MakeFeeLog(amount string, info *TreeUpdateInfo, tokenId uint64, sign *zt.ZkSignature) (*types.Receipt, error)

func (*Action) MintNFT added in v1.67.4

func (a *Action) MintNFT(payload *zt.ZkMintNFT) (*types.Receipt, error)

func (*Action) ProxyExit added in v1.67.4

func (a *Action) ProxyExit(payload *zt.ZkProxyExit) (*types.Receipt, error)

ProxyExit 代理其他账户退出机制,在其他账户设置L2地址出错而不能设置公钥提款的场景,可由代理账户帮助退出回其eth地址

func (*Action) SetDefultPubKey added in v1.67.4

func (a *Action) SetDefultPubKey(payload *zt.ZkSetPubKey, info *TreeUpdateInfo, leaf *zt.Leaf, operationInfo *zt.OperationInfo) ([]*types.KeyValue, []*types.KeyValue, error)

func (*Action) SetProxyPubKey added in v1.67.4

func (a *Action) SetProxyPubKey(payload *zt.ZkSetPubKey, info *TreeUpdateInfo, leaf *zt.Leaf, operationInfo *zt.OperationInfo) ([]*types.KeyValue, []*types.KeyValue, error)

设置代理地址的公钥

func (*Action) SetPubKey

func (a *Action) SetPubKey(payload *zt.ZkSetPubKey) (*types.Receipt, error)

func (*Action) SpotMatch added in v1.67.4

func (a *Action) SpotMatch(payload *et.SpotLimitOrder, list *types.Receipt) (*types.Receipt, error)

处理撮合结果

如果是 按不同的交易类型来处理的话, 零知识证明部分的代码, 会随交易的多样化, 需要也写很多函数来支持.
所以结果最好以 结算的形式作为参数.
不同交易的结果, 转化为有限的几种结算
  主动结算: (用户地址发起的交易)    如: 撮合
  被动结算: (系统特定帐号发起的交易) 如: 永续中暴仓, 和资金费
结算的列表以结果的形式体现帐号的变化, 和具体的业务无关

func (*Action) SpotNftMatch added in v1.67.4

func (a *Action) SpotNftMatch(payload *et.SpotNftTakerOrder, list *types.Receipt) (*types.Receipt, error)

func (*Action) Swap added in v1.67.4

func (a *Action) Swap(payload1 *et.SpotLimitOrder, trade *et.ReceiptSpotTrade) (*types.Receipt, error)

A 和 B 交换 = transfer(A,B) + transfer(B,A) + swapfee() A 和 A 交换 = transfer(A,A) 0 + transfer(A,A) 0 + swapfee()

func (*Action) SwapWithNft added in v1.67.4

func (a *Action) SwapWithNft(payload1 *et.SpotNftTakerOrder, trade *et.ReceiptSpotTrade) (*types.Receipt, error)

A 和 B 交换 = transfer(A,B) + transfer(B,A) + swapfee() A 和 A 交换 = transfer(A,A) 0 + transfer(A,A) 0 + swapfee()

func (*Action) TransferToNew

func (a *Action) TransferToNew(payload *zt.ZkTransferToNew) (*types.Receipt, error)

func (*Action) TreeToContract

func (a *Action) TreeToContract(payload *zt.ZkTreeToContract) (*types.Receipt, error)

TreeToContract amount需要和签名的一致,签名需要电路验证,amount需要包括精度位

func (*Action) UpdateContractAccount

func (a *Action) UpdateContractAccount(amount, symbol string, option int32, execName string) (*types.Receipt, error)

func (*Action) UpdateExecAccount added in v1.67.4

func (a *Action) UpdateExecAccount(accountdb *account.DB, amount int64, option int32, execName string) (*types.Receipt, error)

func (*Action) ZkTransfer added in v1.67.4

func (a *Action) ZkTransfer(payload *zt.ZkTransfer) (*types.Receipt, error)

func (*Action) ZkWithdraw added in v1.67.4

func (a *Action) ZkWithdraw(payload *zt.ZkWithdraw) (*types.Receipt, error)

type CommitProofRow

type CommitProofRow struct {
	*zt.ZkCommitProof
}

CommitProofRow table meta 结构

func NewCommitProofRow

func NewCommitProofRow() *CommitProofRow

func (*CommitProofRow) CreateRow

func (r *CommitProofRow) CreateRow() *table.Row

CreateRow 新建数据行

func (*CommitProofRow) Get

func (r *CommitProofRow) Get(key string) ([]byte, error)

Get 按照indexName 查询 indexValue

func (*CommitProofRow) SetPayload

func (r *CommitProofRow) SetPayload(data types.Message) error

SetPayload 设置数据

type HistoryAccountTreeRow

type HistoryAccountTreeRow struct {
	*zt.HistoryLeaf
}

HistoryAccountTreeRow table meta 结构

func NewHistoryAccountTreeRow

func NewHistoryAccountTreeRow() *HistoryAccountTreeRow

func (*HistoryAccountTreeRow) CreateRow

func (r *HistoryAccountTreeRow) CreateRow() *table.Row

CreateRow 新建数据行

func (*HistoryAccountTreeRow) Get

func (r *HistoryAccountTreeRow) Get(key string) ([]byte, error)

Get 按照indexName 查询 indexValue

func (*HistoryAccountTreeRow) SetPayload

func (r *HistoryAccountTreeRow) SetPayload(data types.Message) error

SetPayload 设置数据

type TreeUpdateInfo

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

TreeUpdateInfo 更新信息,用于查询

type ZksyncInfoRow

type ZksyncInfoRow struct {
	*zt.OperationInfo
}

AccountTreeRow table meta 结构

func NewZksyncInfoRow

func NewZksyncInfoRow() *ZksyncInfoRow

func (*ZksyncInfoRow) CreateRow

func (r *ZksyncInfoRow) CreateRow() *table.Row

CreateRow 新建数据行

func (*ZksyncInfoRow) Get

func (r *ZksyncInfoRow) Get(key string) ([]byte, error)

Get 按照indexName 查询 indexValue

func (*ZksyncInfoRow) SetPayload

func (r *ZksyncInfoRow) SetPayload(data types.Message) error

SetPayload 设置数据

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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