-
Notifications
You must be signed in to change notification settings - Fork 1
/
virtual_chain.go
68 lines (54 loc) · 1.2 KB
/
virtual_chain.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
package config
import (
"encoding/json"
"fmt"
"strconv"
"strings"
)
type VirtualChainId uint32
type VirtualChain struct {
Service
Id VirtualChainId
InternalHttpPort int // FIXME should be deprecated as vchain specific
}
type VirtualChainConfig struct {
VirtualChain *VirtualChain
Topology []*FederationNode
NodeAddress NodeAddress
KeyPairConfig []byte `json:"-"` // Prevents key leak via log
}
type Peer struct {
IP string
Port int
}
func GetVcidFromServiceName(serviceName string) int64 {
tokens := strings.Split(serviceName, "-")
if len(tokens) < 2 {
return -1
}
result, err := strconv.ParseInt(tokens[len(tokens)-1], 10, 0)
if err != nil {
return -1
}
return result
}
func (v *VirtualChain) GetContainerName() string {
return fmt.Sprintf("chain-%d", v.Id)
}
func (c *VirtualChain) GetSerializedConfig() []byte {
m := make(map[string]interface{})
for k, v := range c.Config {
m[k] = v
}
m["virtual-chain-id"] = c.Id
rawJSON, _ := json.Marshal(m)
return rawJSON
}
func (id VirtualChainId) String() string {
return strconv.Itoa(int(id))
}
type FederationNode struct {
Address string `json:"address"`
IP string `json:"ip"`
Port int `json:"port"`
}