Add TxID calculation & New{Layer}Tx Type

Add TxID calculation & New{Layer}Tx Type

New{Layer}Tx methods that compute the `TxID` & `TxType` values from the
transaction values:
- NewL1Tx
- NewL2Tx
- NewPoolL2Tx

Add TxID Scanner & Valuer for database/sql

HistoryDB & L2DB & API packages tests will need to be addapted to the
TestTransaction generation once is done.
This commit is contained in:
arnaucube
2020-09-30 14:05:51 +02:00
parent c6f70f3177
commit 9bb4a4ec1b
21 changed files with 422 additions and 131 deletions

View File

@@ -185,7 +185,7 @@ func (s *StateDB) Reset(batchNum common.BatchNum) error {
return err
}
s.db = sto
s.idx = 0
s.idx = 255
s.currentBatch = batchNum
return nil
}

View File

@@ -319,16 +319,19 @@ func (s *StateDB) processL2Tx(exitTree *merkletree.MerkleTree, tx *common.PoolL2
// case ToEthAddr!=0 && ToBJJ=0
idx, err = s.GetIdxByEthAddr(tx.ToEthAddr)
if err != nil {
log.Error(err)
return nil, nil, false, ErrToIdxNotFound
}
} else if !bytes.Equal(tx.ToEthAddr.Bytes(), common.EmptyAddr.Bytes()) && tx.ToBJJ != nil {
// case ToEthAddr!=0 && ToBJJ!=0
idx, err = s.GetIdxByEthAddrBJJ(tx.ToEthAddr, tx.ToBJJ)
if err != nil {
log.Error(err)
return nil, nil, false, ErrToIdxNotFound
}
} else {
// rest of cases (included case ToEthAddr==0) are not possible
log.Error(err)
return nil, nil, false, ErrToIdxNotFound
}
s.zki.AuxToIdx[s.i] = idx.BigInt()

View File

@@ -40,7 +40,7 @@ func TestProcessTxs(t *testing.T) {
require.Nil(t, err)
}
acc, err := sdb.GetAccount(common.Idx(1))
acc, err := sdb.GetAccount(common.Idx(256))
assert.Nil(t, err)
assert.Equal(t, "23", acc.Balance.String())
}
@@ -73,7 +73,7 @@ func TestProcessTxsBatchByBatch(t *testing.T) {
_, exitInfos, err := sdb.ProcessTxs(true, true, l1Txs[0], coordinatorL1Txs[0], poolL2Txs[0])
require.Nil(t, err)
assert.Equal(t, 0, len(exitInfos))
acc, err := sdb.GetAccount(common.Idx(1))
acc, err := sdb.GetAccount(common.Idx(256))
assert.Nil(t, err)
assert.Equal(t, "28", acc.Balance.String())
@@ -82,8 +82,8 @@ func TestProcessTxsBatchByBatch(t *testing.T) {
_, exitInfos, err = sdb.ProcessTxs(true, true, l1Txs[1], coordinatorL1Txs[1], poolL2Txs[1])
require.Nil(t, err)
assert.Equal(t, 5, len(exitInfos))
acc, err = sdb.GetAccount(common.Idx(1))
assert.Nil(t, err)
acc, err = sdb.GetAccount(common.Idx(256))
require.Nil(t, err)
assert.Equal(t, "48", acc.Balance.String())
// use third batch
@@ -91,7 +91,7 @@ func TestProcessTxsBatchByBatch(t *testing.T) {
_, exitInfos, err = sdb.ProcessTxs(true, true, l1Txs[2], coordinatorL1Txs[2], poolL2Txs[2])
require.Nil(t, err)
assert.Equal(t, 1, len(exitInfos))
acc, err = sdb.GetAccount(common.Idx(1))
acc, err = sdb.GetAccount(common.Idx(256))
assert.Nil(t, err)
assert.Equal(t, "23", acc.Balance.String())
}