forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aliases.go
79 lines (71 loc) · 2.22 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
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package genesis
import (
"path"
"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/genesis"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"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{
path.Join(constants.ChainAliasPrefix, constants.PlatformChainID.String()): {
"P",
"platform",
path.Join(constants.ChainAliasPrefix, "P"),
path.Join(constants.ChainAliasPrefix, "platform"),
},
}
chainAliases := map[ids.ID][]string{
constants.PlatformChainID: {"P", "platform"},
}
genesis, err := genesis.Parse(genesisBytes) // TODO let's not re-create genesis to do aliasing
if err != nil {
return nil, nil, err
}
for _, chain := range genesis.Chains {
uChain := chain.Unsigned.(*txs.CreateChainTx)
chainID := chain.ID()
endpoint := path.Join(constants.ChainAliasPrefix, chainID.String())
switch uChain.VMID {
case constants.AVMID:
apiAliases[endpoint] = []string{
"X",
"avm",
path.Join(constants.ChainAliasPrefix, "X"),
path.Join(constants.ChainAliasPrefix, "avm"),
}
chainAliases[chainID] = GetXChainAliases()
case constants.EVMID:
apiAliases[endpoint] = []string{
"C",
"evm",
path.Join(constants.ChainAliasPrefix, "C"),
path.Join(constants.ChainAliasPrefix, "evm"),
}
chainAliases[chainID] = 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"},
}
}