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