forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 3
/
parse.go
31 lines (27 loc) · 814 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
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package block
import "fmt"
func Parse(bytes []byte) (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)
}
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
}