mirror of
https://github.com/luxfi/sdk.git
synced 2026-10-30 15:19:23 +00:00
Lux Partners Limited is not the entity behind this work. Every place the old name stood — copyright lines, site footers, brand config, legal and compliance text — now names the company that actually holds it. lux.fund is the exception and is not renamed to match: that site belongs to Lux Assets Management LLC, a different company, and it says so. Two kinds of line were left for a person rather than rewritten. A dated news item recording that Lux Partners Limited was established in the Isle of Man is a historical fact, and renaming it would falsify the record. And a sentence asserting that the company is domiciled in the Isle of Man is a claim about a jurisdiction, not a name — an Inc or an LLC is not an Isle of Man company, so swapping the name there would assert something untrue. Co-authored-by: Hanzo Dev <[email protected]>
111 lines
2.4 KiB
Go
111 lines
2.4 KiB
Go
// Copyright (C) 2025, Lux Industries Inc All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package contract
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/luxfi/sdk/application"
|
|
"github.com/luxfi/sdk/flags"
|
|
"github.com/luxfi/sdk/key"
|
|
"github.com/luxfi/sdk/models"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
type PrivateKeyFlags struct {
|
|
privateKeyFlagName string
|
|
keyFlagName string
|
|
genesisKeyFlagName string
|
|
PrivateKey string
|
|
KeyName string
|
|
GenesisKey bool
|
|
}
|
|
|
|
const (
|
|
defaultPrivateKeyFlagName = "private-key"
|
|
defaultKeyFlagName = "key"
|
|
defaultGenesisKeyFlagName = "genesis-key"
|
|
)
|
|
|
|
func (pkf *PrivateKeyFlags) fillDefaultFlagNames() {
|
|
if pkf.privateKeyFlagName == "" {
|
|
pkf.privateKeyFlagName = defaultPrivateKeyFlagName
|
|
}
|
|
if pkf.keyFlagName == "" {
|
|
pkf.keyFlagName = defaultKeyFlagName
|
|
}
|
|
if pkf.genesisKeyFlagName == "" {
|
|
pkf.genesisKeyFlagName = defaultGenesisKeyFlagName
|
|
}
|
|
}
|
|
|
|
func (pkf *PrivateKeyFlags) SetFlagNames(
|
|
privateKeyFlagName string,
|
|
keyFlagName string,
|
|
genesisKeyFlagName string,
|
|
) {
|
|
pkf.privateKeyFlagName = privateKeyFlagName
|
|
pkf.keyFlagName = keyFlagName
|
|
pkf.genesisKeyFlagName = genesisKeyFlagName
|
|
}
|
|
|
|
func (pkf *PrivateKeyFlags) AddToCmd(
|
|
cmd *cobra.Command,
|
|
goal string,
|
|
) {
|
|
pkf.fillDefaultFlagNames()
|
|
cmd.Flags().StringVar(
|
|
&pkf.PrivateKey,
|
|
pkf.privateKeyFlagName,
|
|
"",
|
|
fmt.Sprintf("private key to use %s", goal),
|
|
)
|
|
cmd.Flags().StringVar(
|
|
&pkf.KeyName,
|
|
pkf.keyFlagName,
|
|
"",
|
|
fmt.Sprintf("CLI stored key to use %s", goal),
|
|
)
|
|
cmd.Flags().BoolVar(
|
|
&pkf.GenesisKey,
|
|
pkf.genesisKeyFlagName,
|
|
false,
|
|
fmt.Sprintf("use genesis allocated key %s", goal),
|
|
)
|
|
}
|
|
|
|
func (pkf *PrivateKeyFlags) GetPrivateKey(
|
|
app *application.Lux,
|
|
genesisPrivateKey string,
|
|
) (string, error) {
|
|
pkf.fillDefaultFlagNames()
|
|
if !flags.EnsureMutuallyExclusive([]bool{
|
|
pkf.PrivateKey != "",
|
|
pkf.KeyName != "",
|
|
pkf.GenesisKey,
|
|
}) {
|
|
return "", fmt.Errorf("%s, %s and %s are mutually exclusive flags",
|
|
pkf.privateKeyFlagName,
|
|
pkf.keyFlagName,
|
|
pkf.genesisKeyFlagName,
|
|
)
|
|
}
|
|
privateKey := pkf.PrivateKey
|
|
if pkf.KeyName != "" {
|
|
// Load the key to get the private key hex
|
|
network := models.NewLocalNetwork()
|
|
keyPath := app.GetKeyPath(pkf.KeyName)
|
|
k, err := key.LoadSoft(network.ID(), keyPath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
privateKey = k.PrivKeyHex()
|
|
}
|
|
if pkf.GenesisKey {
|
|
privateKey = genesisPrivateKey
|
|
}
|
|
return privateKey, nil
|
|
}
|