arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
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	Type            TxType             `meddler:"tx_type"`
26}
27
28func (tx *L1Tx) Tx() *Tx {
29	return &Tx{
30		TxID:    tx.TxID,
31		FromIdx: tx.FromIdx,
32		ToIdx:   tx.ToIdx,
33		Amount:  tx.Amount,
34		Type:    tx.Type,
35	}
36}