pub struct Context { /* private fields */ }Expand description
The main context for the Bitcoin Kernel library.
The Context manages the global state of the Bitcoin Kernel library
and should be kept in memory for the duration of all context-dependent operations.
It is created via ContextBuilder and can be configured with various
chain types and callbacks.
§Lifetime
It is recommended to outlive any objects that depend on it, such as
ChainstateManager instances.
§Thread Safety
Context can be safely sent between threads and shared via Arc.
§Examples
use bitcoinkernel::{Context, ChainType, KernelError};
// Simple creation with defaults
let context = Context::new()?;
// Using the builder for configuration
let context = Context::builder()
.chain_type(ChainType::Regtest)
.build()?;Implementations§
Source§impl Context
impl Context
Sourcepub fn builder() -> ContextBuilder
pub fn builder() -> ContextBuilder
Returns a new ContextBuilder for constructing a context.
This is the recommended way to create a Context when you need
to configure chain types or register callbacks.
§Returns
A new ContextBuilder instance.
§Example
use bitcoinkernel::{Context, ChainType, KernelError};
let context = Context::builder()
.chain_type(ChainType::Testnet)
.build()?;Sourcepub fn new() -> Result<Context, KernelError>
pub fn new() -> Result<Context, KernelError>
Creates a new context with default settings (mainnet).
This is a convenience method equivalent to calling
ContextBuilder::new().build().
§Returns
Ok(Context)- On successful context creationErr(KernelError::Internal)- If context creation fails
§Example
use bitcoinkernel::{Context, KernelError};
let context = Context::new()?;Sourcepub fn interrupt(&self) -> Result<(), KernelError>
pub fn interrupt(&self) -> Result<(), KernelError>
Interrupts any ongoing operations in the context.
This signals the context to stop any long-running operations that support interruption, such as reindex, importing or processing blocks.
§Returns
Ok(())- If the interrupt signal was successfully sentErr(KernelError::Internal)- If the interrupt operation fails
§Example
use bitcoinkernel::{Context, KernelError};
let context = Context::new()?;
// Later, interrupt ongoing operations
context.interrupt()?;