arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
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/hermez-node/prover"
13	"github.com/hermeznetwork/tracerr"
14)
15
16// TxStatus is used to mark the status of an ethereum transaction
17type TxStatus string
18
19const (
20	// TxStatusPending marks the Tx as Pending
21	TxStatusPending TxStatus = "pending"
22	// TxStatusSent marks the Tx as Sent
23	TxStatusSent TxStatus = "sent"
24)
25
26// BatchInfo contans the Batch information
27type BatchInfo struct {
28	BatchNum       common.BatchNum
29	ServerProof    prover.Client
30	ZKInputs       *common.ZKInputs
31	Proof          *prover.Proof
32	L1UserTxsExtra []common.L1Tx
33	L1CoordTxs     []common.L1Tx
34	L2Txs          []common.PoolL2Tx
35	ForgeBatchArgs *eth.RollupForgeBatchArgs
36	// FeesInfo
37	TxStatus TxStatus
38	EthTx    *types.Transaction
39	Receipt  *types.Receipt
40}
41
42// DebugStore is a debug function to store the BatchInfo as a json text file in
43// storePath
44func (b *BatchInfo) DebugStore(storePath string) error {
45	batchJSON, err := json.Marshal(b)
46	if err != nil {
47		return tracerr.Wrap(err)
48	}
49	oldStateRoot := "null"
50	if b.ZKInputs != nil && b.ZKInputs.OldStateRoot != nil {
51		oldStateRoot = b.ZKInputs.OldStateRoot.String()
52	}
53	filename := fmt.Sprintf("%010d-%s.json", b.BatchNum, oldStateRoot)
54	// nolint reason: 0640 allows rw to owner and r to group
55	//nolint:gosec
56	return ioutil.WriteFile(path.Join(storePath, filename), batchJSON, 0640)
57}