mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
Add abstraction method of processTxs to StateDB
- Update GHA lint.yml increasing timeout time to avoid GHA Lint errors
- Update common.BatchNum & common.Idx & common.Nonce usage in StateDB
- Add abstraction method of processTxs to StateDB
- Which will be used by Synchronizer & BatchBuilder
This commit is contained in:
11
common/tx.go
11
common/tx.go
@@ -2,6 +2,7 @@ package common
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
@@ -20,6 +21,15 @@ func (idx Idx) BigInt() *big.Int {
|
||||
return big.NewInt(int64(idx))
|
||||
}
|
||||
|
||||
// IdxFromBytes returns Idx from a byte array
|
||||
func IdxFromBytes(b []byte) (Idx, error) {
|
||||
if len(b) != 4 {
|
||||
return 0, fmt.Errorf("can not parse Idx, bytes len %d, expected 4", len(b))
|
||||
}
|
||||
idx := binary.LittleEndian.Uint32(b[:4])
|
||||
return Idx(idx), nil
|
||||
}
|
||||
|
||||
// IdxFromBigInt converts a *big.Int to Idx type
|
||||
func IdxFromBigInt(b *big.Int) (Idx, error) {
|
||||
if b.Int64() > 0xffffffff { // 2**32-1
|
||||
@@ -64,7 +74,6 @@ type Tx struct {
|
||||
TxID TxID
|
||||
FromIdx Idx // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
|
||||
ToIdx Idx // ToIdx is ignored in L1Tx/Deposit, but used in the L1Tx/DepositTransfer
|
||||
TokenID TokenID
|
||||
Amount *big.Int
|
||||
Nonce Nonce // effective 40 bits used
|
||||
Fee FeeSelector
|
||||
|
||||
Reference in New Issue
Block a user