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 Vars *RollupVariables
26}
27
28// NewRollupData creates an empty RollupData with the slices initialized.
29func NewRollupData() RollupData {
30 return RollupData{
31 L1UserTxs: make([]L1Tx, 0),
32 Batches: make([]BatchData, 0),
33 AddedTokens: make([]Token, 0),
34 Withdrawals: make([]WithdrawInfo, 0),
35 Vars: nil,
36 }
37}
38
39// AuctionData contains information returned by the Action smart contract
40type AuctionData struct {
41 Bids []Bid
42 Coordinators []Coordinator
43 Vars *AuctionVariables
44}
45
46// NewAuctionData creates an empty AuctionData with the slices initialized.
47func NewAuctionData() AuctionData {
48 return AuctionData{
49 Bids: make([]Bid, 0),
50 Coordinators: make([]Coordinator, 0),
51 Vars: nil,
52 }
53}
54
55// WDelayerTransfer represents a transfer (either deposit or withdrawal) in the
56// WDelayer smart contract
57type WDelayerTransfer struct {
58 Owner ethCommon.Address
59 Token ethCommon.Address
60 Amount *big.Int
61 // TxHash ethCommon.Hash // hash of the transaction in which the wdelayer transfer happened
62}
63
64// WDelayerData contains information returned by the WDelayer smart contract
65type WDelayerData struct {
66 Vars *WDelayerVariables
67 Deposits []WDelayerTransfer
68 // We use an array because there can be multiple deposits in a single eth transaction
69 DepositsByTxHash map[ethCommon.Hash][]*WDelayerTransfer
70 Withdrawals []WDelayerTransfer
71}
72
73// NewWDelayerData creates an empty WDelayerData.
74func NewWDelayerData() WDelayerData {
75 return WDelayerData{
76 Vars: nil,
77 Deposits: make([]WDelayerTransfer, 0),
78 DepositsByTxHash: make(map[ethCommon.Hash][]*WDelayerTransfer),
79 Withdrawals: make([]WDelayerTransfer, 0),
80 }
81}
82
83// BlockData contains the information of a Block
84type BlockData struct {
85 Block Block
86 Rollup RollupData
87 Auction AuctionData
88 WDelayer WDelayerData
89 // TODO: enable when common.WithdrawalDelayerVars is Merged from Synchronizer PR
90 // WithdrawalDelayerVars *common.WithdrawalDelayerVars
91}