-
Notifications
You must be signed in to change notification settings - Fork 671
/
metadata.go
53 lines (42 loc) · 1.45 KB
/
metadata.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package avax
import (
"errors"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/hashing"
"github.com/ava-labs/avalanchego/vms/components/verify"
)
var (
errNilMetadata = errors.New("nil metadata is not valid")
errMetadataNotInitialize = errors.New("metadata was never initialized and is not valid")
_ verify.Verifiable = &Metadata{}
)
// TODO: Delete this once the downstream dependencies have been updated.
type Metadata struct {
id ids.ID // The ID of this data
unsignedBytes []byte // Unsigned byte representation of this data
bytes []byte // Byte representation of this data
}
// Initialize set the bytes and ID
func (md *Metadata) Initialize(unsignedBytes, bytes []byte) {
md.id = hashing.ComputeHash256Array(bytes)
md.unsignedBytes = unsignedBytes
md.bytes = bytes
}
// ID returns the unique ID of this data
func (md *Metadata) ID() ids.ID { return md.id }
// UnsignedBytes returns the unsigned binary representation of this data
func (md *Metadata) Bytes() []byte { return md.unsignedBytes }
// Bytes returns the binary representation of this data
func (md *Metadata) SignedBytes() []byte { return md.bytes }
func (md *Metadata) Verify() error {
switch {
case md == nil:
return errNilMetadata
case md.id == ids.Empty:
return errMetadataNotInitialize
default:
return nil
}
}