hermez-node/coordinator/batch.go
coordinator/batch.goRaw
1package coordinator
2
3import (
4 "encoding/json"
5 "fmt"
6 "io/ioutil"
7 "path"
8
9 "github.com/ethereum/go-ethereum/core/types"
10 "github.com/hermeznetwork/hermez-node/common"
11 "github.com/hermeznetwork/hermez-node/eth"
12 "github.com/hermeznetwork/tracerr"
13)
14
15// Proof TBD this type will be received from the proof server
16type Proof struct {
17}
18
19// TxStatus is used to mark the status of an ethereum transaction
20type TxStatus string
21
22const (
23 // TxStatusPending marks the Tx as Pending
24 TxStatusPending TxStatus = "pending"
25 // TxStatusSent marks the Tx as Sent
26 TxStatusSent TxStatus = "sent"
27)
28
29// BatchInfo contans the Batch information
30type BatchInfo struct {
31 BatchNum common.BatchNum
32 ServerProof ServerProofInterface
33 ZKInputs *common.ZKInputs
34 Proof *Proof
35 L1UserTxsExtra []common.L1Tx
36 L1OperatorTxs []common.L1Tx
37 L2Txs []common.PoolL2Tx
38 ForgeBatchArgs *eth.RollupForgeBatchArgs
39 // FeesInfo
40 TxStatus TxStatus
41 EthTx *types.Transaction
42 Receipt *types.Receipt
43}
44
45// DebugStore is a debug function to store the BatchInfo as a json text file in
46// storePath
47func (b *BatchInfo) DebugStore(storePath string) error {
48 batchJSON, err := json.Marshal(b)
49 if err != nil {
50 return tracerr.Wrap(err)
51 }
52 oldStateRoot := "null"
53 if b.ZKInputs != nil && b.ZKInputs.OldStateRoot != nil {
54 oldStateRoot = b.ZKInputs.OldStateRoot.String()
55 }
56 filename := fmt.Sprintf("%010d-%s.json", b.BatchNum, oldStateRoot)
57 // nolint reason: 0640 allows rw to owner and r to group
58 //nolint:gosec
59 return ioutil.WriteFile(path.Join(storePath, filename), batchJSON, 0640)
60}