TxSel integrated with L2DB, Add L1CoordTx creation
- GetL2TxSelection & GetL1L2TxSelection integrated with dbs
- Create L1CoordinatorTx of type CreateAccountDeposit when a L2
requires it (and the AccountCreationAuth exists)
// maxBalanceBytes is the maximum bytes that can use the Account.Balance *big.Int
// maxBalanceBytes is the maximum bytes that can use the Account.Balance *big.Int
maxBalanceBytes=24
maxBalanceBytes=24
idxBytesLen=4
// maxIdxValue is the maximum value that Idx can have (32 bits: maxIdxValue=2**32-1)
maxIdxValue=0xffffffff
// userThreshold determines the threshold from the User Idxs can be
userThreshold=256
// IdxUserThreshold is a Idx type value that determines the threshold
// from the User Idxs can be
IdxUserThreshold=Idx(userThreshold)
)
)
// Idx represents the account Index in the MerkleTree
typeIdxuint32
// Bytes returns a byte array representing the Idx
func(idxIdx)Bytes()[]byte{
varb[4]byte
binary.LittleEndian.PutUint32(b[:],uint32(idx))
returnb[:]
}
// BigInt returns a *big.Int representing the Idx
func(idxIdx)BigInt()*big.Int{
returnbig.NewInt(int64(idx))
}
// IdxFromBytes returns Idx from a byte array
funcIdxFromBytes(b[]byte)(Idx,error){
iflen(b)!=idxBytesLen{
return0,fmt.Errorf("can not parse Idx, bytes len %d, expected 4",len(b))
}
idx:=binary.LittleEndian.Uint32(b[:4])
returnIdx(idx),nil
}
// IdxFromBigInt converts a *big.Int to Idx type
funcIdxFromBigInt(b*big.Int)(Idx,error){
ifb.Int64()>maxIdxValue{
return0,ErrNumOverflow
}
returnIdx(uint32(b.Int64())),nil
}
// Account is a struct that gives information of the holdings of an address and a specific token. Is the data structure that generates the Value stored in the leaf of the MerkleTree
// Account is a struct that gives information of the holdings of an address and a specific token. Is the data structure that generates the Value stored in the leaf of the MerkleTree
// tx valid, StateDB will use the ToIdx==0 to define the AuxToIdx
validTxs=append(validTxs,l2TxsRaw[i])
continue
}
// check if ToEthAddr is in AccountCreationAuths
_,err:=txsel.l2db.GetAccountCreationAuth(l2TxsRaw[i].ToEthAddr)// TODO once l2db.GetAccountCreationAuth is ready, use the value returned as 'accAuth'
iferr!=nil{
// not found, l2Tx will not be added in the selection
continue
}
validTxs=append(validTxs,l2TxsRaw[i])
// create L1CoordinatorTx for the accountCreation
l1CoordinatorTx:=&common.L1Tx{
UserOrigin:false,
// FromEthAddr: accAuth.EthAddr, // TODO This 2 lines will panic, as l2db.GetAccountCreationAuth is not implemented yet and returns nil. Uncomment this 2 lines once l2db method is done.