forked from ava-labs/avalanchego
/
parser.go
31 lines (26 loc) · 808 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
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package vertex
import (
"github.com/dim4egster/qmallgo/snow/consensus/avalanche"
"github.com/dim4egster/qmallgo/utils/hashing"
)
// Parser parses bytes into a vertex.
type Parser interface {
// Parse a vertex from a slice of bytes
ParseVtx(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 := c.Unmarshal(bytes, &vtx)
if err != nil {
return nil, err
}
vtx.Version = version
return statelessVertex{
innerStatelessVertex: vtx,
id: hashing.ComputeHash256Array(bytes),
bytes: bytes,
}, nil
}