-
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 commands to export and update sequencer metadata (#847)
- Loading branch information
1 parent
da508b9
commit 3febe76
Showing
9 changed files
with
363 additions
and
19 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
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,126 @@ | ||
package export | ||
|
||
import ( | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
|
||
initconfig "github.com/dymensionxyz/roller/cmd/config/init" | ||
"github.com/dymensionxyz/roller/cmd/consts" | ||
"github.com/dymensionxyz/roller/cmd/utils" | ||
globalutils "github.com/dymensionxyz/roller/utils" | ||
"github.com/dymensionxyz/roller/utils/config/tomlconfig" | ||
"github.com/dymensionxyz/roller/utils/errorhandling" | ||
"github.com/dymensionxyz/roller/utils/sequencer" | ||
sequencerutils "github.com/dymensionxyz/roller/utils/sequencer" | ||
"github.com/dymensionxyz/roller/utils/structs" | ||
) | ||
|
||
func Cmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "export", | ||
Short: "Exports the current sequencer metadata into a .json file", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := initconfig.AddFlags(cmd) | ||
if err != nil { | ||
pterm.Error.Println("failed to add flags") | ||
return | ||
} | ||
|
||
home, err := globalutils.ExpandHomePath(cmd.Flag(utils.FlagNames.Home).Value.String()) | ||
if err != nil { | ||
pterm.Error.Println("failed to expand home directory") | ||
return | ||
} | ||
|
||
rollerData, err := tomlconfig.LoadRollerConfig(home) | ||
if err != nil { | ||
pterm.Error.Println("failed to load roller config file", err) | ||
return | ||
} | ||
|
||
// redundant | ||
hd, err := tomlconfig.LoadHubData(home) | ||
if err != nil { | ||
pterm.Error.Println("failed to load hub data from roller.toml") | ||
} | ||
|
||
rollappConfig, err := tomlconfig.LoadRollappMetadataFromChain( | ||
home, | ||
rollerData.RollappID, | ||
&hd, | ||
) | ||
errorhandling.PrettifyErrorIfExists(err) | ||
|
||
hubSeqKC := utils.KeyConfig{ | ||
Dir: filepath.Join(rollappConfig.Home, consts.ConfigDirName.HubKeys), | ||
ID: consts.KeysIds.HubSequencer, | ||
ChainBinary: consts.Executables.Dymension, | ||
Type: consts.SDK_ROLLAPP, | ||
} | ||
|
||
seqAddrInfo, err := utils.GetAddressInfoBinary(hubSeqKC, hubSeqKC.ChainBinary) | ||
if err != nil { | ||
pterm.Error.Println("failed to get address info: ", err) | ||
return | ||
} | ||
seqAddrInfo.Address = strings.TrimSpace(seqAddrInfo.Address) | ||
|
||
seq, err := sequencerutils.GetRegisteredSequencers(rollappConfig.RollappID, hd) | ||
if err != nil { | ||
pterm.Error.Println("failed to retrieve registered sequencers: ", err) | ||
} | ||
|
||
ok := sequencer.IsRegisteredAsSequencer(seq.Sequencers, seqAddrInfo.Address) | ||
if !ok { | ||
pterm.Error.Printf( | ||
"%s is not registered as a sequencer for %s\n", | ||
seqAddrInfo.Address, | ||
rollappConfig.RollappID, | ||
) | ||
return | ||
} | ||
|
||
pterm.Info.Printf( | ||
"%s is registered as a sequencer for %s\n", | ||
seqAddrInfo.Address, | ||
rollappConfig.RollappID, | ||
) | ||
pterm.Info.Println( | ||
"retrieving existing metadata", | ||
) | ||
|
||
metadata, err := sequencer.GetMetadata(seqAddrInfo.Address, hd) | ||
if err != nil { | ||
pterm.Error.Println("failed to retrieve metadata, ", err) | ||
return | ||
} | ||
|
||
metadataFilePath := filepath.Join( | ||
home, consts.ConfigDirName.Rollapp, "init", | ||
"sequencer-metadata.json", | ||
) | ||
err = structs.ExportStructToFile( | ||
*metadata, | ||
metadataFilePath, | ||
) | ||
if err != nil { | ||
pterm.Error.Println("failed to export metadata", err) | ||
return | ||
} | ||
|
||
pterm.Info.Printf("metadata successfully exported to %s\n", metadataFilePath) | ||
pterm.Info.Println("next steps:") | ||
pterm.Info.Println("update the metadata file") | ||
pterm.Info.Printf( | ||
"run %s to submit a transaction to update the sequencer metadata\n", | ||
pterm.DefaultBasicText.WithStyle(pterm.FgYellow.ToStyle()). | ||
Sprintf("roller rollapp sequencer metadata update"), | ||
) | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
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,20 @@ | ||
package metadata | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/dymensionxyz/roller/cmd/rollapp/sequencer/metadata/export" | ||
"github.com/dymensionxyz/roller/cmd/rollapp/sequencer/metadata/update" | ||
) | ||
|
||
func Cmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "metadata [command]", | ||
Short: "Commands to manage sequencer metadata", | ||
} | ||
|
||
cmd.AddCommand(export.Cmd()) | ||
cmd.AddCommand(update.Cmd()) | ||
|
||
return cmd | ||
} |
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,82 @@ | ||
package update | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"path/filepath" | ||
|
||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
|
||
initconfig "github.com/dymensionxyz/roller/cmd/config/init" | ||
"github.com/dymensionxyz/roller/cmd/consts" | ||
"github.com/dymensionxyz/roller/cmd/utils" | ||
globalutils "github.com/dymensionxyz/roller/utils" | ||
"github.com/dymensionxyz/roller/utils/bash" | ||
"github.com/dymensionxyz/roller/utils/config/tomlconfig" | ||
"github.com/dymensionxyz/roller/utils/tx" | ||
) | ||
|
||
func Cmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "update [metadata-file.json]", | ||
Short: "Update the sequencer metadata", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := initconfig.AddFlags(cmd) | ||
if err != nil { | ||
pterm.Error.Println("failed to add flags") | ||
return | ||
} | ||
|
||
home, err := globalutils.ExpandHomePath(cmd.Flag(utils.FlagNames.Home).Value.String()) | ||
if err != nil { | ||
pterm.Error.Println("failed to expand home directory") | ||
return | ||
} | ||
|
||
rollerData, err := tomlconfig.LoadRollerConfig(home) | ||
if err != nil { | ||
pterm.Error.Println("failed to load roller config file", err) | ||
return | ||
} | ||
|
||
metadataFilePath := filepath.Join( | ||
home, consts.ConfigDirName.Rollapp, "init", | ||
"sequencer-metadata.json", | ||
) | ||
|
||
updateSeqCmd := exec.Command( | ||
consts.Executables.Dymension, | ||
"tx", | ||
"sequencer", | ||
"update-sequencer", | ||
rollerData.RollappID, | ||
metadataFilePath, | ||
"--from", | ||
consts.KeysIds.HubSequencer, | ||
"--keyring-backend", | ||
"test", | ||
"--fees", | ||
fmt.Sprintf("%d%s", consts.DefaultFee, consts.Denoms.Hub), | ||
"--gas-adjustment", | ||
"1.3", | ||
"--keyring-dir", | ||
filepath.Join(utils.GetRollerRootDir(), consts.ConfigDirName.HubKeys), | ||
) | ||
|
||
txHash, err := bash.ExecCommandWithInput(updateSeqCmd) | ||
if err != nil { | ||
pterm.Error.Println("failed to update sequencer metadata", err) | ||
return | ||
} | ||
|
||
err = tx.MonitorTransaction(rollerData.HubData.RPC_URL, txHash) | ||
if err != nil { | ||
pterm.Error.Println("transaction failed", err) | ||
return | ||
} | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
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,18 @@ | ||
package sequencer | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/dymensionxyz/roller/cmd/rollapp/sequencer/metadata" | ||
) | ||
|
||
func Cmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "sequencer [command]", | ||
Short: "Commands to manage sequencer instance", | ||
} | ||
|
||
cmd.AddCommand(metadata.Cmd()) | ||
|
||
return cmd | ||
} |
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
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
Oops, something went wrong.