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