Skip to content

Conversation

@stringintech
Copy link
Owner

@stringintech stringintech commented Nov 15, 2025

This PR refactors the Context and ChainstateManager APIs to use functional options that work directly with raw C option pointers, removing the Go wrapper structs ContextOptions and ChainstateManagerOptions.

This simplification:

  • Reduces API surface area by eliminating intermediate wrapper types
  • Follows idiomatic Go functional options pattern

Context API

Previous approach:

// Create chain parameters
chainParams, err := NewChainParameters(ChainTypeRegtest)
if err != nil {
    return err
}
defer chainParams.Destroy()

// Create options struct
opts := NewContextOptions()
opts.SetChainParams(chainParams)
opts.SetNotifications(notificationCallbacks)
opts.SetValidationInterface(validationCallbacks)
defer opts.Destroy()

// Create context from options
ctx, err := NewContext(opts)

New approach:

// Create context with functional options directly
ctx, err := NewContext(
    WithChainType(ChainTypeRegtest),
    WithNotifications(notificationCallbacks),
    WithValidationInterface(validationCallbacks),
)

ChainstateManager API

Previous approach:

// Create options struct
opts, err := NewChainstateManagerOptions(ctx, dataDir, blocksDir)
if err != nil {
    return err
}
defer opts.Destroy()

opts.SetWorkerThreads(1)
opts.UpdateBlockTreeDBInMemory(true)
opts.UpdateChainstateDBInMemory(true)
err = opts.SetWipeDBs(true, true)
if err != nil {
    return err
}

// Create chainstate manager from options
manager, err := NewChainstateManager(opts)

New approach:

// Create chainstate manager with functional options directly
manager, err := NewChainstateManager(ctx, dataDir, blocksDir,
    WithWorkerThreads(1),
    WithBlockTreeDBInMemory,
    WithChainstateDBInMemory,
    WithWipeDBs(true, true),
)

@stringintech stringintech merged commit 00b4aba into main Nov 16, 2025
8 checks passed
@stringintech stringintech deleted the refactor-options branch November 16, 2025 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants