arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
hermez-node/common/block.go
common/block.goRaw
 1package common
 2
 3import (
 4	"math/big"
 5	"time"
 6
 7	ethCommon "github.com/ethereum/go-ethereum/common"
 8)
 9
10// Block represents of an Ethereum block
11type Block struct {
12	Num        int64          `meddler:"eth_block_num"`
13	Timestamp  time.Time      `meddler:"timestamp,utctime"`
14	Hash       ethCommon.Hash `meddler:"hash"`
15	ParentHash ethCommon.Hash `meddler:"-" json:"-"`
16}
17
18// RollupData contains information returned by the Rollup smart contract
19type RollupData struct {
20	// L1UserTxs that were submitted in the block
21	L1UserTxs            []L1Tx
22	Batches              []BatchData
23	AddedTokens          []Token
24	Withdrawals          []WithdrawInfo
25	UpdateBucketWithdraw []BucketUpdate
26	TokenExchanges       []TokenExchange
27	Vars                 *RollupVariables
28}
29
30// NewRollupData creates an empty RollupData with the slices initialized.
31func NewRollupData() RollupData {
32	return RollupData{
33		L1UserTxs:   make([]L1Tx, 0),
34		Batches:     make([]BatchData, 0),
35		AddedTokens: make([]Token, 0),
36		Withdrawals: make([]WithdrawInfo, 0),
37		Vars:        nil,
38	}
39}
40
41// AuctionData contains information returned by the Action smart contract
42type AuctionData struct {
43	Bids         []Bid
44	Coordinators []Coordinator
45	Vars         *AuctionVariables
46}
47
48// NewAuctionData creates an empty AuctionData with the slices initialized.
49func NewAuctionData() AuctionData {
50	return AuctionData{
51		Bids:         make([]Bid, 0),
52		Coordinators: make([]Coordinator, 0),
53		Vars:         nil,
54	}
55}
56
57// WDelayerTransfer represents a transfer (either deposit or withdrawal) in the
58// WDelayer smart contract
59type WDelayerTransfer struct {
60	Owner  ethCommon.Address
61	Token  ethCommon.Address
62	Amount *big.Int
63	// TxHash ethCommon.Hash // hash of the transaction in which the wdelayer transfer happened
64}
65
66// WDelayerData contains information returned by the WDelayer smart contract
67type WDelayerData struct {
68	Vars     *WDelayerVariables
69	Deposits []WDelayerTransfer
70	// We use an array because there can be multiple deposits in a single eth transaction
71	DepositsByTxHash       map[ethCommon.Hash][]*WDelayerTransfer
72	Withdrawals            []WDelayerTransfer
73	EscapeHatchWithdrawals []WDelayerEscapeHatchWithdrawal
74}
75
76// NewWDelayerData creates an empty WDelayerData.
77func NewWDelayerData() WDelayerData {
78	return WDelayerData{
79		Vars:             nil,
80		Deposits:         make([]WDelayerTransfer, 0),
81		DepositsByTxHash: make(map[ethCommon.Hash][]*WDelayerTransfer),
82		Withdrawals:      make([]WDelayerTransfer, 0),
83	}
84}
85
86// BlockData contains the information of a Block
87type BlockData struct {
88	Block    Block
89	Rollup   RollupData
90	Auction  AuctionData
91	WDelayer WDelayerData
92}