-
Notifications
You must be signed in to change notification settings - Fork 11
feat(rollkit): add rollkit init #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b64a523
feat(rollkit): add rollkit init
julienrbrt abbaf66
updates
julienrbrt 07d927b
Merge branch 'main' into julien/rollkit-init
julienrbrt 42281a1
updates
julienrbrt 0f4a070
updates
julienrbrt 3f6c864
add integration test
julienrbrt 551d380
formatting
julienrbrt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,122 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "github.com/cometbft/cometbft/crypto" | ||
| cmtjson "github.com/cometbft/cometbft/libs/json" | ||
| cmprivval "github.com/cometbft/cometbft/privval" | ||
| cmttypes "github.com/cometbft/cometbft/types" | ||
| genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" | ||
| "github.com/pkg/errors" | ||
| "github.com/spf13/cobra" | ||
|
|
||
| configchain "github.com/ignite/cli/v28/ignite/config/chain" | ||
| "github.com/ignite/cli/v28/ignite/pkg/cliui" | ||
| "github.com/ignite/cli/v28/ignite/pkg/cliui/colors" | ||
| "github.com/ignite/cli/v28/ignite/services/chain" | ||
| ) | ||
|
|
||
| func NewRollkitInit() *cobra.Command { | ||
| c := &cobra.Command{ | ||
| Use: "init", | ||
| Short: "Init rollkit support", | ||
| Args: cobra.NoArgs, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| session := cliui.New() | ||
| defer session.End() | ||
|
|
||
| appPath, err := cmd.Flags().GetString(flagPath) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| absPath, err := filepath.Abs(appPath) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| rc, err := chain.New(absPath, chain.CollectEvents(session.EventBus())) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if localDa, err := cmd.Flags().GetBool(flagLocalDa); err == nil && localDa { | ||
| igniteConfig, err := rc.Config() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| igniteConfig.Validators[0].Bonded = "1000000000stake" | ||
julienrbrt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for i, account := range igniteConfig.Accounts { | ||
| if account.Name == igniteConfig.Validators[0].Name { | ||
| igniteConfig.Accounts[i].Coins = []string{"10000000000000000000000000stake"} | ||
| } | ||
| } | ||
|
|
||
| if err := configchain.Save(*igniteConfig, rc.ConfigPath()); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| if err := rc.Init(cmd.Context(), chain.InitArgsAll); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| home, err := rc.Home() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // modify genesis (add sequencer) | ||
| genesisPath, err := rc.GenesisPath() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| genesis, err := genutiltypes.AppGenesisFromFile(genesisPath) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| pubKey, err := getPubKey(home) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| genesis.Consensus.Validators = []cmttypes.GenesisValidator{ | ||
| { | ||
| Name: "Rollkit Sequencer", | ||
| Address: pubKey.Address(), | ||
| PubKey: pubKey, | ||
| Power: 1000, | ||
| }, | ||
| } | ||
|
|
||
| if err := genesis.SaveAs(genesisPath); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return session.Printf("🗃 Initialized. Checkout your rollkit chain's home (data) directory: %s\n", colors.Info(home)) | ||
| }, | ||
| } | ||
|
|
||
| c.Flags().StringP(flagPath, "p", ".", "path of the app") | ||
| c.Flags().BoolP(flagLocalDa, "l", false, "use local-da (creates the expected genesis account for local-da)") | ||
|
|
||
| return c | ||
| } | ||
|
|
||
| // getPubKey returns the validator public key. | ||
| func getPubKey(chainHome string) (crypto.PubKey, error) { | ||
| keyFilePath := filepath.Join(chainHome, "config", "priv_validator_key.json") | ||
julienrbrt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| keyJSONBytes, err := os.ReadFile(keyFilePath) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| var pvKey cmprivval.FilePVKey | ||
| if err = cmtjson.Unmarshal(keyJSONBytes, &pvKey); err != nil { | ||
| return nil, errors.Errorf("error reading PrivValidator key from %v: %s", keyFilePath, err) | ||
| } | ||
| return pvKey.PubKey, nil | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.