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)
13
14// Proof TBD this type will be received from the proof server
15type Proof struct {
16}
17
18// TxStatus is used to mark the status of an ethereum transaction
19type TxStatus string
20
21const (
22	// TxStatusPending marks the Tx as Pending
23	TxStatusPending TxStatus = "pending"
24	// TxStatusSent marks the Tx as Sent
25	TxStatusSent TxStatus = "sent"
26)
27
28// BatchInfo contans the Batch information
29type BatchInfo struct {
30	BatchNum       common.BatchNum
31	ServerProof    ServerProofInterface
32	ZKInputs       *common.ZKInputs
33	Proof          *Proof
34	L1UserTxsExtra []common.L1Tx
35	L1OperatorTxs  []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 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}