-
Notifications
You must be signed in to change notification settings - Fork 671
/
codec.go
96 lines (82 loc) · 3.3 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package txs
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/signer"
"github.com/ava-labs/avalanchego/vms/platformvm/stakeable"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)
// Version is the current default codec version
const Version = 0
var (
Codec codec.Manager
// GenesisCodec allows txs of larger than usual size to be parsed.
// While this gives flexibility in accommodating large genesis txs
// it must not be used to parse new, unverified txs which instead
// must be processed by Codec
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 []linearcodec.Codec{c, gc} {
// Order in which type are registered affect the byte representation
// generated by marshalling ops. To maintain codec type ordering,
// we skip positions for the blocks.
c.SkipRegistrations(5)
errs.Add(RegisterUnsignedTxsTypes(c))
}
errs.Add(
Codec.RegisterCodec(Version, c),
GenesisCodec.RegisterCodec(Version, gc),
)
if errs.Errored() {
panic(errs.Err)
}
}
// RegisterUnsignedTxsTypes allows registering relevant type of unsigned package
// in the right sequence. Following repackaging of platformvm package, a few
// subpackage-level codecs were introduced, each handling serialization of specific types.
// RegisterUnsignedTxsTypes is made exportable so to guarantee that other codecs
// are coherent with components one.
func RegisterUnsignedTxsTypes(targetCodec codec.Registry) error {
errs := wrappers.Errs{}
errs.Add(
// 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.
targetCodec.RegisterType(&secp256k1fx.TransferInput{}),
targetCodec.RegisterType(&secp256k1fx.MintOutput{}),
targetCodec.RegisterType(&secp256k1fx.TransferOutput{}),
targetCodec.RegisterType(&secp256k1fx.MintOperation{}),
targetCodec.RegisterType(&secp256k1fx.Credential{}),
targetCodec.RegisterType(&secp256k1fx.Input{}),
targetCodec.RegisterType(&secp256k1fx.OutputOwners{}),
targetCodec.RegisterType(&AddValidatorTx{}),
targetCodec.RegisterType(&AddSubnetValidatorTx{}),
targetCodec.RegisterType(&AddDelegatorTx{}),
targetCodec.RegisterType(&CreateChainTx{}),
targetCodec.RegisterType(&CreateSubnetTx{}),
targetCodec.RegisterType(&ImportTx{}),
targetCodec.RegisterType(&ExportTx{}),
targetCodec.RegisterType(&AdvanceTimeTx{}),
targetCodec.RegisterType(&RewardValidatorTx{}),
targetCodec.RegisterType(&stakeable.LockIn{}),
targetCodec.RegisterType(&stakeable.LockOut{}),
// Banff additions:
targetCodec.RegisterType(&RemoveSubnetValidatorTx{}),
targetCodec.RegisterType(&TransformSubnetTx{}),
targetCodec.RegisterType(&AddPermissionlessValidatorTx{}),
targetCodec.RegisterType(&AddPermissionlessDelegatorTx{}),
targetCodec.RegisterType(&signer.Empty{}),
targetCodec.RegisterType(&signer.ProofOfPossession{}),
)
return errs.Err
}