-
Notifications
You must be signed in to change notification settings - Fork 666
/
codec.go
77 lines (64 loc) · 2.14 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
75
76
77
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package platformvm
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/stakeable"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)
const (
// CodecVersion is the current default codec version
CodecVersion = 0
)
// Codecs do serialization and deserialization
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(
c.RegisterType(&ProposalBlock{}),
c.RegisterType(&AbortBlock{}),
c.RegisterType(&CommitBlock{}),
c.RegisterType(&StandardBlock{}),
c.RegisterType(&AtomicBlock{}),
// The Fx is registered here because this is the same place it is
// registered in the AVM. This ensures that the typeIDs match up for
// utxos in shared memory.
c.RegisterType(&secp256k1fx.TransferInput{}),
c.RegisterType(&secp256k1fx.MintOutput{}),
c.RegisterType(&secp256k1fx.TransferOutput{}),
c.RegisterType(&secp256k1fx.MintOperation{}),
c.RegisterType(&secp256k1fx.Credential{}),
c.RegisterType(&secp256k1fx.Input{}),
c.RegisterType(&secp256k1fx.OutputOwners{}),
c.RegisterType(&UnsignedAddValidatorTx{}),
c.RegisterType(&UnsignedAddSubnetValidatorTx{}),
c.RegisterType(&UnsignedAddDelegatorTx{}),
c.RegisterType(&UnsignedCreateChainTx{}),
c.RegisterType(&UnsignedCreateSubnetTx{}),
c.RegisterType(&UnsignedImportTx{}),
c.RegisterType(&UnsignedExportTx{}),
c.RegisterType(&UnsignedAdvanceTimeTx{}),
c.RegisterType(&UnsignedRewardValidatorTx{}),
c.RegisterType(&stakeable.LockIn{}),
c.RegisterType(&stakeable.LockOut{}),
)
}
errs.Add(
Codec.RegisterCodec(CodecVersion, c),
GenesisCodec.RegisterCodec(CodecVersion, gc),
)
if errs.Errored() {
panic(errs.Err)
}
}