Skip to content

Commit

Permalink
witness: make collection id start from 0 (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
yutianwu authored Aug 26, 2022
1 parent 1e552a1 commit 98b88ff
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions core/executor/create_collection_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (e *CreateCollectionExecutor) Prepare() error {

fromAccount := e.bc.StateDB().AccountMap[txInfo.AccountIndex]
// add collection nonce to tx info
txInfo.CollectionId = fromAccount.CollectionNonce + 1
txInfo.CollectionId = fromAccount.CollectionNonce

return nil
}
Expand Down Expand Up @@ -88,7 +88,7 @@ func (e *CreateCollectionExecutor) ApplyTransaction() error {
fromAccount.AssetInfo[txInfo.GasFeeAssetId].Balance = ffmath.Sub(fromAccount.AssetInfo[txInfo.GasFeeAssetId].Balance, txInfo.GasFeeAssetAmount)
gasAccount.AssetInfo[txInfo.GasFeeAssetId].Balance = ffmath.Add(gasAccount.AssetInfo[txInfo.GasFeeAssetId].Balance, txInfo.GasFeeAssetAmount)
fromAccount.Nonce++
fromAccount.CollectionNonce = txInfo.CollectionId
fromAccount.CollectionNonce++

stateCache := e.bc.StateDB()
stateCache.PendingUpdateAccountIndexMap[txInfo.AccountIndex] = statedb.StateCachePending
Expand Down Expand Up @@ -174,12 +174,13 @@ func (e *CreateCollectionExecutor) GenerateTxDetails() ([]*tx.TxDetail, error) {
AccountIndex: txInfo.AccountIndex,
AccountName: fromAccount.AccountName,
Balance: strconv.FormatInt(fromAccount.CollectionNonce, 10),
BalanceDelta: strconv.FormatInt(txInfo.CollectionId, 10),
BalanceDelta: strconv.FormatInt(fromAccount.CollectionNonce+1, 10),
Order: order,
Nonce: fromAccount.Nonce,
AccountOrder: accountOrder,
CollectionNonce: fromAccount.CollectionNonce,
})
fromAccount.CollectionNonce = fromAccount.CollectionNonce + 1

// from account gas
order++
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
)

require (
github.com/bnb-chain/zkbas-crypto v0.0.4-0.20220825082047-852b76a0f52e
github.com/bnb-chain/zkbas-crypto v0.0.4-0.20220826080057-cf73b7c34536
github.com/bnb-chain/zkbas-eth-rpc v0.0.1
github.com/consensys/gnark v0.7.0
github.com/consensys/gnark-crypto v0.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqO
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
github.com/bnb-chain/bas-smt v0.0.0-20220804090937-a7712cdee391 h1:U0pz17/+58EvEzjpqmRoJJ+wy0hYWNDQb+afohYrths=
github.com/bnb-chain/bas-smt v0.0.0-20220804090937-a7712cdee391/go.mod h1:VJsBjo+k7FICpTw27+LwuAvfq9I13UJ4hUjmberr22Q=
github.com/bnb-chain/zkbas-crypto v0.0.4-0.20220825082047-852b76a0f52e h1:8WbyjU7FVTpmmH/wsNPJZEfV/cdqjztXR9TA9wkQ7Gk=
github.com/bnb-chain/zkbas-crypto v0.0.4-0.20220825082047-852b76a0f52e/go.mod h1:W9Daa6XJT7U48WA9+5YQTsEfwzxFs8rC3FeUQ6hGFNo=
github.com/bnb-chain/zkbas-crypto v0.0.4-0.20220826080057-cf73b7c34536 h1:Aor/h0Nc1cEO1ujhxzAzH7x6Lm1lNYWMZhnnaceOo5A=
github.com/bnb-chain/zkbas-crypto v0.0.4-0.20220826080057-cf73b7c34536/go.mod h1:W9Daa6XJT7U48WA9+5YQTsEfwzxFs8rC3FeUQ6hGFNo=
github.com/bnb-chain/zkbas-eth-rpc v0.0.1 h1:5wqS5TumcxXWovdMRWE6ZWC8mU4lmfRrRCV7sI7mVvw=
github.com/bnb-chain/zkbas-eth-rpc v0.0.1/go.mod h1:t8jY6/Jt/Rw8LeU9Rhw406uaOIOou4ycVX06LKyVxKo=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
Expand Down

0 comments on commit 98b88ff

Please sign in to comment.