forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 3
/
parser.go
33 lines (27 loc) · 855 Bytes
/
parser.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
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package vertex
import (
"context"
"github.com/MetalBlockchain/metalgo/snow/consensus/avalanche"
"github.com/MetalBlockchain/metalgo/utils/hashing"
)
// Parser parses bytes into a vertex.
type Parser interface {
// Parse a vertex from a slice of bytes
ParseVtx(ctx context.Context, vertex []byte) (avalanche.Vertex, error)
}
// Parse parses the provided vertex bytes into a stateless vertex
func Parse(bytes []byte) (StatelessVertex, error) {
vtx := innerStatelessVertex{}
version, err := Codec.Unmarshal(bytes, &vtx)
if err != nil {
return nil, err
}
vtx.Version = version
return statelessVertex{
innerStatelessVertex: vtx,
id: hashing.ComputeHash256Array(bytes),
bytes: bytes,
}, nil
}