-
Notifications
You must be signed in to change notification settings - Fork 658
/
datastream.go
48 lines (41 loc) · 1.28 KB
/
datastream.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package sequencer
import (
"time"
"unsafe"
"github.com/0xPolygonHermez/zkevm-data-streamer/datastreamer"
"github.com/ethereum/go-ethereum/common"
)
const (
// StreamTypeSequencer represents a Sequencer stream
StreamTypeSequencer datastreamer.StreamType = 1
// EntryTypeL2Block represents a L2 block
EntryTypeL2Block datastreamer.EntryType = 1
// EntryTypeL2Tx represents a L2 transaction
EntryTypeL2Tx datastreamer.EntryType = 2
)
// DSL2Block represents a data stream L2 block
type DSL2Block struct {
BatchNumber uint64
L2BlockNumber uint64
Timestamp time.Time
GlobalExitRoot common.Hash
Coinbase common.Address
}
// Encode returns the encoded L2Block as a byte slice
func (b DSL2Block) Encode() []byte {
const size = int(unsafe.Sizeof(DSL2Block{}))
return (*(*[size]byte)(unsafe.Pointer(&b)))[:]
}
// DSL2Transaction represents a data stream L2 transaction
type DSL2Transaction struct {
BatchNumber uint64
EffectiveGasPricePercentage uint8
IsValid uint8
EncodedLength uint32
Encoded []byte
}
// Encode returns the encoded L2Transaction as a byte slice
func (l DSL2Transaction) Encode() []byte {
const size = int(unsafe.Sizeof(DSL2Transaction{}))
return (*(*[size]byte)(unsafe.Pointer(&l)))[:]
}