-
Notifications
You must be signed in to change notification settings - Fork 661
/
parse.go
34 lines (30 loc) · 863 Bytes
/
parse.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
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package block
import (
"fmt"
"time"
)
func Parse(bytes []byte, durangoTime time.Time) (Block, error) {
var block Block
parsedVersion, err := Codec.Unmarshal(bytes, &block)
if err != nil {
return nil, err
}
if parsedVersion != CodecVersion {
return nil, fmt.Errorf("expected codec version %d but got %d", CodecVersion, parsedVersion)
}
return block, block.initialize(bytes, durangoTime)
}
func ParseHeader(bytes []byte) (Header, error) {
header := statelessHeader{}
parsedVersion, err := Codec.Unmarshal(bytes, &header)
if err != nil {
return nil, err
}
if parsedVersion != CodecVersion {
return nil, fmt.Errorf("expected codec version %d but got %d", CodecVersion, parsedVersion)
}
header.bytes = bytes
return &header, nil
}