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 L1UserTxsExtra []common.L1Tx
35 L1CoordTxs []common.L1Tx
36 L2Txs []common.PoolL2Tx
37 ForgeBatchArgs *eth.RollupForgeBatchArgs
38 // FeesInfo
39 TxStatus TxStatus
40 EthTx *types.Transaction
41 Receipt *types.Receipt
42}
43
44// DebugStore is a debug function to store the BatchInfo as a json text file in
45// storePath
46func (b *BatchInfo) DebugStore(storePath string) error {
47 batchJSON, err := json.Marshal(b)
48 if err != nil {
49 return tracerr.Wrap(err)
50 }
51 oldStateRoot := "null"
52 if b.ZKInputs != nil && b.ZKInputs.OldStateRoot != nil {
53 oldStateRoot = b.ZKInputs.OldStateRoot.String()
54 }
55 filename := fmt.Sprintf("%010d-%s.json", b.BatchNum, oldStateRoot)
56 // nolint reason: 0640 allows rw to owner and r to group
57 //nolint:gosec
58 return ioutil.WriteFile(path.Join(storePath, filename), batchJSON, 0640)
59}