Documentation ¶
Index ¶
- Constants
- func AddNewLeaf(statedb dbm.KV, localdb dbm.KV, info *TreeUpdateInfo, ethAddress string, ...) ([]*types.KeyValue, []*types.KeyValue, error)
- func CalLeafProof(statedb dbm.KV, leaf *zt.Leaf, info *TreeUpdateInfo) (*zt.MerkleTreeProof, error)
- func CalTokenProof(statedb dbm.KV, leaf *zt.Leaf, token *zt.TokenBalance, info *TreeUpdateInfo) (*zt.MerkleTreeProof, error)
- func GetAccountIdPrimaryKey(accountId uint64) []byte
- func GetAccountTreeKey() []byte
- func GetAllRoots(db dbm.KV, endIndex uint64, info *TreeUpdateInfo) ([]*zt.RootInfo, error)
- func GetChain33EthPrimaryKey(chain33Addr string, ethAddr string) []byte
- func GetHistoryAccountProof(historyAccountInfo *zt.HistoryAccountProofInfo, ...) (*zt.ZkProofWitness, error)
- func GetLeafByAccountId(db dbm.KV, accountId uint64, info *TreeUpdateInfo) (*zt.Leaf, error)
- func GetLeafByChain33Address(db dbm.KV, chain33Addr string) ([]*zt.Leaf, error)
- func GetLeafByChain33AndEthAddress(db dbm.KV, chain33Addr, ethAddress string, info *TreeUpdateInfo) (*zt.Leaf, error)
- func GetLeafByEthAddress(db dbm.KV, ethAddress string) ([]*zt.Leaf, error)
- func GetLeavesByStartAndEndIndex(db dbm.KV, startIndex uint64, endIndex uint64, info *TreeUpdateInfo) ([]*zt.Leaf, error)
- func GetLocalChain33EthPrimaryKey(chain33Addr string, ethAddr string) []byte
- func GetNFTHashPrimaryKey(nftHash string) []byte
- func GetNFTIdPrimaryKey(nftTokenId uint64) []byte
- func GetName() string
- func GetRootByStartIndex(db dbm.KV, index uint64, info *TreeUpdateInfo) (*zt.RootInfo, error)
- func GetRootIndexPrimaryKey(rootIndex uint64) []byte
- func GetSpotMatch(receipt *types.Receipt) *types.Receipt
- func GetTokenByAccountIdAndTokenId(db dbm.KV, accountId uint64, tokenId uint64, info *TreeUpdateInfo) (*zt.TokenBalance, error)
- func GetTokenByAccountIdAndTokenIdInDB(db dbm.KV, accountId uint64, tokenId uint64) (*zt.TokenBalance, error)
- func GetTokenPrimaryKey(accountId uint64, tokenId uint64) []byte
- func GetTokenSymbolIdKey(symbol string) []byte
- func GetTokenSymbolKey(tokenId string) []byte
- func Init(name string, cfg *types.Chain33Config, sub []byte)
- func InitExecType()
- func NewAccountTree(localDb dbm.KVDB, ethFeeAddr, chain33FeeAddr string) ([]*types.KeyValue, *table.Table)
- func NewAccountTreeTable(kvdb db.KV) *table.Table
- func NewCommitProofTable(kvdb db.KV) *table.Table
- func NewHistoryAccountTreeTable(kvdb db.KV) *table.Table
- func NewTxInfo(tx *types.Transaction, index int) *et.TxInfo
- func NewZkSpotDex(e *zksync, tx *types.Transaction, index int) *zkSpotDex
- func NewZksync() drivers.Driver
- func NewZksyncInfoTable(kvdb db.KV) *table.Table
- func SpotCheckTx(cfg *types.Chain33Config, tx *types.Transaction, index int) error
- func UpdateLeaf(statedb dbm.KV, localdb dbm.KV, info *TreeUpdateInfo, accountId uint64, ...) ([]*types.KeyValue, []*types.KeyValue, error)
- func UpdatePubKey(statedb dbm.KV, localdb dbm.KV, info *TreeUpdateInfo, pubKeyTy uint64, ...) ([]*types.KeyValue, []*types.KeyValue, error)
- type AccountTreeRow
- type Action
- func (a *Action) AssetMatch(payload *et.SpotAssetLimitOrder, list *types.Receipt) (*types.Receipt, error)
- func (a *Action) AssetTransfer(transfer *types.AssetsTransfer, tx *types.Transaction, index int) (*types.Receipt, error)
- func (a *Action) AssetTransferToExec(transfer *types.AssetsTransferToExec, tx *types.Transaction, index int) (*types.Receipt, error)
- func (a *Action) AssetWithdraw(withdraw *types.AssetsWithdraw, tx *types.Transaction, index int) (*types.Receipt, error)
- func (a *Action) ContractToTree(payload *zt.ZkContractToTree) (*types.Receipt, error)
- func (a *Action) ContractToTreeAcctIdProc(payload *zt.ZkContractToTree, token *zt.ZkTokenSymbol) (*types.Receipt, error)
- func (a *Action) Deposit(payload *zt.ZkDeposit) (*types.Receipt, error)
- func (a *Action) FullExit(payload *zt.ZkFullExit) (*types.Receipt, error)
- func (a *Action) GetIndex() int64
- func (a *Action) MakeFeeLog(amount string, info *TreeUpdateInfo, tokenId uint64, sign *zt.ZkSignature) (*types.Receipt, error)
- func (a *Action) MintNFT(payload *zt.ZkMintNFT) (*types.Receipt, error)
- func (a *Action) ProxyExit(payload *zt.ZkProxyExit) (*types.Receipt, error)
- func (a *Action) SetDefultPubKey(payload *zt.ZkSetPubKey, info *TreeUpdateInfo, leaf *zt.Leaf, ...) ([]*types.KeyValue, []*types.KeyValue, error)
- func (a *Action) SetProxyPubKey(payload *zt.ZkSetPubKey, info *TreeUpdateInfo, leaf *zt.Leaf, ...) ([]*types.KeyValue, []*types.KeyValue, error)
- func (a *Action) SetPubKey(payload *zt.ZkSetPubKey) (*types.Receipt, error)
- func (a *Action) SpotMatch(payload *et.SpotLimitOrder, list *types.Receipt) (*types.Receipt, error)
- func (a *Action) SpotNftMatch(payload *et.SpotNftTakerOrder, list *types.Receipt) (*types.Receipt, error)
- func (a *Action) Swap(payload1 *et.SpotLimitOrder, trade *et.ReceiptSpotTrade) (*types.Receipt, error)
- func (a *Action) SwapWithNft(payload1 *et.SpotNftTakerOrder, trade *et.ReceiptSpotTrade) (*types.Receipt, error)
- func (a *Action) TransferToNew(payload *zt.ZkTransferToNew) (*types.Receipt, error)
- func (a *Action) TreeToContract(payload *zt.ZkTreeToContract) (*types.Receipt, error)
- func (a *Action) UpdateContractAccount(amount, symbol string, option int32, execName string) (*types.Receipt, error)
- func (a *Action) UpdateExecAccount(accountdb *account.DB, amount int64, option int32, execName string) (*types.Receipt, error)
- func (a *Action) ZkTransfer(payload *zt.ZkTransfer) (*types.Receipt, error)
- func (a *Action) ZkWithdraw(payload *zt.ZkWithdraw) (*types.Receipt, error)
- type CommitProofRow
- type HistoryAccountTreeRow
- type TreeUpdateInfo
- type ZksyncInfoRow
Constants ¶
const ( // 存款 ListZkDeposit = 1 // 提款 ListZkWithdraw = 2 // 现货撮合 ListSpotMatch = 1001 )
const ( //KeyPrefixStateDB state db key必须前缀 KeyPrefixStateDB = "mavl-zksync-" //KeyPrefixLocalDB local db的key必须前缀 KeyPrefixLocalDB = "LODB-zksync" )
Variables ¶
This section is empty.
Functions ¶
func AddNewLeaf ¶
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 GetAccountTreeKey ¶
func GetAccountTreeKey() []byte
func GetAllRoots ¶
func GetChain33EthPrimaryKey ¶
func GetHistoryAccountProof ¶ added in v1.67.4
func GetHistoryAccountProof(historyAccountInfo *zt.HistoryAccountProofInfo, targetAccountId, targetTokenId uint64) (*zt.ZkProofWitness, error)
func GetLeafByAccountId ¶
func GetLeafByChain33Address ¶
func GetLeafByEthAddress ¶
func GetNFTHashPrimaryKey ¶ added in v1.67.4
func GetNFTIdPrimaryKey ¶ added in v1.67.4
func GetRootByStartIndex ¶
func GetRootIndexPrimaryKey ¶
func GetTokenByAccountIdAndTokenId ¶
func GetTokenByAccountIdAndTokenId(db dbm.KV, accountId uint64, tokenId uint64, info *TreeUpdateInfo) (*zt.TokenBalance, error)
func GetTokenPrimaryKey ¶
func GetTokenSymbolIdKey ¶ added in v1.67.4
GetTokenSymbolIdKey token symbol 对应id
func GetTokenSymbolKey ¶ added in v1.67.4
GetTokenSymbolKey tokenId 对应symbol
func NewAccountTree ¶
func NewAccountTree(localDb dbm.KVDB, ethFeeAddr, chain33FeeAddr string) ([]*types.KeyValue, *table.Table)
NewAccountTree 生成账户树,同时生成1号账户
func NewAccountTreeTable ¶
NewAccountTreeTable ...
func NewCommitProofTable ¶
NewCommitProofTable ...
func NewHistoryAccountTreeTable ¶
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 SpotCheckTx ¶ added in v1.67.4
func SpotCheckTx(cfg *types.Chain33Config, tx *types.Transaction, index int) error
CheckTx 实现自定义检验交易接口,供框架调用
Types ¶
type AccountTreeRow ¶
AccountTreeRow table meta 结构
func NewAccountTreeRow ¶
func NewAccountTreeRow() *AccountTreeRow
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 (*Action) AssetMatch ¶ added in v1.67.4
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 ¶
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) FullExit ¶
FullExit 为了避免L2不打包某些用户的从L2向L1的提款交易,fullExit是从L1发起的,强制L2打包提款的交易,L1会在证明中校验,当前没支持此类交易
func (*Action) MakeFeeLog ¶
func (a *Action) MakeFeeLog(amount string, info *TreeUpdateInfo, tokenId uint64, sign *zt.ZkSignature) (*types.Receipt, error)
func (*Action) ProxyExit ¶ added in v1.67.4
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) SpotMatch ¶ added in v1.67.4
处理撮合结果
如果是 按不同的交易类型来处理的话, 零知识证明部分的代码, 会随交易的多样化, 需要也写很多函数来支持. 所以结果最好以 结算的形式作为参数. 不同交易的结果, 转化为有限的几种结算 主动结算: (用户地址发起的交易) 如: 撮合 被动结算: (系统特定帐号发起的交易) 如: 永续中暴仓, 和资金费 结算的列表以结果的形式体现帐号的变化, 和具体的业务无关
func (*Action) SpotNftMatch ¶ added in v1.67.4
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 (*Action) TreeToContract ¶
TreeToContract amount需要和签名的一致,签名需要电路验证,amount需要包括精度位
func (*Action) UpdateContractAccount ¶
func (*Action) UpdateExecAccount ¶ added in v1.67.4
func (*Action) ZkTransfer ¶ added in v1.67.4
func (*Action) ZkWithdraw ¶ added in v1.67.4
type CommitProofRow ¶
type CommitProofRow struct {
*zt.ZkCommitProof
}
CommitProofRow table meta 结构
func NewCommitProofRow ¶
func NewCommitProofRow() *CommitProofRow
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) Get ¶
func (r *ZksyncInfoRow) Get(key string) ([]byte, error)
Get 按照indexName 查询 indexValue
func (*ZksyncInfoRow) SetPayload ¶
func (r *ZksyncInfoRow) SetPayload(data types.Message) error
SetPayload 设置数据