-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a command to change DA with an existing rollapp (#451)
- Loading branch information
1 parent
09a18aa
commit 487f0c8
Showing
3 changed files
with
62 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package set | ||
|
||
import ( | ||
"fmt" | ||
"github.com/dymensionxyz/roller/cmd/consts" | ||
"github.com/dymensionxyz/roller/config" | ||
datalayer "github.com/dymensionxyz/roller/data_layer" | ||
"github.com/dymensionxyz/roller/sequencer" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func setDA(rlpCfg config.RollappConfig, value config.DAType) error { | ||
if value == rlpCfg.DA { | ||
return nil | ||
} | ||
supportedDas := []config.DAType{config.Celestia, config.Avail, config.Local} | ||
if !config.IsValidDAType(string(value)) { | ||
return fmt.Errorf("invalid DA type. Supported types are: %v", supportedDas) | ||
} | ||
return updateDaConfig(rlpCfg, value) | ||
} | ||
|
||
func updateDaConfig(rlpCfg config.RollappConfig, newDa config.DAType) error { | ||
if err := cleanDADir(rlpCfg); err != nil { | ||
return err | ||
} | ||
daManager := datalayer.NewDAManager(newDa, rlpCfg.Home) | ||
if err := daManager.InitializeLightNodeConfig(); err != nil { | ||
return err | ||
} | ||
rlpCfg.DA = newDa | ||
if err := sequencer.UpdateDymintDAConfig(rlpCfg); err != nil { | ||
return err | ||
} | ||
return config.WriteConfigToTOML(rlpCfg) | ||
} | ||
|
||
func cleanDADir(cfg config.RollappConfig) error { | ||
return os.RemoveAll(filepath.Join(cfg.Home, consts.ConfigDirName.DALightNode)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters