forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codec.go
72 lines (62 loc) · 2.47 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-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package txs
import (
"github.com/kukrer/savannahnode/codec"
"github.com/kukrer/savannahnode/codec/linearcodec"
"github.com/kukrer/savannahnode/utils/wrappers"
"github.com/kukrer/savannahnode/vms/platformvm/stakeable"
"github.com/kukrer/savannahnode/vms/secp256k1fx"
)
// Version is the current default codec version
const Version = 0
// Codec does serialization and deserialization
var Codec codec.Manager
func init() {
c := linearcodec.NewDefault()
Codec = codec.NewDefaultManager()
// 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 := wrappers.Errs{}
errs.Add(
RegisterUnsignedTxsTypes(c),
Codec.RegisterCodec(Version, c),
)
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{}),
)
return errs.Err
}