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]>
116 lines
3.1 KiB
Go
116 lines
3.1 KiB
Go
// Copyright (C) 2020-2025, Lux Industries Inc All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package sdk
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"math/big"
|
|
|
|
log "github.com/luxfi/log"
|
|
"github.com/luxfi/sdk/blockchain"
|
|
"github.com/luxfi/sdk/config"
|
|
"github.com/luxfi/sdk/network"
|
|
)
|
|
|
|
// LuxSDK is the main SDK interface providing comprehensive blockchain development capabilities
|
|
type LuxSDK struct {
|
|
networkManager *network.NetworkManager
|
|
blockchainBuilder *blockchain.Builder
|
|
config *config.Config
|
|
logger log.Logger
|
|
}
|
|
|
|
// New creates a new instance of the Lux SDK
|
|
func New(cfg *config.Config) (*LuxSDK, error) {
|
|
if cfg == nil {
|
|
cfg = config.Default()
|
|
}
|
|
|
|
// Create logger using lux log package
|
|
// Use the global logger with SDK context
|
|
logger := log.New("sdk")
|
|
|
|
// Initialize network manager
|
|
networkManager, err := network.NewNetworkManager(cfg.Network, logger)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create network manager: %w", err)
|
|
}
|
|
|
|
// Initialize blockchain builder
|
|
blockchainBuilder := blockchain.NewBuilder(logger)
|
|
|
|
return &LuxSDK{
|
|
networkManager: networkManager,
|
|
blockchainBuilder: blockchainBuilder,
|
|
config: cfg,
|
|
logger: logger,
|
|
}, nil
|
|
}
|
|
|
|
// Networks returns the network manager for network operations
|
|
func (sdk *LuxSDK) Networks() *network.NetworkManager {
|
|
return sdk.networkManager
|
|
}
|
|
|
|
// Blockchains returns the blockchain builder for blockchain operations
|
|
func (sdk *LuxSDK) Blockchains() *blockchain.Builder {
|
|
return sdk.blockchainBuilder
|
|
}
|
|
|
|
// LaunchNetwork launches a network using the network manager
|
|
func (sdk *LuxSDK) LaunchNetwork(ctx context.Context, networkType string, numNodes int) (*network.Network, error) {
|
|
params := &network.NetworkParams{
|
|
Name: networkType,
|
|
Type: network.NetworkType(networkType),
|
|
NumNodes: numNodes,
|
|
}
|
|
return sdk.networkManager.CreateNetwork(ctx, params)
|
|
}
|
|
|
|
// CreateAndDeployBlockchain creates and deploys a blockchain
|
|
func (sdk *LuxSDK) CreateAndDeployBlockchain(ctx context.Context, params *BlockchainParams) (*blockchain.Blockchain, error) {
|
|
// Create blockchain configuration
|
|
createParams := &blockchain.CreateParams{
|
|
Name: params.Name,
|
|
Type: params.Type,
|
|
VMType: params.VMType,
|
|
ChainID: params.ChainID,
|
|
Genesis: params.Genesis,
|
|
}
|
|
|
|
// Create blockchain
|
|
bc, err := sdk.blockchainBuilder.CreateBlockchain(ctx, createParams)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create blockchain: %w", err)
|
|
}
|
|
|
|
// Deploy blockchain to network if specified
|
|
if params.Network != nil {
|
|
if err := sdk.blockchainBuilder.Deploy(ctx, bc, params.Network); err != nil {
|
|
return nil, fmt.Errorf("failed to deploy blockchain: %w", err)
|
|
}
|
|
}
|
|
|
|
return bc, nil
|
|
}
|
|
|
|
// BlockchainParams defines parameters for creating and deploying a blockchain
|
|
type BlockchainParams struct {
|
|
Name string
|
|
Type blockchain.BlockchainType
|
|
VMType blockchain.VMType
|
|
ChainID *big.Int
|
|
Genesis []byte
|
|
Network *network.Network
|
|
}
|
|
|
|
// NodeInfo contains information about a node
|
|
type NodeInfo struct {
|
|
NodeID string
|
|
Version string
|
|
NetworkID uint32
|
|
NetworkName string
|
|
}
|