Files
cli/pkg/vm/createCustom.go
2026-01-14 19:55:40 -08:00

58 lines
1.4 KiB
Go

// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package vm
import (
"os"
"github.com/luxfi/cli/pkg/application"
"github.com/luxfi/cli/pkg/ux"
"github.com/luxfi/sdk/models"
)
func CreateCustomChainConfig(app *application.Lux, chainName string, genesisPath, vmPath string) ([]byte, *models.Sidecar, error) {
ux.Logger.PrintToUser("creating custom VM net %s", chainName)
genesisBytes, err := loadCustomGenesis(app, genesisPath)
if err != nil {
return nil, &models.Sidecar{}, err
}
sc := &models.Sidecar{
Name: chainName,
VM: models.CustomVM,
Chain: chainName,
TokenName: "",
}
err = CopyCustomVM(app, chainName, vmPath)
return genesisBytes, sc, err
}
func loadCustomGenesis(app *application.Lux, genesisPath string) ([]byte, error) {
var err error
if genesisPath == "" {
genesisPath, err = app.Prompt.CaptureExistingFilepath("Enter path to custom genesis")
if err != nil {
return nil, err
}
}
genesisBytes, err := os.ReadFile(genesisPath) //nolint:gosec // G304: User-specified genesis file
return genesisBytes, err
}
func CopyCustomVM(app *application.Lux, chainName string, vmPath string) error {
var err error
if vmPath == "" {
vmPath, err = app.Prompt.CaptureExistingFilepath("Enter path to vm binary")
if err != nil {
return err
}
}
return app.CopyVMBinary(vmPath, chainName)
}