xchain

package
v1.22.29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2025 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package xchain implements X-Chain DEX service with hybrid transport

Package xchain provides X-Chain transport configuration

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExampleHybridTransport

func ExampleHybridTransport()

Example usage showing how both protocols work together

Types

type Block

type Block struct {
	Height uint64
	Data   []byte
}

Block represents a blockchain block

type DEXService

type DEXService struct {
	// contains filtered or unexported fields
}

DEXService handles DEX operations on X-Chain

func NewDEXService

func NewDEXService(transportConfig *TransportConfig, serviceConfig *ServiceConfig) (*DEXService, error)

NewDEXService creates a new DEX service

func (*DEXService) BroadcastBlock

func (s *DEXService) BroadcastBlock(ctx context.Context, block *Block) error

BroadcastBlock broadcasts a block to validators

func (*DEXService) Start

func (s *DEXService) Start() error

Start starts the DEX service

func (*DEXService) SubmitOrder

func (s *DEXService) SubmitOrder(ctx context.Context, order *Order) error

SubmitOrder submits an order to the DEX

type GRPCHandler

type GRPCHandler struct {
	// contains filtered or unexported fields
}

GRPCHandler handles gRPC requests (default for most operations)

func NewGRPCHandler

func NewGRPCHandler(server *grpc.Server) *GRPCHandler

type GRPCTransportConfig

type GRPCTransportConfig struct {
	// Port for gRPC server
	Port int

	// MaxMessageSize in bytes
	MaxMessageSize int

	// EnableTLS enables TLS encryption
	EnableTLS bool

	// CertFile path to TLS certificate
	CertFile string

	// KeyFile path to TLS key
	KeyFile string
}

GRPCTransportConfig configures gRPC transport

type NetworkPipeConfig

type NetworkPipeConfig struct {
	// ListenAddr is the address to listen on
	ListenAddr string

	// AdvertiseAddr is the address to advertise to peers
	AdvertiseAddr string

	// P2PPort is the main P2P port (9651)
	P2PPort int

	// RPCPort is the RPC port (9630)
	RPCPort int

	// Peers list of peer addresses
	Peers []string

	// MaxConnections per peer
	MaxConnections int

	// Bandwidth limits in Mbps
	BandwidthLimit int
}

NetworkPipeConfig defines shared network infrastructure

type NetworkPipeManager

type NetworkPipeManager struct {
	// contains filtered or unexported fields
}

NetworkPipeManager manages shared network infrastructure

func NewNetworkPipeManager

func NewNetworkPipeManager(config *NetworkPipeConfig) *NetworkPipeManager

func (*NetworkPipeManager) Start

func (npm *NetworkPipeManager) Start() error

type Order

type Order struct {
	ID          string
	Market      string
	Side        string // "buy" or "sell"
	Type        string // "limit", "market", etc.
	Price       uint64
	Quantity    uint64
	UserAddress string
	AssetID     string
}

Order represents a DEX order

type QZMQHandler

type QZMQHandler struct {
	// contains filtered or unexported fields
}

QZMQHandler handles QZMQ requests (for quantum-secure DEX operations)

func NewQZMQHandler

func NewQZMQHandler(transport *qzmq.XChainDEXTransport) *QZMQHandler

type QZMQTransportConfig

type QZMQTransportConfig struct {
	// EnableQuantum enables post-quantum cryptography
	EnableQuantum bool

	// ConsensusPort base port for consensus (5000-5002)
	ConsensusPort int

	// DEXPort base port for DEX operations (6000-6003)
	DEXPort int

	// KeyRotation interval for key rotation
	KeyRotation time.Duration

	// SecurityMode: "performance", "balanced", "conservative"
	SecurityMode string
}

QZMQTransportConfig configures QZMQ transport

type ServiceConfig

type ServiceConfig struct {
	// UseQZMQForDEX enables QZMQ for DEX operations
	UseQZMQForDEX bool

	// UseGRPCForConsensus keeps gRPC for consensus (default)
	UseGRPCForConsensus bool

	// EnableQuantumSecurity enables post-quantum crypto for DEX
	EnableQuantumSecurity bool
}

ServiceConfig configures the DEX service

type TransportConfig

type TransportConfig struct {
	// Type selects the transport protocol
	Type TransportType

	// EnableQZMQ enables QZMQ for DEX operations
	EnableQZMQ bool

	// EnableGRPC enables gRPC (default true)
	EnableGRPC bool

	// QZMQConfig holds QZMQ-specific settings
	QZMQConfig *QZMQTransportConfig

	// GRPCConfig holds gRPC-specific settings
	GRPCConfig *GRPCTransportConfig

	// NetworkPipes shared network configuration
	NetworkPipes *NetworkPipeConfig
}

TransportConfig configures X-Chain network transport

func DefaultTransportConfig

func DefaultTransportConfig() *TransportConfig

DefaultTransportConfig returns default configuration

func XChainDEXConfig

func XChainDEXConfig() *TransportConfig

XChainDEXConfig returns configuration optimized for DEX

type TransportManager

type TransportManager struct {
	// contains filtered or unexported fields
}

TransportManager manages both gRPC and QZMQ transports

func NewTransportManager

func NewTransportManager(config *TransportConfig) (*TransportManager, error)

NewTransportManager creates a new transport manager

func (*TransportManager) Close

func (tm *TransportManager) Close() error

Close shuts down all transports

func (*TransportManager) GetProtocolForMessage

func (tm *TransportManager) GetProtocolForMessage(msgType string) TransportType

GetProtocolForMessage returns which protocol to use for a message type

func (*TransportManager) SendMessage

func (tm *TransportManager) SendMessage(msgType string, data []byte) error

SendMessage sends a message using the appropriate transport

func (*TransportManager) Start

func (tm *TransportManager) Start() error

Start starts the transport manager

type TransportType

type TransportType string

TransportType defines the transport protocol to use

const (
	// TransportGRPC uses standard gRPC (default)
	TransportGRPC TransportType = "grpc"

	// TransportQZMQ uses quantum-secure ZeroMQ (for X-Chain DEX)
	TransportQZMQ TransportType = "qzmq"

	// TransportHybrid uses both gRPC and QZMQ
	TransportHybrid TransportType = "hybrid"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL