-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathencoding.go
47 lines (38 loc) · 1.14 KB
/
encoding.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
package common
import (
"fmt"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
)
// EncodedL1Block the encoded version of an L1 block.
type EncodedL1Block []byte
func EncodeBlock(b *types.Block) (EncodedL1Block, error) {
encoded, err := rlp.EncodeToBytes(b)
if err != nil {
return nil, fmt.Errorf("could not encode block to bytes. Cause: %w", err)
}
return encoded, nil
}
func (eb EncodedL1Block) DecodeBlock() (*types.Block, error) {
b := types.Block{}
if err := rlp.DecodeBytes(eb, &b); err != nil {
return nil, fmt.Errorf("could not decode block from bytes. Cause: %w", err)
}
return &b, nil
}
func EncodeRollup(r *ExtRollup) (EncodedRollup, error) {
return rlp.EncodeToBytes(r)
}
func DecodeRollup(encoded EncodedRollup) (*ExtRollup, error) {
r := new(ExtRollup)
err := rlp.DecodeBytes(encoded, r)
return r, err
}
func EncodeAttestation(att *AttestationReport) (EncodedAttestationReport, error) {
return rlp.EncodeToBytes(att)
}
func DecodeAttestation(encoded EncodedAttestationReport) (*AttestationReport, error) {
att := new(AttestationReport)
err := rlp.DecodeBytes(encoded, att)
return att, err
}