Files
cli/pkg/vm/createEVMWrapper.go
zeekay 8fe5c15af6 fix(lint): resolve all staticcheck issues
- Apply De Morgan's law in validations and helpers (QF1001)
- Convert if-else chains to tagged switch statements (QF1002/QF1003)
- Replace deprecated core.GenesisAlloc/GenesisAccount with types package
- Refactor atMostOne functions to use cleaner count-based approach
- Add missing validator choice and management constants
2026-01-02 05:29:31 -08:00

89 lines
2.4 KiB
Go

// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package vm
import (
"encoding/json"
"math/big"
"strings"
"github.com/luxfi/cli/pkg/application"
"github.com/luxfi/cli/pkg/key"
"github.com/luxfi/cli/pkg/warp"
"github.com/luxfi/geth/common"
"github.com/luxfi/geth/core/types"
)
// CreateEVMGenesisWithParams creates EVM genesis with extended parameters
func CreateEVMGenesisWithParams(
app *application.Lux,
params EVMGenesisParams,
warpInfo *warp.WarpInfo,
addWarpRegistryToGenesis bool,
proxyContractOwner string,
rewardBasisPoints uint64,
useACP99 bool,
) ([]byte, error) {
// Get chain ID from params
chainIDBig := new(big.Int).SetUint64(params.ChainID)
// Create allocations with prefunded addresses
allocations := make(types.GenesisAlloc)
// Add allocation for any prefunded addresses from params
for _, alloc := range params.Allocations {
addr := common.HexToAddress(alloc.Address)
balance, ok := new(big.Int).SetString(alloc.Balance, 10)
if !ok {
// Try hex format without 0x prefix
balanceStr := strings.TrimPrefix(alloc.Balance, "0x")
balance, ok = new(big.Int).SetString(balanceStr, 16)
if !ok {
balance = new(big.Int).SetUint64(0)
}
}
allocations[addr] = types.Account{
Balance: balance,
}
}
// Add default allocation using local key if no allocations provided
if len(allocations) == 0 {
// Use local key for default allocation (generated per machine, or from env vars)
const localNetworkID = 12345
localKey, err := key.GetOrCreateLocalKey(localNetworkID)
if err == nil {
localAddr := common.HexToAddress(localKey.C())
balance := new(big.Int)
balance.SetString("1000000000000000000000000000", 10) // 1 billion with 18 decimals
allocations[localAddr] = types.Account{
Balance: balance,
}
}
}
// Add warp prefunded address if warpInfo is available
if warpInfo != nil && warpInfo.FundedAddress != "" {
warpAddr := common.HexToAddress(warpInfo.FundedAddress)
if warpInfo.FundedBalance != nil {
allocations[warpAddr] = types.Account{
Balance: warpInfo.FundedBalance,
}
}
}
timestamps := make(map[string]uint64)
// Create genesis map
genesisMap := CreateEVMGenesis(chainIDBig, allocations, timestamps)
// Serialize to JSON
genesisBytes, err := json.MarshalIndent(genesisMap, "", " ")
if err != nil {
return nil, err
}
return genesisBytes, nil
}