mirror of
https://github.com/luxfi/vm.git
synced 2026-10-30 15:13:40 +00:00
Nineteen Go modules require github.com/luxfi/node, and all twelve chain VMs that touch it at all touch only seven packages: version, vms, vms/artifacts, vms/types/fee, cache, utils/json, and one function out of config. That is the plugin-SDK surface a ChainVM needs to declare itself to a host — not networking, not consensus — and it is the reason luxfi/node cannot be retired while it is the only place they can get it. Six of the seven import nothing from luxfi/node and moved unchanged. config does not: it pulls in benchlist, chains, config/node, genesis/builder, nets and network, so moving it would have brought the node with it. It also has exactly two call sites in the whole VM set, both in an fhe_c.go, both calling GetGlobalGPUConfig — and config/gpu.go is 129 lines that import nothing at all. It is here as its own package, gpu, so a VM asking what GPU to use does not thereby depend on how a node parses its flags. Nothing is deleted from luxfi/node by this commit. The consumers still have to be repointed, and two things in this repository block verifying that: go.sum carries a stale hash for a moved luxfi/consensus tag, and registry's own tests import a luxfi/vm/manager that does not exist. Both predate this change. Co-authored-by: Hanzo Dev <[email protected]>
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package vms
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
)
|
|
|
|
// HandlerProvider is the interface that VMs must implement to provide HTTP handlers
|
|
type HandlerProvider interface {
|
|
CreateHandlers(context.Context) (map[string]http.Handler, error)
|
|
}
|
|
|
|
// HandlerDelegator wraps a VM and delegates handler creation
|
|
type HandlerDelegator[T any] struct {
|
|
vm T
|
|
}
|
|
|
|
// NewHandlerDelegator creates a new handler delegator for a VM
|
|
func NewHandlerDelegator[T any](vm T) *HandlerDelegator[T] {
|
|
return &HandlerDelegator[T]{vm: vm}
|
|
}
|
|
|
|
// CreateHandlers delegates to the underlying VM's CreateHandlers method if it exists
|
|
func (h *HandlerDelegator[T]) CreateHandlers(ctx context.Context) (map[string]http.Handler, error) {
|
|
return DelegateHandlers(ctx, h.vm)
|
|
}
|
|
|
|
// CreateStaticHandlers returns an empty map as a default implementation
|
|
func (h *HandlerDelegator[T]) CreateStaticHandlers(ctx context.Context) (map[string]http.Handler, error) {
|
|
// Default implementation returns no static handlers
|
|
return nil, nil
|
|
}
|
|
|
|
// DelegateHandlers delegates the CreateHandlers call to the underlying VM
|
|
func DelegateHandlers(ctx context.Context, vm interface{}) (map[string]http.Handler, error) {
|
|
if handlerCreator, ok := vm.(HandlerProvider); ok {
|
|
return handlerCreator.CreateHandlers(ctx)
|
|
}
|
|
return nil, nil
|
|
}
|