/
core.go
49 lines (43 loc) · 966 Bytes
/
core.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
package config
import (
"fmt"
"github.com/hyperledger-labs/yui-relayer/core"
)
type CoreConfig struct {
config *Config
}
var _ core.ConfigI = (*CoreConfig)(nil)
func initCoreConfig(c *Config) {
config := &CoreConfig{
config: c,
}
core.SetCoreConfig(config)
}
func (c CoreConfig) UpdateConfigID(pathName string, chainID string, configID core.ConfigIDType, id string) error {
configPath, err := c.config.Paths.Get(pathName)
if err != nil {
return err
}
var pathEnd *core.PathEnd
if chainID == configPath.Src.ChainID {
pathEnd = configPath.Src
}
if chainID == configPath.Dst.ChainID {
pathEnd = configPath.Dst
}
if pathEnd == nil {
return fmt.Errorf("pathEnd is nil")
}
switch configID {
case core.ConfigIDClient:
pathEnd.ClientID = id
case core.ConfigIDConnection:
pathEnd.ConnectionID = id
case core.ConfigIDChannel:
pathEnd.ChannelID = id
}
if err := c.config.OverWriteConfig(); err != nil {
return err
}
return nil
}