arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
hermez-node/common/pooll2tx.go
common/pooll2tx.goRaw
 1package common
 2
 3import (
 4	"math/big"
 5	"time"
 6
 7	eth "github.com/ethereum/go-ethereum/common"
 8	"github.com/iden3/go-iden3-crypto/babyjub"
 9)
10
11// PoolL2Tx is a struct that represents a L2Tx sent by an account to the coordinator hat is waiting to be forged
12type PoolL2Tx struct {
13	// Stored in DB: mandatory fileds
14	TxID      TxID               `meddler:"tx_id"`
15	FromIdx   Idx                `meddler:"from_idx"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
16	ToIdx     Idx                `meddler:"to_idx"`   // ToIdx is ignored in L1Tx/Deposit, but used in the L1Tx/DepositAndTransfer
17	ToEthAddr eth.Address        `meddler:"to_eth_addr"`
18	ToBJJ     *babyjub.PublicKey `meddler:"to_bjj"` // TODO: stop using json, use scanner/valuer
19	TokenID   TokenID            `meddler:"token_id"`
20	Amount    *big.Int           `meddler:"amount,bigint"` // TODO: change to float16
21	Fee       FeeSelector        `meddler:"fee"`
22	Nonce     uint64             `meddler:"nonce"` // effective 48 bits used
23	State     PoolL2TxState      `meddler:"state"`
24	Signature babyjub.Signature  `meddler:"signature"`         // tx signature
25	Timestamp time.Time          `meddler:"timestamp,utctime"` // time when added to the tx pool
26	// Stored in DB: optional fileds, may be uninitialized
27	BatchNum          BatchNum           `meddler:"batch_num,zeroisnull"`   // batchNum in which this tx was forged. Presence indicates "forged" state.
28	RqFromIdx         Idx                `meddler:"rq_from_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
29	RqToIdx           Idx                `meddler:"rq_to_idx,zeroisnull"`   // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
30	RqToEthAddr       eth.Address        `meddler:"rq_to_eth_addr"`
31	RqToBJJ           *babyjub.PublicKey `meddler:"rq_to_bjj"` // TODO: stop using json, use scanner/valuer
32	RqTokenID         TokenID            `meddler:"rq_token_id,zeroisnull"`
33	RqAmount          *big.Int           `meddler:"rq_amount,bigintnull"` // TODO: change to float16
34	RqFee             FeeSelector        `meddler:"rq_fee,zeroisnull"`
35	RqNonce           uint64             `meddler:"rq_nonce,zeroisnull"` // effective 48 bits used
36	AbsoluteFee       float64            `meddler:"absolute_fee,zeroisnull"`
37	AbsoluteFeeUpdate time.Time          `meddler:"absolute_fee_update,utctimez"`
38	// Extra metadata, may be uninitialized
39	Type               TxType `meddler:"-"` // optional, descrives which kind of tx it's
40	RqTxCompressedData []byte `meddler:"-"` // 253 bits, optional for atomic txs
41}
42
43// PoolL2TxState is a struct that represents the status of a L2 transaction
44type PoolL2TxState string
45
46const (
47	// PoolL2TxStatePending represents a valid L2Tx that hasn't started the forging process
48	PoolL2TxStatePending PoolL2TxState = "pend"
49	// PoolL2TxStateForging represents a valid L2Tx that has started the forging process
50	PoolL2TxStateForging PoolL2TxState = "fing"
51	// PoolL2TxStateForged represents a L2Tx that has already been forged
52	PoolL2TxStateForged PoolL2TxState = "fged"
53	// PoolL2TxStateInvalid represents a L2Tx that has been invalidated
54	PoolL2TxStateInvalid PoolL2TxState = "invl"
55)