-
Notifications
You must be signed in to change notification settings - Fork 2
/
hypersdkVryxChain.go
58 lines (52 loc) · 1.57 KB
/
hypersdkVryxChain.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
// Copyright (C) 2024, AllianceBlock. All rights reserved.
// See the file LICENSE for licensing terms.
package cmd
import (
"fmt"
"os"
"github.com/ava-labs/avalanchego/ids"
"gopkg.in/yaml.v2"
)
type ClusterInfo struct {
ChainID string `yaml:"CHAIN_ID"` // ids.ID requires "first and last characters to be quotes"
SubnetID string `yaml:"SUBNET_ID"`
APIs []struct {
CloudID string `yaml:"CLOUD_ID"`
IP string `yaml:"IP"`
Region string `yaml:"REGION"`
} `yaml:"API"`
Validators []struct {
CloudID string `yaml:"CLOUD_ID"`
IP string `yaml:"IP"`
Region string `yaml:"REGION"`
NodeID string `yaml:"NODE_ID"`
} `yaml:"VALIDATOR"`
}
func ReadCLIFile(cliPath string) (ids.ID, map[string]string, error) {
// Load yaml file
yamlFile, err := os.ReadFile(cliPath)
if err != nil {
return ids.Empty, nil, err
}
var yamlContents ClusterInfo
if err := yaml.Unmarshal(yamlFile, &yamlContents); err != nil {
return ids.Empty, nil, fmt.Errorf("%w: unable to unmarshal YAML", err)
}
chainID, err := ids.FromString(yamlContents.ChainID)
if err != nil {
return ids.Empty, nil, err
}
// Load nodes
nodes := make(map[string]string)
for i, api := range yamlContents.APIs {
name := fmt.Sprintf("%s-%d (%s)", "API", i, api.Region)
uri := fmt.Sprintf("http://%s:9650/ext/bc/%s", api.IP, chainID)
nodes[name] = uri
}
for i, validator := range yamlContents.Validators {
name := fmt.Sprintf("%s-%d (%s)", "Validator", i, validator.Region)
uri := fmt.Sprintf("http://%s:9650/ext/bc/%s", validator.IP, chainID)
nodes[name] = uri
}
return chainID, nodes, nil
}