-
Notifications
You must be signed in to change notification settings - Fork 82
/
id.go
113 lines (95 loc) · 2.84 KB
/
id.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package eth
import (
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
type BlockID struct {
Hash common.Hash `json:"hash"`
Number uint64 `json:"number"`
}
func (id BlockID) String() string {
return fmt.Sprintf("%s:%d", id.Hash.String(), id.Number)
}
// TerminalString implements log.TerminalStringer, formatting a string for console
// output during logging.
func (id BlockID) TerminalString() string {
return fmt.Sprintf("%s:%d", id.Hash.TerminalString(), id.Number)
}
func ReceiptBlockID(r *types.Receipt) BlockID {
return BlockID{Number: r.BlockNumber.Uint64(), Hash: r.BlockHash}
}
func HeaderBlockID(h *types.Header) BlockID {
return BlockID{Number: h.Number.Uint64(), Hash: h.Hash()}
}
type L2BlockRef struct {
Hash common.Hash `json:"hash"`
Number uint64 `json:"number"`
ParentHash common.Hash `json:"parentHash"`
Time uint64 `json:"timestamp"`
L1Origin BlockID `json:"l1origin"`
SequenceNumber uint64 `json:"sequenceNumber"` // distance to first block of epoch
}
func (id L2BlockRef) String() string {
return fmt.Sprintf("%s:%d", id.Hash.String(), id.Number)
}
// TerminalString implements log.TerminalStringer, formatting a string for console
// output during logging.
func (id L2BlockRef) TerminalString() string {
return fmt.Sprintf("%s:%d", id.Hash.TerminalString(), id.Number)
}
type L1BlockRef struct {
Hash common.Hash `json:"hash"`
Number uint64 `json:"number"`
ParentHash common.Hash `json:"parentHash"`
Time uint64 `json:"timestamp"`
}
func (id L1BlockRef) String() string {
return fmt.Sprintf("%s:%d", id.Hash.String(), id.Number)
}
// TerminalString implements log.TerminalStringer, formatting a string for console
// output during logging.
func (id L1BlockRef) TerminalString() string {
return fmt.Sprintf("%s:%d", id.Hash.TerminalString(), id.Number)
}
func (id L1BlockRef) ID() BlockID {
return BlockID{
Hash: id.Hash,
Number: id.Number,
}
}
func (id L1BlockRef) ParentID() BlockID {
n := id.ID().Number
// Saturate at 0 with subtraction
if n > 0 {
n -= 1
}
return BlockID{
Hash: id.ParentHash,
Number: n,
}
}
func (id L2BlockRef) ID() BlockID {
return BlockID{
Hash: id.Hash,
Number: id.Number,
}
}
func (id L2BlockRef) ParentID() BlockID {
n := id.ID().Number
// Saturate at 0 with subtraction
if n > 0 {
n -= 1
}
return BlockID{
Hash: id.ParentHash,
Number: n,
}
}
// IndexedBlobHash represents a blob hash that commits to a single blob confirmed in a block. The
// index helps us avoid unnecessary blob to blob hash conversions to find the right content in a
// sidecar.
type IndexedBlobHash struct {
Index uint64 // absolute index in the block, a.k.a. position in sidecar blobs array
Hash common.Hash // hash of the blob, used for consistency checks
}