Files
zeekay 8f56009cc7 fix: deep audit - remove stubs, fix imports, clean dead code
Deep audit changes:
- Replace stub signature aggregator with real SDK warp implementation
- Remove dead pkg/lpm package (SDK lpmintegration used instead)
- Fix fs imports: use local utils.FileExists, DirExists, ExpandHome
- Fix secp256k1fx imports: use node/vms/secp256k1fx
- Fix platformvm imports: use node/vms/platformvm
- Fix e2e test TODOs: uncomment BootstrapValidators assertions
- Improve localnet stub implementations with real logic
- Fix node.go fs.FileExists reference

Note: Build requires GOWORK=off due to workspace dependency issues
2026-01-10 11:17:00 -08:00

98 lines
2.5 KiB
Go

// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package plugins
import (
"fmt"
"os/user"
"path/filepath"
"strings"
"github.com/luxfi/cli/pkg/application"
"github.com/luxfi/cli/pkg/binutils"
"github.com/luxfi/netrunner/utils"
"github.com/luxfi/sdk/models"
)
func SanitizePath(path string) (string, error) {
usr, err := user.Current()
if err != nil {
return "", err
}
homeDir := usr.HomeDir
if path == "~" {
// In case of "~", which won't be caught by the "else if"
path = homeDir
} else if strings.HasPrefix(path, "~/") {
path = filepath.Join(homeDir, path[2:])
}
return path, nil
}
// Downloads the chain's VM (if necessary) and copies it into the plugin directory
func CreatePlugin(app *application.Lux, chainName string, pluginDir string) (string, error) {
sc, err := app.LoadSidecar(chainName)
if err != nil {
return "", fmt.Errorf("failed to load sidecar: %w", err)
}
var vmSourcePath string
var vmDestPath string
if sc.ImportedFromLPM {
vmSourcePath = binutils.SetupLPMBin(app, sc.ImportedVMID)
vmDestPath = filepath.Join(pluginDir, sc.ImportedVMID)
} else {
// Not imported
chainVMID, err := utils.VMID(chainName)
if err != nil {
return "", fmt.Errorf("failed to create VM ID from %s: %w", chainName, err)
}
switch sc.VM {
case models.EVM:
vmSourcePath, err = binutils.SetupEVM(app, sc.VMVersion)
if err != nil {
return "", fmt.Errorf("failed to install evm: %w", err)
}
case models.CustomVM:
vmSourcePath = binutils.SetupCustomBin(app, chainName)
default:
return "", fmt.Errorf("unknown vm: %s", sc.VM)
}
vmDestPath = filepath.Join(pluginDir, chainVMID.String())
}
return vmDestPath, binutils.CopyFile(vmSourcePath, vmDestPath)
}
// Downloads the target VM (if necessary) and copies it into the plugin directory
func CreatePluginFromVersion(
app *application.Lux,
chainName string,
vm models.VMType,
version string,
vmid string,
pluginDir string,
) (string, error) {
var vmSourcePath string
var vmDestPath string
var err error
switch vm {
case models.EVM:
vmSourcePath, err = binutils.SetupEVM(app, version)
if err != nil {
return "", fmt.Errorf("failed to install evm: %w", err)
}
case models.CustomVM:
vmSourcePath = binutils.SetupCustomBin(app, chainName)
default:
return "", fmt.Errorf("unknown vm: %s", vm)
}
vmDestPath = filepath.Join(pluginDir, vmid)
return vmDestPath, binutils.CopyFile(vmSourcePath, vmDestPath)
}