Help us shape the future of Go! Take the 2026 Go Developer Survey

parsebatchl2data

package
v0.1.113 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FORKID_DRAGONFRUIT = 5

	// EfficiencyPercentageByteLength is the length of the effective percentage in bytes
	EfficiencyPercentageByteLength uint64 = 1
)

Variables

View Source
var (
	// ErrBatchV2DontStartWithChangeL2Block is returned when the batch start directly with a trsansaction (without a changeL2Block)
	ErrBatchV2DontStartWithChangeL2Block = errors.New("batch v2 must start with changeL2Block before Tx (suspect a V1 Batch or a ForcedBatch?))")
	// ErrInvalidBatchV2 is returned when the batch is invalid.
	ErrInvalidBatchV2 = errors.New("invalid batch v2")
	// ErrInvalidRLP is returned when the rlp is invalid.
	ErrInvalidRLP = errors.New("invalid rlp codification")
	// ErrInvalidData is the error when the raw txs is unexpected
	ErrInvalidData = errors.New("invalid data")
)
View Source
var ParseBatchL2Data = &cobra.Command{
	Use:     "parse-batch-l2-data [flags]",
	Aliases: []string{"parsebatchl2data"},
	Short:   "Convert batch l2 data into an ndjson stream.",
	Long:    usage,
	RunE: func(cmd *cobra.Command, args []string) error {

		rawData, err := getInputData(cmd, args)
		if err != nil {
			return err
		}
		batchL2Data := strings.TrimSpace(strings.TrimPrefix(string(rawData), "0x"))
		rawBatchL2Data, err := hex.DecodeString(batchL2Data)
		if err != nil {
			log.Err(err).Msg("Unable to hex decode batch l2 data")
			return err
		}

		rawBatch, err := DecodeBatchV2(rawBatchL2Data)
		if err != nil {
			log.Error().Err(err).Msg("Unable to decode L2 batch data")
			tryRawBatch(rawBatchL2Data)
			return err
		}

		blocks := rawBatch.Blocks

		for _, l2RawBlock := range blocks {
			blockData := struct {
				IndexL1InfoTree uint32
				DeltaTimestamp  uint32
			}{l2RawBlock.IndexL1InfoTree, l2RawBlock.DeltaTimestamp}
			blockDataBytes, err := json.Marshal(blockData)
			if err != nil {
				log.Err(err).Msg("Unable to marshal block data")
				return err
			}
			fmt.Println(string(blockDataBytes))

			for i := range l2RawBlock.Transactions {
				if err := printTxData(&l2RawBlock.Transactions[i]); err != nil {
					log.Error().Err(err).Int("tx_index", i).Msg("Failed to print transaction data")
				}
			}
		}
		return nil
	},
	Args: func(cmd *cobra.Command, args []string) error {
		return nil
	},
}

Functions

func DecodeTxs

func DecodeTxs(txsData []byte, forkID uint64) ([]*types.Transaction, []byte, []uint8, error)

DecodeTxs extracts Transactions for its encoded form

func RlpFieldsToLegacyTx

func RlpFieldsToLegacyTx(fields [][]byte, v, r, s []byte) (tx *types.LegacyTx, err error)

Types

type BatchRawV2

type BatchRawV2 struct {
	Blocks []L2BlockRaw
}

BatchRawV2 is the representation of a batch of transactions.

func DecodeBatchV2

func DecodeBatchV2(txsData []byte) (*BatchRawV2, error)

DecodeBatchV2 decodes a batch of transactions from a byte slice.

type ForcedBatchRawV2

type ForcedBatchRawV2 struct {
	Transactions []L2TxRaw
}

func DecodeForcedBatchV2

func DecodeForcedBatchV2(txsData []byte) (*ForcedBatchRawV2, error)

type L2BlockRaw

type L2BlockRaw struct {
	DeltaTimestamp  uint32
	IndexL1InfoTree uint32
	Transactions    []L2TxRaw
}

L2BlockRaw is the raw representation of a L2 block.

type L2TxRaw

type L2TxRaw struct {
	Tx                   *types.Transaction
	EfficiencyPercentage uint8
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL