pub struct DlcDevKit<T: Transport, S: Storage, O: Oracle> {
pub runtime: Arc<RwLock<Option<Runtime>>>,
pub wallet: Arc<DlcDevKitWallet>,
pub manager: Arc<Manager<Arc<DlcDevKitWallet>, Arc<CachedContractSignerProvider<Arc<DlcDevKitWallet>, SimpleSigner>>, Arc<EsploraClient>, Arc<S>, Arc<O>, Arc<SystemTimeProvider>, Arc<DlcDevKitWallet>, SimpleSigner, Arc<Logger>>>,
pub sender: Sender<DlcManagerMessage>,
pub transport: Arc<T>,
pub storage: Arc<S>,
pub oracle: Arc<O>,
pub network: Network,
pub stop_signal: Receiver<bool>,
pub stop_signal_sender: Sender<bool>,
pub logger: Arc<Logger>,
}Expand description
DDK object with all services Main DDK instance that encapsulates all DLC functionality.
This struct manages:
-
Runtime Context:
- Single tokio runtime for all async operations
- Background task management
- Graceful shutdown handling
-
Core Components:
- Wallet for Bitcoin operations
- DLC manager for contract operations
- Transport layer for peer communication
- Storage backend for persistence
- Oracle client for external data
-
Communication:
- Message channel to the DLC manager actor
- Stop signal broadcasting for shutdown coordination
The struct is designed to be thread-safe and can be shared across multiple threads using Arc.
Fieldsยง
ยงruntime: Arc<RwLock<Option<Runtime>>>Tokio runtime for async operations
wallet: Arc<DlcDevKitWallet>Bitcoin wallet instance
manager: Arc<Manager<Arc<DlcDevKitWallet>, Arc<CachedContractSignerProvider<Arc<DlcDevKitWallet>, SimpleSigner>>, Arc<EsploraClient>, Arc<S>, Arc<O>, Arc<SystemTimeProvider>, Arc<DlcDevKitWallet>, SimpleSigner, Arc<Logger>>>DLC manager instance
sender: Sender<DlcManagerMessage>Channel for sending messages to the DLC manager
transport: Arc<T>Transport layer implementation
storage: Arc<S>Storage backend implementation
oracle: Arc<O>Oracle client implementation
network: NetworkBitcoin network (mainnet, testnet, regtest)
stop_signal: Receiver<bool>Receiver for stop signal
stop_signal_sender: Sender<bool>Sender for stop signal
logger: Arc<Logger>Logger instance for structured logging
Implementationsยง
Sourceยงimpl<T, S, O> DlcDevKit<T, S, O>
impl<T, S, O> DlcDevKit<T, S, O>
Sourcepub fn start(&self) -> Result<(), Error>
pub fn start(&self) -> Result<(), Error>
Starts the DDK runtime with a new multi-threaded tokio runtime. This spawns all necessary background tasks:
- Transport layer listeners
- Wallet synchronization
- Periodic contract checks
Sourcepub fn start_with_runtime(&self, runtime: Runtime) -> Result<(), Error>
pub fn start_with_runtime(&self, runtime: Runtime) -> Result<(), Error>
Starts the DDK runtime with a provided tokio runtime. Useful when integrating with existing async applications.
This method spawns three critical background tasks:
- Transport Listener Thread:
- Handles incoming DLC messages
- Manages peer connections
- Routes messages to DLC manager
- Gracefully shuts down on stop signal
- Wallet Sync Thread:
- Runs every 60 seconds
- Updates UTXO set
- Syncs with blockchain
- Maintains wallet state
- Contract Monitor Thread:
- Runs every 30 seconds
- Checks contract states
- Triggers necessary updates
- Maintains contract lifecycle
ยงArguments
runtime- A tokio runtime to use for async operations
ยงReturns
Ok(())if runtime started successfullyErr(Error::RuntimeExists)if runtime is already running
Sourcepub fn stop(&self) -> Result<(), Error>
pub fn stop(&self) -> Result<(), Error>
Gracefully stops the DDK runtime and all background tasks. This ensures:
- All listeners are closed
- Background tasks are terminated
- Resources are properly cleaned up
Sourcepub async fn send_dlc_offer(
&self,
contract_input: &ContractInput,
counter_party: PublicKey,
oracle_announcements: Vec<OracleAnnouncement>,
) -> Result<OfferDlc, Error>
pub async fn send_dlc_offer( &self, contract_input: &ContractInput, counter_party: PublicKey, oracle_announcements: Vec<OracleAnnouncement>, ) -> Result<OfferDlc, Error>
Creates and sends a new DLC offer to a counterparty.
This method:
- Creates a DLC offer message
- Sends it through the transport layer
- Returns the created offer for further processing
Sourcepub async fn accept_dlc_offer(
&self,
contract: [u8; 32],
) -> Result<(String, String, AcceptDlc), Error>
pub async fn accept_dlc_offer( &self, contract: [u8; 32], ) -> Result<(String, String, AcceptDlc), Error>
Accepts an existing DLC offer.
This method:
- Processes the acceptance
- Creates acceptance message
- Sends it to the counterparty
- Returns the acceptance details