-
Notifications
You must be signed in to change notification settings - Fork 663
/
codec.go
74 lines (63 loc) · 2.1 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
73
74
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package block
import (
"math"
"github.com/ava-labs/avalanchego/codec"
"github.com/ava-labs/avalanchego/codec/linearcodec"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/wrappers"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
)
const CodecVersion = txs.CodecVersion
var (
// GenesisCodec 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
GenesisCodec codec.Manager
Codec codec.Manager
)
func init() {
c := linearcodec.NewDefault()
gc := linearcodec.NewDefault()
errs := wrappers.Errs{}
for _, c := range []linearcodec.Codec{c, gc} {
errs.Add(
RegisterApricotBlockTypes(c),
txs.RegisterUnsignedTxsTypes(c),
RegisterBanffBlockTypes(c),
txs.RegisterDUnsignedTxsTypes(c),
)
}
Codec = codec.NewDefaultManager()
GenesisCodec = codec.NewManager(math.MaxInt32)
errs.Add(
Codec.RegisterCodec(CodecVersion, c),
GenesisCodec.RegisterCodec(CodecVersion, 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 {
return utils.Err(
targetCodec.RegisterType(&ApricotProposalBlock{}),
targetCodec.RegisterType(&ApricotAbortBlock{}),
targetCodec.RegisterType(&ApricotCommitBlock{}),
targetCodec.RegisterType(&ApricotStandardBlock{}),
targetCodec.RegisterType(&ApricotAtomicBlock{}),
)
}
func RegisterBanffBlockTypes(targetCodec codec.Registry) error {
return utils.Err(
targetCodec.RegisterType(&BanffProposalBlock{}),
targetCodec.RegisterType(&BanffAbortBlock{}),
targetCodec.RegisterType(&BanffCommitBlock{}),
targetCodec.RegisterType(&BanffStandardBlock{}),
)
}