github.com/MetalBlockchain/metalgo@v1.11.9/snow/engine/avalanche/vertex/parser.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package vertex 5 6 import ( 7 "context" 8 9 "github.com/MetalBlockchain/metalgo/snow/consensus/avalanche" 10 "github.com/MetalBlockchain/metalgo/utils/hashing" 11 ) 12 13 // Parser parses bytes into a vertex. 14 type Parser interface { 15 // Parse a vertex from a slice of bytes 16 ParseVtx(ctx context.Context, vertex []byte) (avalanche.Vertex, error) 17 } 18 19 // Parse parses the provided vertex bytes into a stateless vertex 20 func Parse(bytes []byte) (StatelessVertex, error) { 21 vtx := innerStatelessVertex{} 22 version, err := Codec.Unmarshal(bytes, &vtx) 23 if err != nil { 24 return nil, err 25 } 26 vtx.Version = version 27 28 return statelessVertex{ 29 innerStatelessVertex: vtx, 30 id: hashing.ComputeHash256Array(bytes), 31 bytes: bytes, 32 }, nil 33 }