api

package
v0.0.0-...-5a53b6d Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 62 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Runtime

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

Runtime owns all per-network state. Each network swap builds a fresh Runtime (new DB, new engines, new mux); the old Runtime is canceled + closed after its handlers drain.

func (*Runtime) Close

func (rt *Runtime) Close()

Close cancels engines, waits for goroutines, and closes the DB. Safe to call once. Subsequent calls are no-ops.

func (*Runtime) Start

func (rt *Runtime) Start(parent context.Context)

Start forks rt's engine context from parent and launches goroutines. Each engine writes its terminal error to errCh if non-nil; errCh closes when all engines have exited.

type Server

Server hosts bitwindowd's HTTP/Connect surface. Long-lived service connectors and the listener live here; per-network state (db, engines, sub-handlers) lives in Runtime, which is recycled in-process on network swap via Recycle.

func New

func New(
	ctx context.Context,
	svcs Services,
	conf config.Config,
	onShutdown func(ctx context.Context),
) (*Server, error)

New creates a Server with long-lived connectors started, builds the initial Runtime for the configured network, and starts that runtime's engines. The HTTP listener is not opened until Serve.

func (*Server) Handler

func (s *Server) Handler() http.Handler

func (*Server) Recycle

func (s *Server) Recycle(ctx context.Context, network config.Network) error

Recycle swaps to a fresh Runtime for the given network: opens a new network-scoped DB, builds new engines, registers new sub-handlers on a new mux, atomically points the listener at the new mux, and tears down the old runtime asynchronously. The HTTP server keeps running across the swap on the same port; the bitwindowd process never exits.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, address string) error

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context)

Shutdown tries to gracefully stop the server, forcing a shutdown after a timeout if needed, then closes the current runtime.

type Services

type Services struct {
	BitcoindConnector service.Connector[corerpc.BitcoinServiceClient]
	WalletConnector   service.Connector[validatorrpc.WalletServiceClient]
	EnforcerConnector service.Connector[validatorrpc.ValidatorServiceClient]
	CryptoConnector   service.Connector[cryptorpc.CryptoServiceClient]

	// Sidechain connectors
	ThunderConnector   service.Connector[*thunder.Client]
	BitNamesConnector  service.Connector[*bitnames.Client]
	BitAssetsConnector service.Connector[*bitassets.Client]
	TruthcoinConnector service.Connector[*truthcoin.Client]
	PhotonConnector    service.Connector[*photon.Client]
	CoinShiftConnector service.Connector[*coinshift.Client]

	OrchestratorAddr string // e.g. "http://localhost:30400"

	// Test overrides: when set, buildRuntime uses these instead of opening
	// fresh from disk. Production callers leave these zero.
	Database    *sql.DB
	ChainParams *chaincfg.Params
	WalletDir   string
	DataDir     string
}

Jump to

Keyboard shortcuts

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