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

@@ -27,7 +27,7 @@ func CleanL2DB(db *sqlx.DB) {
func GenPoolTxs(n int, tokens []common.Token) []*common.PoolL2Tx {
txs := make([]*common.PoolL2Tx, 0, n)
privK := babyjub.NewRandPrivKey()
for i := 0; i < n; i++ {
for i := 256; i < 256+n; i++ {
var state common.PoolL2TxState
//nolint:gomnd
if i%4 == 0 {
@@ -54,7 +54,6 @@ func GenPoolTxs(n int, tokens []common.Token) []*common.PoolL2Tx {
*absFee = fee.Percentage() * *usd
}
tx := &common.PoolL2Tx{
TxID: common.TxID(common.Hash([]byte(strconv.Itoa(i)))),
FromIdx: common.Idx(i),
ToIdx: common.Idx(i + 1),
ToEthAddr: ethCommon.BigToAddress(big.NewInt(int64(i))),
@@ -72,6 +71,11 @@ func GenPoolTxs(n int, tokens []common.Token) []*common.PoolL2Tx {
AbsoluteFee: absFee,
AbsoluteFeeUpdate: token.USDUpdate,
}
var err error
tx, err = common.NewPoolL2Tx(tx)
if err != nil {
panic(err)
}
if i%2 == 0 { // Optional parameters: rq
tx.RqFromIdx = common.Idx(i)
tx.RqToIdx = common.Idx(i + 1)