mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
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
76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package lpmintegration
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/url"
|
|
"path"
|
|
"strings"
|
|
)
|
|
|
|
func removeSlashes(str string) string {
|
|
return strings.TrimSuffix(strings.TrimPrefix(str, "/"), "/")
|
|
}
|
|
|
|
func getGitOrg(gitURL *url.URL) (string, error) {
|
|
org, repo := path.Split(gitURL.Path)
|
|
|
|
org = removeSlashes(org)
|
|
repo = removeSlashes(repo)
|
|
|
|
if org == "" || repo == "" {
|
|
return "", errors.New("invalid url format, unable to find org: " + gitURL.Path)
|
|
}
|
|
|
|
return org, nil
|
|
}
|
|
|
|
func getGitRepo(gitURL *url.URL) (string, error) {
|
|
org, repo := path.Split(gitURL.Path)
|
|
|
|
org = removeSlashes(org)
|
|
repo = removeSlashes(repo)
|
|
|
|
if org == "" || repo == "" {
|
|
return "", errors.New("invalid url format, unable to find repo name: " + gitURL.Path)
|
|
}
|
|
|
|
return strings.TrimSuffix(repo, gitExtension), nil
|
|
}
|
|
|
|
func getAlias(url *url.URL) (string, error) {
|
|
org, err := getGitOrg(url)
|
|
if err != nil {
|
|
return "", fmt.Errorf("unable to create alias: %w", err)
|
|
}
|
|
|
|
repo, err := getGitRepo(url)
|
|
if err != nil {
|
|
return "", fmt.Errorf("unable to create alias: %w", err)
|
|
}
|
|
|
|
return makeAlias(org, repo), nil
|
|
}
|
|
|
|
func makeAlias(org, repo string) string {
|
|
return org + "/" + repo
|
|
}
|
|
|
|
// MakeKey creates an LPM key from an alias and chain name.
|
|
func MakeKey(alias, chain string) string {
|
|
return alias + ":" + chain
|
|
}
|
|
|
|
func splitKey(chainKey string) (string, string, error) {
|
|
splitChain := strings.Split(chainKey, ":")
|
|
if len(splitChain) != 2 {
|
|
return "", "", fmt.Errorf("invalid chain key: %s", chainKey)
|
|
}
|
|
repo := splitChain[0]
|
|
chainName := splitChain[1]
|
|
return repo, chainName, nil
|
|
}
|