-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: build evmos and init genesis commands
- Loading branch information
Showing
12 changed files
with
316 additions
and
9 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,78 @@ | ||
package playground | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/hanchon/hanchond/playground/filesmanager" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const LocalVesrsion = "local" | ||
|
||
// buildEvmosCmd represents the buildEvmos command | ||
var buildEvmosCmd = &cobra.Command{ | ||
Use: "build-evmos", | ||
Short: "Build an specific version of Evmos (hanchond playground build-evmos v18.0.0), it also supports local repositories (hanchond playground build-evmos --path /home/hanchon/evmos)", | ||
Long: `It downloads, builds and clean up temp files for any Evmos tag. Using the --path flag will build you local repo`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
_ = filesmanager.SetHomeFolderFromCobraFlags(cmd) | ||
|
||
path, err := cmd.Flags().GetString("path") | ||
// Local build | ||
if err == nil && path != "" { | ||
version := LocalVesrsion | ||
if path[len(path)-1] == '/' { | ||
path = path[0 : len(path)-2] | ||
} | ||
fmt.Println("Building evmos...") | ||
if err := filesmanager.BuildEvmos(path); err != nil { | ||
fmt.Println("error building evmos:", err.Error()) | ||
os.Exit(1) | ||
} | ||
fmt.Println("Moving built binary...") | ||
if err := filesmanager.CopyFile(path+"/build/evmosd", filesmanager.GetEvmosdPath(version)); err != nil { | ||
fmt.Println("could not move the built binary:", err.Error()) | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
} | ||
|
||
// Clone from github | ||
if len(args) == 0 { | ||
fmt.Println("version is missing. Usage: hanchond playground build-evmosd v18.1.0") | ||
os.Exit(1) | ||
} | ||
version := args[0] | ||
if err := filesmanager.CreateTempFolder(version); err != nil { | ||
fmt.Println("could not create temp folder:" + err.Error()) | ||
os.Exit(1) | ||
} | ||
fmt.Println("Cloning evmos version:", version) | ||
if err := filesmanager.GitCloneEvmosBranch(version); err != nil { | ||
fmt.Println("could not clone the evmos version: ", err) | ||
os.Exit(1) | ||
} | ||
fmt.Println("Building evmos...") | ||
if err := filesmanager.BuildEvmosVersion(version); err != nil { | ||
fmt.Println("error building evmos:", err) | ||
os.Exit(1) | ||
} | ||
fmt.Println("Moving built binary...") | ||
if err := filesmanager.SaveEvmosBuiltVersion(version); err != nil { | ||
fmt.Println("could not move the built binary:", err.Error()) | ||
os.Exit(1) | ||
} | ||
fmt.Println("Cleaning up...") | ||
if err := filesmanager.CleanUpTempFolder(); err != nil { | ||
fmt.Println("could not remove temp folder", err.Error()) | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
}, | ||
} | ||
|
||
func init() { | ||
PlaygroundCmd.AddCommand(buildEvmosCmd) | ||
buildEvmosCmd.Flags().StringP("path", "p", "", "Path to you local clone of Evmos") | ||
} |
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,128 @@ | ||
package playground | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/hanchon/hanchond/playground/database" | ||
"github.com/hanchon/hanchond/playground/evmos" | ||
"github.com/hanchon/hanchond/playground/filesmanager" | ||
"github.com/hanchon/hanchond/playground/sql" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func initDB(dbPath string) (*database.Queries, error) { | ||
db, err := sql.InitDatabase(context.Background(), dbPath+"/playground.db") | ||
if err != nil { | ||
return nil, err | ||
} | ||
return database.New(db), nil | ||
} | ||
|
||
// initGenesisCmd represents the initGenesis command | ||
var initGenesisCmd = &cobra.Command{ | ||
Use: "init-genesis", | ||
Args: cobra.ExactArgs(1), | ||
Short: "Init the genesis file for a new chain", | ||
Long: `Set up the data and config folder for the new chain`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
home := filesmanager.SetHomeFolderFromCobraFlags(cmd) | ||
queries, err := initDB(home) | ||
if err != nil { | ||
fmt.Println("could not init database", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
version, err := cmd.Flags().GetString("version") | ||
if err != nil { | ||
fmt.Println("version flag was not set") | ||
os.Exit(1) | ||
} | ||
|
||
chainid, err := strconv.ParseInt(args[0], 10, 64) | ||
if err != nil { | ||
fmt.Println("invalid chain id, it must be integer", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
if !filesmanager.DoesEvmosdPathExist(version) { | ||
fmt.Println("the evmos version was not found in the built folder", version) | ||
os.Exit(1) | ||
|
||
} | ||
|
||
if filesmanager.IsNodeHomeFolderInitialized(chainid) { | ||
fmt.Println("the home folder for this node was already created") | ||
os.Exit(1) | ||
} | ||
|
||
path := filesmanager.GetNodeHomeFolder(chainid) | ||
chainID := fmt.Sprintf("evmos_9001-%d", chainid) | ||
|
||
e := evmos.NewEvmos(version, path, chainID, fmt.Sprintf("mykey%d", chainid)) | ||
if err := e.InitGenesis(); err != nil { | ||
fmt.Println("could not init the genesis file", err.Error()) | ||
os.Exit(1) | ||
} | ||
if err := e.SetPorts(); err != nil { | ||
fmt.Println("could not set the ports", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
row, err := queries.InsertChain(context.Background(), database.InsertChainParams{ | ||
Name: fmt.Sprintf("chain%d", chainid), | ||
ChainID: e.ChainID, | ||
BinaryVersion: e.Version, | ||
}) | ||
if err != nil { | ||
fmt.Println("could not insert chain. ", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
nodeID, err := queries.InsertNode(context.Background(), database.InsertNodeParams{ | ||
ChainID: row.ID, | ||
ConfigFolder: path, | ||
Moniker: e.Moniker, | ||
ValidatorKey: e.ValMnemonic, | ||
ValidatorKeyName: e.ValKeyName, | ||
BinaryVersion: e.Version, | ||
ProcessID: 0, | ||
IsValidator: 1, | ||
IsArchive: 0, | ||
IsRunning: 0, | ||
}) | ||
if err != nil { | ||
fmt.Println("could not insert node", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
err = queries.InsertPorts(context.Background(), database.InsertPortsParams{ | ||
NodeID: nodeID, | ||
P1317: int64(e.Ports.P1317), | ||
P8080: int64(e.Ports.P8080), | ||
P9090: int64(e.Ports.P9090), | ||
P9091: int64(e.Ports.P9091), | ||
P8545: int64(e.Ports.P8545), | ||
P8546: int64(e.Ports.P8546), | ||
P6065: int64(e.Ports.P6065), | ||
P26658: int64(e.Ports.P26658), | ||
P26657: int64(e.Ports.P26657), | ||
P6060: int64(e.Ports.P6060), | ||
P26656: int64(e.Ports.P26656), | ||
P26660: int64(e.Ports.P26660), | ||
}) | ||
if err != nil { | ||
fmt.Println("could not insert ports", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println("Node added with id:", nodeID) | ||
}, | ||
} | ||
|
||
func init() { | ||
PlaygroundCmd.AddCommand(initGenesisCmd) | ||
initGenesisCmd.Flags().StringP("version", "v", "local", "Version of the Evmos node that you want to use, defaults to local. Tag names are supported.") | ||
} |
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,28 @@ | ||
# Build Evmos | ||
|
||
To run a network, you first need to chain binary. The command `build-evmos` allows you to build from tags | ||
|
||
## Build from Github tags | ||
|
||
Passing the version tag will automatically download the Github repo, build the binary and move the built binary to the playground data folder. | ||
|
||
```sh | ||
hanchond playground build-evmos v18.1.0 | ||
Cloning evmos version: v18.1.0 | ||
Building evmos... | ||
Moving built binary... | ||
``` | ||
|
||
## Build from a local repository | ||
|
||
If you pass the `--path` flag, it will build your local Evmos and tag it for internal usage as `local` | ||
|
||
```sh | ||
hanchond playground build-evmos --path /Users/hanchon/devel/evmos/evmos | ||
Building evmos... | ||
Moving built binary.. | ||
``` | ||
|
||
:::info | ||
Make sure that you are using the `local` version while interacting with the playground to use the Evmos built with the `--path` flag | ||
::: |
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 @@ | ||
# Init Genesis | ||
|
||
Before starting the chain, a genesis file needs to be set up. | ||
|
||
## Set up the genesis and config files | ||
|
||
Running the `init-genesis` command will set up the genesis file and update the configuration files so the ports do not conflict with the rest of your network. | ||
|
||
The ID argument is required, it must be an integer and will represent your chain. | ||
|
||
```sh | ||
hanchond playground init-genesis 1 --version local | ||
Node added with id: 1 | ||
``` | ||
|
||
:::info | ||
By default the `--version` flag will be `local`, it can be overwritten with any of the versions that were previously built | ||
::: |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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.