-
Notifications
You must be signed in to change notification settings - Fork 644
/
codec.go
72 lines (64 loc) · 2.09 KB
/
codec.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package blocks
import (
"math"
"github.com/ava-labs/avalanchego/codec"
"github.com/ava-labs/avalanchego/codec/linearcodec"
"github.com/ava-labs/avalanchego/utils/wrappers"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
)
// GenesisCode allows blocks of larger than usual size to be parsed.
// While this gives flexibility in accommodating large genesis blocks
// it must not be used to parse new, unverified blocks which instead
// must be processed by Codec
var (
Codec codec.Manager
GenesisCodec codec.Manager
)
func init() {
c := linearcodec.NewDefault()
Codec = codec.NewDefaultManager()
gc := linearcodec.NewCustomMaxLength(math.MaxInt32)
GenesisCodec = codec.NewManager(math.MaxInt32)
errs := wrappers.Errs{}
for _, c := range []codec.Registry{c, gc} {
errs.Add(
RegisterApricotBlockTypes(c),
txs.RegisterUnsignedTxsTypes(c),
RegisterBlueberryBlockTypes(c),
)
}
errs.Add(
Codec.RegisterCodec(txs.Version, c),
GenesisCodec.RegisterCodec(txs.Version, gc),
)
if errs.Errored() {
panic(errs.Err)
}
}
// RegisterApricotBlockTypes allows registering relevant type of blocks package
// in the right sequence. Following repackaging of platformvm package, a few
// subpackage-level codecs were introduced, each handling serialization of
// specific types.
func RegisterApricotBlockTypes(targetCodec codec.Registry) error {
errs := wrappers.Errs{}
errs.Add(
targetCodec.RegisterType(&ApricotProposalBlock{}),
targetCodec.RegisterType(&ApricotAbortBlock{}),
targetCodec.RegisterType(&ApricotCommitBlock{}),
targetCodec.RegisterType(&ApricotStandardBlock{}),
targetCodec.RegisterType(&ApricotAtomicBlock{}),
)
return errs.Err
}
func RegisterBlueberryBlockTypes(targetCodec codec.Registry) error {
errs := wrappers.Errs{}
errs.Add(
targetCodec.RegisterType(&BlueberryProposalBlock{}),
targetCodec.RegisterType(&BlueberryAbortBlock{}),
targetCodec.RegisterType(&BlueberryCommitBlock{}),
targetCodec.RegisterType(&BlueberryStandardBlock{}),
)
return errs.Err
}