Skip to content

Commit

Permalink
fix core.ConfigI to allow to update the "order" and "version" fields
Browse files Browse the repository at this point in the history
Signed-off-by: Masanori Yoshida <[email protected]>
  • Loading branch information
siburu committed Jul 25, 2024
1 parent 68f0bee commit 6d53f43
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
38 changes: 22 additions & 16 deletions config/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,37 @@ func initCoreConfig(c *Config) {
core.SetCoreConfig(config)
}

func (c CoreConfig) UpdateConfigID(pathName string, chainID string, configID core.ConfigIDType, id string) error {
func (c CoreConfig) UpdatePathConfig(pathName string, chainID string, kv map[core.PathConfigKey]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 {
} else if chainID == configPath.Dst.ChainID {
pathEnd = configPath.Dst
}
if pathEnd == nil {
} else {
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

for k, v := range kv {
switch k {
case core.PathConfigClientID:
pathEnd.ClientID = v
case core.PathConfigConnectionID:
pathEnd.ConnectionID = v
case core.PathConfigChannelID:
pathEnd.ChannelID = v
case core.PathConfigOrder:
pathEnd.Order = v
case core.PathConfigVersion:
pathEnd.Version = v
default:
panic(fmt.Sprintf("unexpected path config key: %s", k))
}
}
return nil

return c.config.OverWriteConfig()
}
34 changes: 17 additions & 17 deletions core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ import (

var config ConfigI

type ConfigIDType string
type PathConfigKey string

const (
ConfigIDClient ConfigIDType = "client"
ConfigIDConnection ConfigIDType = "connection"
ConfigIDChannel ConfigIDType = "channel"
PathConfigClientID PathConfigKey = "client-id"
PathConfigConnectionID PathConfigKey = "connection-id"
PathConfigChannelID PathConfigKey = "channel-id"
PathConfigOrder PathConfigKey = "order"
PathConfigVersion PathConfigKey = "version"
)

type ConfigI interface {
UpdateConfigID(pathName string, chainID string, configID ConfigIDType, id string) error
UpdatePathConfig(pathName string, chainID string, kv map[PathConfigKey]string) error
}

func SetCoreConfig(c ConfigI) {
Expand Down Expand Up @@ -156,23 +158,21 @@ func SyncChainConfigFromEvents(pathName string, msgIDs []MsgID, chain *ProvableC
}

for _, event := range msgRes.Events() {
var id string
var configID ConfigIDType
kv := make(map[PathConfigKey]string)

switch event := event.(type) {
case *EventGenerateClientIdentifier:
configID = ConfigIDClient
id = event.ID
kv[PathConfigClientID] = event.ID
case *EventGenerateConnectionIdentifier:
configID = ConfigIDConnection
id = event.ID
kv[PathConfigConnectionID] = event.ID
case *EventGenerateChannelIdentifier:
configID = ConfigIDChannel
id = event.ID
kv[PathConfigChannelID] = event.ID
default:
continue
}
if id != "" {
if err := config.UpdateConfigID(pathName, chain.ChainID(), configID, id); err != nil {
return err
}

if err := config.UpdatePathConfig(pathName, chain.ChainID(), kv); err != nil {
return err
}
}
}
Expand Down

0 comments on commit 6d53f43

Please sign in to comment.