-
Notifications
You must be signed in to change notification settings - Fork 671
/
aliases.go
67 lines (60 loc) · 2.17 KB
/
aliases.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
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package genesis
import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/vms/nftfx"
"github.com/ava-labs/avalanchego/vms/platformvm"
"github.com/ava-labs/avalanchego/vms/propertyfx"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)
// Aliases returns the default aliases based on the network ID
func Aliases(genesisBytes []byte) (map[string][]string, map[ids.ID][]string, error) {
apiAliases := map[string][]string{
constants.ChainAliasPrefix + constants.PlatformChainID.String(): {
"P",
"platform",
constants.ChainAliasPrefix + "P",
constants.ChainAliasPrefix + "platform",
},
}
chainAliases := map[ids.ID][]string{
constants.PlatformChainID: {"P", "platform"},
}
genesis := &platformvm.Genesis{} // TODO let's not re-create genesis to do aliasing
if _, err := platformvm.GenesisCodec.Unmarshal(genesisBytes, genesis); err != nil {
return nil, nil, err
}
if err := genesis.Initialize(); err != nil {
return nil, nil, err
}
for _, chain := range genesis.Chains {
uChain := chain.UnsignedTx.(*platformvm.UnsignedCreateChainTx)
switch uChain.VMID {
case constants.AVMID:
apiAliases[constants.ChainAliasPrefix+chain.ID().String()] = []string{"X", "avm", constants.ChainAliasPrefix + "X", constants.ChainAliasPrefix + "avm"}
chainAliases[chain.ID()] = GetXChainAliases()
case constants.EVMID:
apiAliases[constants.ChainAliasPrefix+chain.ID().String()] = []string{"C", "evm", constants.ChainAliasPrefix + "C", constants.ChainAliasPrefix + "evm"}
chainAliases[chain.ID()] = GetCChainAliases()
}
}
return apiAliases, chainAliases, nil
}
func GetCChainAliases() []string {
return []string{"C", "evm"}
}
func GetXChainAliases() []string {
return []string{"X", "avm"}
}
func GetVMAliases() map[ids.ID][]string {
return map[ids.ID][]string{
constants.PlatformVMID: {"platform"},
constants.AVMID: {"avm"},
constants.EVMID: {"evm"},
secp256k1fx.ID: {"secp256k1fx"},
nftfx.ID: {"nftfx"},
propertyfx.ID: {"propertyfx"},
}
}