hermez-node/common/l1tx.go
common/l1tx.goRaw
1package common
2
3import (
4 "math/big"
5
6 ethCommon "github.com/ethereum/go-ethereum/common"
7 "github.com/iden3/go-iden3-crypto/babyjub"
8)
9
10// L1Tx is a struct that represents a L1 tx
11type L1Tx struct {
12 // Stored in DB: mandatory fileds
13 TxID TxID `meddler:"tx_id"`
14 ToForgeL1TxsNum uint32 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged
15 Position int `meddler:"position"`
16 UserOrigin bool `meddler:"user_origin"` // true if the tx was originated by a user, false if it was aoriginated by a coordinator. Note that this differ from the spec for implementation simplification purpposes
17 FromIdx Idx `meddler:"from_idx"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
18 FromEthAddr ethCommon.Address `meddler:"from_eth_addr"`
19 FromBJJ *babyjub.PublicKey `meddler:"from_bjj"`
20 ToIdx Idx `meddler:"to_idx"` // ToIdx is ignored in L1Tx/Deposit, but used in the L1Tx/DepositAndTransfer
21 TokenID TokenID `meddler:"token_id"`
22 Amount *big.Int `meddler:"amount,bigint"`
23 LoadAmount *big.Int `meddler:"load_amount,bigint"`
24 EthBlockNum uint64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue
25 // Extra metadata, may be uninitialized
26 Type TxType `meddler:"-"` // optional, descrives which kind of tx it's
27}
28
29func (tx *L1Tx) Tx() *Tx {
30 return &Tx{
31 TxID: tx.TxID,
32 FromIdx: tx.FromIdx,
33 ToIdx: tx.ToIdx,
34 TokenID: tx.TokenID,
35 Amount: tx.Amount,
36 Nonce: 0,
37 Fee: 0,
38 Type: tx.Type,
39 }
40}