Feature/null refactor (#173)

* WIP: rebase

* Make nullable fields use pointers
This commit is contained in:
a_bennassar
2020-10-06 10:34:49 +02:00
committed by GitHub
parent 7df9288977
commit 49366e3fa4
32 changed files with 422 additions and 240 deletions

View File

@@ -74,7 +74,9 @@ func GenBatches(nBatches int, blocks []common.Block) []common.Batch {
SlotNum: common.SlotNum(i),
}
if i%2 == 0 {
batch.ForgeL1TxsNum = int64(i)
toForge := new(int64)
*toForge = int64(i)
batch.ForgeL1TxsNum = toForge
}
batches = append(batches, batch)
}
@@ -155,7 +157,7 @@ func GenL1Txs(
panic(err)
}
tx = *nTx
if batches[i%len(batches)].ForgeL1TxsNum != 0 {
if batches[i%len(batches)].ForgeL1TxsNum != nil {
// Add already forged txs
tx.BatchNum = &batches[i%len(batches)].BatchNum
setFromToAndAppend(fromIdx, tx, i, nUserTxs, userAddr, accounts, &userTxs, &othersTxs)
@@ -170,13 +172,13 @@ func GenL1Txs(
}
// GetNextToForgeNumAndBatch returns the next BatchNum and ForgeL1TxsNum to be added
func GetNextToForgeNumAndBatch(batches []common.Batch) (common.BatchNum, int64) {
func GetNextToForgeNumAndBatch(batches []common.Batch) (common.BatchNum, *int64) {
batchNum := batches[len(batches)-1].BatchNum + 1
var toForgeL1TxsNum int64
toForgeL1TxsNum := new(int64)
found := false
for i := len(batches) - 1; i >= 0; i-- {
if batches[i].ForgeL1TxsNum != 0 {
toForgeL1TxsNum = batches[i].ForgeL1TxsNum + 1
if batches[i].ForgeL1TxsNum != nil {
*toForgeL1TxsNum = *batches[i].ForgeL1TxsNum + 1
found = true
break
}
@@ -218,7 +220,9 @@ func setFromToAndAppend(
panic(err)
}
}
tx.FromIdx = from.Idx
fromIdx := new(common.Idx)
*fromIdx = from.Idx
tx.FromIdx = fromIdx
tx.FromEthAddr = from.EthAddr
tx.FromBJJ = from.PublicKey
tx.ToIdx = to.Idx
@@ -232,7 +236,9 @@ func setFromToAndAppend(
if err != nil {
panic(err)
}
tx.FromIdx = from.Idx
fromIdx := new(common.Idx)
*fromIdx = from.Idx
tx.FromIdx = fromIdx
tx.FromEthAddr = from.EthAddr
tx.FromBJJ = from.PublicKey
tx.ToIdx = to.Idx
@@ -435,9 +441,6 @@ func randomTxType(seed int) common.TxType {
case 0:
return common.TxTypeExit
//nolint:gomnd
case 1:
return common.TxTypeWithdrawn
//nolint:gomnd
case 2:
return common.TxTypeTransfer
//nolint:gomnd