From 70cba965bb97853fdfcfd62d5267917a5cf5a78d Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Wed, 24 Jul 2024 11:08:57 +0900 Subject: [PATCH] fix core.ConfigI to allow to update the "order" and "version" fields Signed-off-by: Masanori Yoshida --- config/core.go | 34 ++++++++++++++++++---------------- core/config.go | 22 ++++++++++++---------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/config/core.go b/config/core.go index 08055b99..047aae70 100644 --- a/config/core.go +++ b/config/core.go @@ -19,31 +19,33 @@ 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, key core.PathConfigKey, value 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 + + switch key { + case core.PathConfigClientID: + pathEnd.ClientID = value + case core.PathConfigConnectionID: + pathEnd.ConnectionID = value + case core.PathConfigChannelID: + pathEnd.ChannelID = value + case core.PathConfigOrder: + pathEnd.Order = value + case core.PathConfigVersion: + pathEnd.Version = value } - return nil + + return c.config.OverWriteConfig() } diff --git a/core/config.go b/core/config.go index ce1b8c9c..5c8d44fe 100644 --- a/core/config.go +++ b/core/config.go @@ -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, key PathConfigKey, value string) error } func SetCoreConfig(c ConfigI) { @@ -157,20 +159,20 @@ func SyncChainConfigFromEvents(pathName string, msgIDs []MsgID, chain *ProvableC for _, event := range msgRes.Events() { var id string - var configID ConfigIDType + var configID PathConfigKey switch event := event.(type) { case *EventGenerateClientIdentifier: - configID = ConfigIDClient + configID = PathConfigClientID id = event.ID case *EventGenerateConnectionIdentifier: - configID = ConfigIDConnection + configID = PathConfigConnectionID id = event.ID case *EventGenerateChannelIdentifier: - configID = ConfigIDChannel + configID = PathConfigChannelID id = event.ID } if id != "" { - if err := config.UpdateConfigID(pathName, chain.ChainID(), configID, id); err != nil { + if err := config.UpdatePathConfig(pathName, chain.ChainID(), configID, id); err != nil { return err } }